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);
}
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);
}
}
Aggregations