mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 03:43:30 +01:00
fixed up some issues
This commit is contained in:
parent
b3bc24ef09
commit
5497de1f1d
10 changed files with 22 additions and 52 deletions
|
@ -13,6 +13,7 @@ import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.util.Tuple;
|
import net.minecraft.util.Tuple;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
import net.minecraft.world.phys.AABB;
|
import net.minecraft.world.phys.AABB;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import org.apache.commons.lang3.mutable.MutableFloat;
|
import org.apache.commons.lang3.mutable.MutableFloat;
|
||||||
|
@ -201,8 +202,8 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IAuraChunk createAuraChunk() {
|
public IAuraChunk createAuraChunk(LevelChunk chunk) {
|
||||||
return new AuraChunk();
|
return new AuraChunk(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package de.ellpeck.naturesaura.api;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
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.IAuraChunk;
|
||||||
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
|
import de.ellpeck.naturesaura.api.aura.chunk.IDrainSpotEffect;
|
||||||
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
|
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.item.ItemStack;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
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.AABB;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
import net.neoforged.neoforge.attachment.AttachmentType;
|
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)}.
|
* 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;
|
private static final IInternalHooks INSTANCE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -260,7 +260,7 @@ public final class NaturesAuraAPI {
|
||||||
|
|
||||||
ILevelData getLevelData(Level level);
|
ILevelData getLevelData(Level level);
|
||||||
|
|
||||||
IAuraChunk createAuraChunk();
|
IAuraChunk createAuraChunk(LevelChunk chunk);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -33,7 +33,7 @@ public interface IAuraChunk extends INBTSerializable<CompoundTag> {
|
||||||
*/
|
*/
|
||||||
static IAuraChunk getAuraChunk(Level level, BlockPos pos) {
|
static IAuraChunk getAuraChunk(Level level, BlockPos pos) {
|
||||||
var chunk = (LevelChunk) level.getChunk(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 markDirty();
|
||||||
|
|
||||||
void ensureInitialized(LevelChunk chunk);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class BlockProjectileGenerator extends BlockContainerImpl implements ITES
|
||||||
protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) {
|
protected Projectile getProjectile(Level levelIn, Position position, ItemStack stackIn) {
|
||||||
var ret = new ThrownTrident(EntityType.TRIDENT, levelIn);
|
var ret = new ThrownTrident(EntityType.TRIDENT, levelIn);
|
||||||
ret.setPos(position.x(), position.y(), position.z());
|
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;
|
ret.pickup = AbstractArrow.Pickup.ALLOWED;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ import java.lang.reflect.Field;
|
||||||
|
|
||||||
public class BlockEntityFurnaceHeater extends BlockEntityImpl implements ITickableBlockEntity {
|
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 boolean isActive;
|
||||||
|
|
||||||
public BlockEntityFurnaceHeater(BlockPos pos, BlockState state) {
|
public BlockEntityFurnaceHeater(BlockPos pos, BlockState state) {
|
||||||
|
|
|
@ -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<Integer, Integer>> auraAndSpotAmountCache = HashBasedTable.create();
|
||||||
private final Table<BlockPos, Integer, Pair<BlockPos, Integer>[]> limitSpotCache = HashBasedTable.create();
|
private final Table<BlockPos, Integer, Pair<BlockPos, Integer>[]> limitSpotCache = HashBasedTable.create();
|
||||||
private final List<IDrainSpotEffect> effects = new ArrayList<>();
|
private final List<IDrainSpotEffect> effects = new ArrayList<>();
|
||||||
|
private final LevelChunk chunk;
|
||||||
|
private final IAuraType type;
|
||||||
|
|
||||||
private LevelChunk chunk;
|
|
||||||
private IAuraType type;
|
|
||||||
private boolean needsSync;
|
private boolean needsSync;
|
||||||
|
|
||||||
@Override
|
public AuraChunk(LevelChunk chunk) {
|
||||||
public void ensureInitialized(LevelChunk chunk) {
|
|
||||||
// are we already initialized?
|
|
||||||
if (this.chunk != null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
this.chunk = chunk;
|
this.chunk = chunk;
|
||||||
this.type = IAuraType.forLevel(chunk.getLevel());
|
this.type = IAuraType.forLevel(chunk.getLevel());
|
||||||
|
|
||||||
|
|
|
@ -33,14 +33,14 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class CommonEvents {
|
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();
|
private static final ListMultimap<UUID, ChunkPos> PENDING_AURA_CHUNKS = ArrayListMultimap.create();
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onChunkUnload(ChunkEvent.Unload event) {
|
public void onChunkUnload(ChunkEvent.Unload event) {
|
||||||
var iChunk = event.getChunk();
|
var iChunk = event.getChunk();
|
||||||
if (iChunk instanceof LevelChunk chunk) {
|
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) {
|
if (auraChunk instanceof AuraChunk) {
|
||||||
var data = (LevelData) ILevelData.getLevelData(chunk.getLevel());
|
var data = (LevelData) ILevelData.getLevelData(chunk.getLevel());
|
||||||
data.auraChunksWithSpots.remove(chunk.getPos().toLong());
|
data.auraChunksWithSpots.remove(chunk.getPos().toLong());
|
||||||
|
@ -76,7 +76,7 @@ public class CommonEvents {
|
||||||
var chunk = holder.getTickingChunk();
|
var chunk = holder.getTickingChunk();
|
||||||
if (chunk == null)
|
if (chunk == null)
|
||||||
continue;
|
continue;
|
||||||
var auraChunk = (AuraChunk) chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT).get(chunk);
|
var auraChunk = (AuraChunk) chunk.getData(NaturesAuraAPI.AURA_CHUNK_ATTACHMENT);
|
||||||
if (auraChunk != null)
|
if (auraChunk != null)
|
||||||
auraChunk.update();
|
auraChunk.update();
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ public class CommonEvents {
|
||||||
var chunk = Helper.getLoadedChunk(player.level(), pos.x, pos.z);
|
var chunk = Helper.getLoadedChunk(player.level(), pos.x, pos.z);
|
||||||
if (!(chunk instanceof LevelChunk levelChunk))
|
if (!(chunk instanceof LevelChunk levelChunk))
|
||||||
return false;
|
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)
|
if (auraChunk == null)
|
||||||
return false;
|
return false;
|
||||||
PacketHandler.sendTo(player, auraChunk.makePacket());
|
PacketHandler.sendTo(player, auraChunk.makePacket());
|
||||||
|
|
|
@ -70,6 +70,11 @@ public class LevelData extends SavedData implements ILevelData {
|
||||||
return compound;
|
return compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDirty() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStackHandlerNA getEnderStorage(String name) {
|
public ItemStackHandlerNA getEnderStorage(String name) {
|
||||||
return this.enderStorages.computeIfAbsent(name, n -> new ItemStackHandlerNA(27));
|
return this.enderStorages.computeIfAbsent(name, n -> new ItemStackHandlerNA(27));
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class PacketAuraChunk implements CustomPacketPayload {
|
||||||
var chunk = level.getChunk(this.chunkX, this.chunkZ);
|
var chunk = level.getChunk(this.chunkX, this.chunkZ);
|
||||||
if (chunk.isEmpty())
|
if (chunk.isEmpty())
|
||||||
return false;
|
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)
|
if (auraChunk == null)
|
||||||
return false;
|
return false;
|
||||||
auraChunk.setSpots(this.drainSpots);
|
auraChunk.setSpots(this.drainSpots);
|
||||||
|
|
Loading…
Reference in a new issue