Search in sources :

Example 1 with ICustomDataTile

use of gregtech.api.capability.ICustomDataTile in project GregTech by GregTechCE.

the class CustomDataTileHandler method onChunkWatch.

@SubscribeEvent
public void onChunkWatch(ChunkWatchEvent.Watch event) {
    ChunkPos chunkPos = event.getChunk();
    EntityPlayerMP player = event.getPlayer();
    Chunk chunk = player.world.getChunkFromChunkCoords(chunkPos.x, chunkPos.z);
    for (TileEntity tileEntity : chunk.getTileEntityMap().values()) {
        if (tileEntity instanceof ICustomDataTile) {
            ICustomDataTile customDataTile = (ICustomDataTile) tileEntity;
            customDataTile.onBeingWatched(player);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ICustomDataTile(gregtech.api.capability.ICustomDataTile) ChunkPos(net.minecraft.util.math.ChunkPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Chunk(net.minecraft.world.chunk.Chunk) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with ICustomDataTile

use of gregtech.api.capability.ICustomDataTile in project GregTech by GregTechCE.

the class CustomDataTileHandler method onClientTick.

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
    if (event.phase != Phase.END)
        return;
    World clientWorld = Minecraft.getMinecraft().world;
    if (clientWorld == null)
        return;
    Iterator<BlockPos> keyIterator = pendingInitialSyncData.keySet().iterator();
    while (keyIterator.hasNext()) {
        BlockPos blockPos = keyIterator.next();
        TileEntity tileEntity = clientWorld.getTileEntity(blockPos);
        if (tileEntity instanceof ICustomDataTile) {
            pendingInitialSyncData.get(blockPos).forEach(((ICustomDataTile) tileEntity)::handleDataPacket);
            keyIterator.remove();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ICustomDataTile(gregtech.api.capability.ICustomDataTile) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

ICustomDataTile (gregtech.api.capability.ICustomDataTile)2 TileEntity (net.minecraft.tileentity.TileEntity)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 World (net.minecraft.world.World)1 Chunk (net.minecraft.world.chunk.Chunk)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1