Search in sources :

Example 1 with PacketCustomTileData

use of gregtech.api.net.PacketCustomTileData in project GregTech by GregTechCE.

the class ICustomDataTile method onBeingWatched.

default void onBeingWatched(EntityPlayerMP watcher) {
    TileEntity tileEntity = (TileEntity) this;
    PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
    buffer.writeBoolean(true);
    writeInitialSyncData(buffer);
    PacketCustomTileData packet = new PacketCustomTileData(tileEntity.getPos(), buffer);
    NetworkHandler.channel.sendTo(packet.toFMLPacket(), watcher);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PacketCustomTileData(gregtech.api.net.PacketCustomTileData) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 2 with PacketCustomTileData

use of gregtech.api.net.PacketCustomTileData in project GregTech by GregTechCE.

the class ICustomDataTile method writeCustomData.

default void writeCustomData(int discriminator, Consumer<PacketBuffer> dataWriter) {
    // unsafe
    TileEntity tileEntity = (TileEntity) this;
    WorldServer worldServer = (WorldServer) tileEntity.getWorld();
    BlockPos pos = tileEntity.getPos();
    PlayerChunkMapEntry chunkLoaderEntry = worldServer.getPlayerChunkMap().getEntry(pos.getX() / 16, pos.getZ() / 16);
    // nobody is watching chunk, so...
    if (chunkLoaderEntry == null)
        return;
    PacketBuffer backedData = new PacketBuffer(Unpooled.buffer());
    backedData.writeBoolean(false);
    backedData.writeInt(discriminator);
    dataWriter.accept(backedData);
    PacketCustomTileData packet = new PacketCustomTileData(pos, backedData);
    for (EntityPlayerMP watcher : chunkLoaderEntry.players) {
        NetworkHandler.channel.sendTo(packet.toFMLPacket(), watcher);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PacketCustomTileData(gregtech.api.net.PacketCustomTileData) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) PlayerChunkMapEntry(net.minecraft.server.management.PlayerChunkMapEntry) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PacketBuffer(net.minecraft.network.PacketBuffer)

Aggregations

PacketCustomTileData (gregtech.api.net.PacketCustomTileData)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 PlayerChunkMapEntry (net.minecraft.server.management.PlayerChunkMapEntry)1 BlockPos (net.minecraft.util.math.BlockPos)1 WorldServer (net.minecraft.world.WorldServer)1