fixed up some issues

This commit is contained in:
Ell 2024-03-12 19:53:57 +01:00
parent b3bc24ef09
commit 5497de1f1d
10 changed files with 22 additions and 52 deletions

View file

@ -13,6 +13,7 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Tuple;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.apache.commons.lang3.mutable.MutableFloat;
@ -201,8 +202,8 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
}
@Override
public IAuraChunk createAuraChunk() {
return new AuraChunk();
public IAuraChunk createAuraChunk(LevelChunk chunk) {
return new AuraChunk(chunk);
}
}

View file

@ -2,7 +2,6 @@ package de.ellpeck.naturesaura.api;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import de.ellpeck.naturesaura.api.aura.chunk.AuraChunkProvider;
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
@ -23,6 +22,7 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.attachment.AttachmentType;
@ -99,7 +99,7 @@ public final class NaturesAuraAPI {
/**
* The capability that any chunk in a level has to store Aura in it. As this is only applicable to chunks and all chunks in the level automatically get assigned this capability, using it directly is not necessary for addon developers. To retrieve this capability from any chunk, use the helper method {@link IAuraChunk#getAuraChunk(net.minecraft.world.level.Level, BlockPos)}.
*/
public static final AttachmentType<AuraChunkProvider> AURA_CHUNK_ATTACHMENT = AttachmentType.serializable(AuraChunkProvider::new).build();
public static final AttachmentType<IAuraChunk> AURA_CHUNK_ATTACHMENT = AttachmentType.serializable(h -> NaturesAuraAPI.instance().createAuraChunk((LevelChunk) h)).build();
private static final IInternalHooks INSTANCE;
static {
@ -260,7 +260,7 @@ public final class NaturesAuraAPI {
ILevelData getLevelData(Level level);
IAuraChunk createAuraChunk();
IAuraChunk createAuraChunk(LevelChunk chunk);
}

View file

@ -1,29 +0,0 @@
package de.ellpeck.naturesaura.api.aura.chunk;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.chunk.LevelChunk;
import net.neoforged.neoforge.common.util.INBTSerializable;
public class AuraChunkProvider implements INBTSerializable<CompoundTag> {
private IAuraChunk auraChunk;
public IAuraChunk get(LevelChunk chunk) {
if (this.auraChunk == null)
this.auraChunk = NaturesAuraAPI.instance().createAuraChunk();
this.auraChunk.ensureInitialized(chunk);
return this.auraChunk;
}
@Override
public CompoundTag serializeNBT() {
return this.get(null).serializeNBT();
}
@Override
public void deserializeNBT(CompoundTag nbt) {
this.get(null).deserializeNBT(nbt);
}
}

View file

@ -33,7 +33,7 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
*/
static IAuraChunk getAuraChunk(Level level, BlockPos pos) {
var chunk = (LevelChunk) level.getChunk(pos);
return chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(chunk);
return chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT);
}
/**
@ -160,6 +160,4 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
void markDirty();
void ensureInitialized(LevelChunk chunk);
}

View file

@ -50,7 +50,7 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) {
var ret = new ThrownTrident(EntityType.TRIDENT, levelIn);
ret.setPos(position.x(), position.y(), position.z());
ObfuscationReflectionHelper.setPrivateValue(ThrownTrident.class, ret, stackIn.copy(), "f_37555_");
ObfuscationReflectionHelper.setPrivateValue(ThrownTrident.class, ret, stackIn.copy(), "pickupItemStack");
ret.pickup = AbstractArrow.Pickup.ALLOWED;
return ret;
}

View file

@ -24,7 +24,7 @@ import java.lang.reflect.Field;
public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickableBlockEntity {
private static final Field FURNACE_DATA_FIELD = ObfuscationReflectionHelper.findField(AbstractFurnaceBlockEntity.class, "f_58311_");
private static final Field FURNACE_DATA_FIELD = ObfuscationReflectionHelper.findField(AbstractFurnaceBlockEntity.class, "dataAccess");
public boolean isActive;
public BlockEntityFurnaceHeater(BlockPos pos, BlockState state) {

View file

@ -37,17 +37,12 @@ public class AuraChunk implements IAuraChunk {
private final Table<BlockPos, Integer, Pair<Integer, Integer>> auraAndSpotAmountCache = HashBasedTable.create();
private final Table<BlockPos, Integer, Pair<BlockPos, Integer>[]> limitSpotCache = HashBasedTable.create();
private final List<IDrainSpotEffect> effects = new ArrayList<>();
private final LevelChunk chunk;
private final IAuraType type;
private LevelChunk chunk;
private IAuraType type;
private boolean needsSync;
@Override
public void ensureInitialized(LevelChunk chunk) {
// are we already initialized?
if (this.chunk != null)
return;
public AuraChunk(LevelChunk chunk) {
this.chunk = chunk;
this.type = IAuraType.forLevel(chunk.getLevel());

View file

@ -33,14 +33,14 @@ import java.util.UUID;
public class CommonEvents {
private static final Method GET_LOADED_CHUNKS_METHOD = ObfuscationReflectionHelper.findMethod(ChunkMap.class, "m_140416_");
private static final Method GET_LOADED_CHUNKS_METHOD = ObfuscationReflectionHelper.findMethod(ChunkMap.class, "getChunks");
private static final ListMultimap<UUID, ChunkPos> PENDING_AURA_CHUNKS = ArrayListMultimap.create();
@SubscribeEvent
public void onChunkUnload(ChunkEvent.Unload event) {
var iChunk = event.getChunk();
if (iChunk instanceof LevelChunk chunk) {
var auraChunk = chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(chunk);
var auraChunk = chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT);
if (auraChunk instanceof AuraChunk) {
var data = (LevelData) ILevelData.getLevelData(chunk.getLevel());
data.auraChunksWithSpots.remove(chunk.getPos().toLong());
@ -76,7 +76,7 @@ public class CommonEvents {
var chunk = holder.getTickingChunk();
if (chunk == null)
continue;
var auraChunk = (AuraChunk) chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(chunk);
var auraChunk = (AuraChunk) chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT);
if (auraChunk != null)
auraChunk.update();
}
@ -116,7 +116,7 @@ public class CommonEvents {
var chunk = Helper.getLoadedChunk(player.level(), pos.x, pos.z);
if (!(chunk instanceof LevelChunk levelChunk))
return false;
var auraChunk = (AuraChunk) levelChunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(levelChunk);
var auraChunk = (AuraChunk) levelChunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT);
if (auraChunk == null)
return false;
PacketHandler.sendTo(player, auraChunk.makePacket());

View file

@ -70,6 +70,11 @@ public class LevelData extends SavedData implements ILevelData {
return compound;
}
@Override
public boolean isDirty() {
return true;
}
@Override
public ItemStackHandlerNA getEnderStorage(String name) {
return this.enderStorages.computeIfAbsent(name, n -> new ItemStackHandlerNA(27));

View file

@ -61,7 +61,7 @@ public class PacketAuraChunk implements CustomPacketPayload {
var chunk = level.getChunk(this.chunkX, this.chunkZ);
if (chunk.isEmpty())
return false;
var auraChunk = (AuraChunk) chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(chunk);
var auraChunk = (AuraChunk) chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT);
if (auraChunk == null)
return false;
auraChunk.setSpots(this.drainSpots);