diff --git a/core/Registration.java b/core/Registration.java index 2f69e15ba..93d02e349 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 eeb433815..8d3bdfc49 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 03a19d178..88d5a30c6 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)