From 45c292344f098de564581a1fedbd90af811c8aaa Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Mon, 12 May 2014 21:15:45 -0500 Subject: [PATCH] Fixed Dormant Chunk Cache. --- core/Registration.java | 1 + hooks/TickHandler.java | 16 +++++++++++++++- tile/AEBaseTile.java | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/Registration.java b/core/Registration.java index 2f69e15b..93d02e34 100644 --- a/core/Registration.java +++ b/core/Registration.java @@ -490,6 +490,7 @@ public class Registration ph.registerNewLayer( "appeng.api.parts.layers.LayerIEnergyHandler", "cofh.api.energy.IEnergyHandler" ); FMLCommonHandler.instance().bus().register( TickHandler.instance ); + MinecraftForge.EVENT_BUS.register( TickHandler.instance ); MinecraftForge.EVENT_BUS.register( new PartPlacement() ); IGridCacheRegistry gcr = AEApi.instance().registries().gridCache(); diff --git a/hooks/TickHandler.java b/hooks/TickHandler.java index eeb43381..8d3bdfc4 100644 --- a/hooks/TickHandler.java +++ b/hooks/TickHandler.java @@ -5,6 +5,7 @@ import java.util.LinkedList; import java.util.Queue; import java.util.concurrent.Callable; +import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.WorldEvent; import appeng.api.networking.IGridNode; import appeng.core.AELog; @@ -103,10 +104,23 @@ public class TickHandler } } + @SubscribeEvent + public void onChunkLoad(ChunkEvent.Load load) + { + for (Object te : load.getChunk().chunkTileEntityMap.values()) + { + if ( te instanceof AEBaseTile ) + { + ((AEBaseTile) te).onChunkLoad(); + } + } + } + @SubscribeEvent public void onTick(TickEvent ev) { - if ( ev.type == Type.SERVER && ev.phase == Phase.END ) // for no there is no reason to care about this on the client... + if ( ev.type == Type.SERVER && ev.phase == Phase.END ) // for no there is no reason to care about this on the + // client... { HandlerRep repo = getRepo(); while (!repo.tiles.isEmpty()) diff --git a/tile/AEBaseTile.java b/tile/AEBaseTile.java index 03a19d17..88d5a30c 100644 --- a/tile/AEBaseTile.java +++ b/tile/AEBaseTile.java @@ -111,6 +111,22 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile, h.Tick(); } + @Override + public void onChunkUnload() + { + if ( !isInvalid() ) + invalidate(); + } + + /** + * for dormant chunk cache. + */ + public void onChunkLoad() + { + if ( isInvalid() ) + validate(); + } + @Override // NOTE: WAS FINAL, changed for Immibis public void writeToNBT(NBTTagCompound data)