mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-11 15:57:42 +00:00
Added IChunkLoadTile
This commit is contained in:
1 parent
feb8bfd028
commit
29e4eda53b
2 files changed
+36
No files matched your search
@@ -0,0 +1,12 @@
|
||||
package codechicken.lib.world;
|
||||
|
||||
/**
|
||||
* Provides a callback for tile entities when a chunk is loaded, as an alternative to validate when the chunk hasn't been added to the world.
|
||||
* To hook all world join/seperate events. Use this, TileEntity.validate with a worldObj.blockExists check, TileEntity.onChunkUnload and TileEntity.invalidate
|
||||
* Be sure to call TileChunkLoadHook.init() from your mod during initialisation
|
||||
* You could easily implement this in your own mod, but providing it here reduces the number of times the chunkTileEntityMap needs to be iterated
|
||||
*/
|
||||
public interface IChunkLoadTile
|
||||
{
|
||||
public void onChunkLoad();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package codechicken.lib.world;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.world.ChunkEvent;
|
||||
|
||||
public class TileChunkLoadHook
|
||||
{
|
||||
private static boolean init;
|
||||
public static void init() {
|
||||
if(init) return;
|
||||
init = true;
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new TileChunkLoadHook());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onChunkLoad(ChunkEvent.Load event) {
|
||||
for(TileEntity t : ((Iterable<TileEntity>)event.getChunk().chunkTileEntityMap.values()))
|
||||
if(t instanceof IChunkLoadTile)
|
||||
((IChunkLoadTile)t).onChunkLoad();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user