From 81c6034c2184013696702b6a4f233fe8d611343d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 23 Jan 2020 02:01:05 +0100 Subject: [PATCH] misc fixes including making aura effects work! --- src/main/java/de/ellpeck/naturesaura/Helper.java | 11 ++++------- .../de/ellpeck/naturesaura/api/NaturesAuraAPI.java | 12 ++++++------ .../java/de/ellpeck/naturesaura/chunk/AuraChunk.java | 2 ++ .../de/ellpeck/naturesaura/events/CommonEvents.java | 7 ++++--- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index fa77af6e..b6b1ca89 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -29,8 +29,6 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.IWorld; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.ChunkStatus; -import net.minecraft.world.chunk.IChunk; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.capabilities.Capability; @@ -58,7 +56,7 @@ public final class Helper { public static boolean getTileEntitiesInArea(IWorld world, BlockPos pos, int radius, Function consumer) { for (int x = (pos.getX() - radius) >> 4; x <= (pos.getX() + radius) >> 4; x++) { for (int z = (pos.getZ() - radius) >> 4; z <= (pos.getZ() + radius) >> 4; z++) { - Chunk chunk = getOptionalChunk(world, x, z); + Chunk chunk = getLoadedChunk(world, x, z); if (chunk != null) { for (BlockPos tilePos : chunk.getTileEntitiesPos()) { if (tilePos.distanceSq(pos) <= radius * radius) @@ -74,7 +72,7 @@ public final class Helper { public static void getAuraChunksInArea(World world, BlockPos pos, int radius, Consumer consumer) { for (int x = (pos.getX() - radius) >> 4; x <= (pos.getX() + radius) >> 4; x++) { for (int z = (pos.getZ() - radius) >> 4; z <= (pos.getZ() + radius) >> 4; z++) { - Chunk chunk = getOptionalChunk(world, x, z); + Chunk chunk = getLoadedChunk(world, x, z); if (chunk != null) { AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); if (auraChunk != null) @@ -95,9 +93,8 @@ public final class Helper { return frames; } - public static Chunk getOptionalChunk(IWorld world, int x, int z) { - IChunk chunk = world.getChunk(x, z, ChunkStatus.EMPTY, false); - return chunk instanceof Chunk ? (Chunk) chunk : null; + public static Chunk getLoadedChunk(IWorld world, int x, int z) { + return world.getChunkProvider().getChunk(x, z, false); } public static int blendColors(int c1, int c2, float ratio) { diff --git a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java index 475a341d..3198605c 100644 --- a/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java +++ b/src/main/java/de/ellpeck/naturesaura/api/NaturesAuraAPI.java @@ -319,32 +319,32 @@ public final class NaturesAuraAPI { boolean isEffectPowderActive(World world, BlockPos pos, ResourceLocation name); /** - * @see IAuraChunk#getSpotsInArea(World, BlockPos, int, BiConsumer) + * @see IAuraChunk#getSpotsInArea(IWorld, BlockPos, int, BiConsumer) */ void getAuraSpotsInArea(World world, BlockPos pos, int radius, BiConsumer consumer); /** - * @see IAuraChunk#getSpotAmountInArea(World, BlockPos, int) + * @see IAuraChunk#getSpotAmountInArea(IWorld, BlockPos, int) */ int getSpotAmountInArea(World world, BlockPos pos, int radius); /** - * @see IAuraChunk#getAuraInArea(World, BlockPos, int) + * @see IAuraChunk#getAuraInArea(IWorld, BlockPos, int) */ int getAuraInArea(World world, BlockPos pos, int radius); /** - * @see IAuraChunk#triangulateAuraInArea(World, BlockPos, int) + * @see IAuraChunk#triangulateAuraInArea(IWorld, BlockPos, int) */ int triangulateAuraInArea(World world, BlockPos pos, int radius); /** - * @see IAuraChunk#getLowestSpot(World, BlockPos, int, BlockPos) + * @see IAuraChunk#getLowestSpot(IWorld, BlockPos, int, BlockPos) */ BlockPos getLowestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot); /** - * @see IAuraChunk#getHighestSpot(World, BlockPos, int, BlockPos) + * @see IAuraChunk#getHighestSpot(IWorld, BlockPos, int, BlockPos) */ BlockPos getHighestAuraDrainSpot(World world, BlockPos pos, int radius, BlockPos defaultSpot); } diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java index 6c7248c7..e21e3141 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java @@ -143,6 +143,8 @@ public class AuraChunk implements IAuraChunk { public void update() { World world = this.chunk.getWorld(); + if (this.drainSpots.size() > 0) + System.out.println("Updating with " + this.drainSpots.size()); for (Map.Entry entry : this.drainSpots.entrySet()) { BlockPos pos = entry.getKey(); MutableInt amount = entry.getValue(); diff --git a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java index 30e96125..74e92e86 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java @@ -22,6 +22,7 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Optional; public class CommonEvents { @@ -47,10 +48,10 @@ public class CommonEvents { ChunkManager manager = ((ServerChunkProvider) event.world.getChunkProvider()).chunkManager; Iterable chunks = (Iterable) GET_LOADED_CHUNKS_METHOD.invoke(manager); for (ChunkHolder holder : chunks) { - Chunk chunk = holder.func_219298_c(); - if (chunk == null) + Optional chunkQuestionmark = holder.func_219296_a().getNow(ChunkHolder.UNLOADED_CHUNK).left(); + if (!chunkQuestionmark.isPresent()) continue; - AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); + AuraChunk auraChunk = (AuraChunk) chunkQuestionmark.get().getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); if (auraChunk != null) auraChunk.update(); }