hopefully finally caused the game to not hang?????????????

This commit is contained in:
Ellpeck 2020-01-23 02:20:02 +01:00
parent 81c6034c21
commit 25d3550e0a
3 changed files with 11 additions and 7 deletions

View file

@ -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) {

View file

@ -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<BlockPos, MutableInt> entry : this.drainSpots.entrySet()) {
BlockPos pos = entry.getKey();
MutableInt amount = entry.getValue();

View file

@ -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<ChunkHolder> chunks = (Iterable<ChunkHolder>) GET_LOADED_CHUNKS_METHOD.invoke(manager);
for (ChunkHolder holder : chunks) {
Optional<Chunk> 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();
}