From 25d3550e0aa60817774cc15b7ad215e4d100a09b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 23 Jan 2020 02:20:02 +0100 Subject: [PATCH] hopefully finally caused the game to not hang????????????? --- src/main/java/de/ellpeck/naturesaura/Helper.java | 9 ++++++++- .../java/de/ellpeck/naturesaura/chunk/AuraChunk.java | 2 -- .../java/de/ellpeck/naturesaura/events/CommonEvents.java | 7 +++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index b6b1ca89..f9d00bae 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -25,9 +25,11 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.*; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.IWorld; import net.minecraft.world.World; +import net.minecraft.world.chunk.AbstractChunkProvider; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -94,7 +96,12 @@ public final class Helper { } public static Chunk getLoadedChunk(IWorld world, int x, int z) { - return world.getChunkProvider().getChunk(x, z, false); + // DO NOT EDIT PLEASE FOR THE LOVE OF GOD + // This is very finicky and easily causes the game to hang for some reason + AbstractChunkProvider provider = world.getChunkProvider(); + if (provider.isChunkLoaded(new ChunkPos(x, z))) + return provider.getChunk(x, z, false); + return null; } public static int blendColors(int c1, int c2, float ratio) { diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java index e21e3141..6c7248c7 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunk.java @@ -143,8 +143,6 @@ 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 74e92e86..30e96125 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java @@ -22,7 +22,6 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Optional; public class CommonEvents { @@ -48,10 +47,10 @@ public class CommonEvents { ChunkManager manager = ((ServerChunkProvider) event.world.getChunkProvider()).chunkManager; Iterable chunks = (Iterable) GET_LOADED_CHUNKS_METHOD.invoke(manager); for (ChunkHolder holder : chunks) { - Optional chunkQuestionmark = holder.func_219296_a().getNow(ChunkHolder.UNLOADED_CHUNK).left(); - if (!chunkQuestionmark.isPresent()) + Chunk chunk = holder.func_219298_c(); + if (chunk == null) continue; - AuraChunk auraChunk = (AuraChunk) chunkQuestionmark.get().getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); + AuraChunk auraChunk = (AuraChunk) chunk.getCapability(NaturesAuraAPI.capAuraChunk, null).orElse(null); if (auraChunk != null) auraChunk.update(); }