use of net.minecraft.network.PacketBuffer 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 net.minecraft.network.PacketBuffer 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);
}
}
use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.
the class Widget method writeUpdateInfo.
/**
* Writes data to be sent to client's {@link #readUpdateInfo}
*/
protected final void writeUpdateInfo(int id, Consumer<PacketBuffer> packetBufferWriter) {
PacketBuffer packetBuffer = new PacketBuffer(Unpooled.buffer());
packetBuffer.writeInt(id);
packetBufferWriter.accept(packetBuffer);
int widgetId = gui.guiWidgets.inverse().get(this);
if (gui.entityPlayer instanceof EntityPlayerMP) {
int currentWindowId = gui.entityPlayer.openContainer.windowId;
PacketUIWidgetUpdate widgetUpdate = new PacketUIWidgetUpdate(currentWindowId, widgetId, packetBuffer);
NetworkHandler.channel.sendTo(NetworkHandler.packet2proxy(widgetUpdate), (EntityPlayerMP) gui.entityPlayer);
}
}
use of net.minecraft.network.PacketBuffer in project RFToolsDimensions by McJty.
the class DimensionSyncPacket method consumePacket.
public void consumePacket(ByteBuf data) {
int size = data.readInt();
for (int i = 0; i < size; i++) {
int id = data.readInt();
PacketBuffer buffer = new PacketBuffer(data);
NBTTagCompound tagCompound;
try {
tagCompound = buffer.readCompoundTag();
} catch (IOException e) {
e.printStackTrace();
return;
}
DimensionDescriptor descriptor = new DimensionDescriptor(tagCompound);
dimensions.put(id, descriptor);
}
size = data.readInt();
for (int i = 0; i < size; i++) {
int id = data.readInt();
String name = NetworkTools.readString(data);
DimensionInformation dimInfo = new DimensionInformation(name, dimensions.get(id), data);
dimensionInformation.put(id, dimInfo);
}
}
use of net.minecraft.network.PacketBuffer in project RFToolsDimensions by McJty.
the class DimensionSyncPacket method getData.
public ByteBuf getData() {
ByteBuf data = Unpooled.buffer();
data.writeInt(dimensions.size());
for (Map.Entry<Integer, DimensionDescriptor> me : dimensions.entrySet()) {
data.writeInt(me.getKey());
NBTTagCompound tagCompound = new NBTTagCompound();
me.getValue().writeToNBT(tagCompound);
PacketBuffer buffer = new PacketBuffer(data);
buffer.writeCompoundTag(tagCompound);
}
data.writeInt(dimensionInformation.size());
for (Map.Entry<Integer, DimensionInformation> me : dimensionInformation.entrySet()) {
data.writeInt(me.getKey());
DimensionInformation dimInfo = me.getValue();
NetworkTools.writeString(data, dimInfo.getName());
dimInfo.toBytes(data);
}
return data;
}
Aggregations