use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.
the class ModularUIContainer method writeClientAction.
@Override
public void writeClientAction(Widget widget, int updateId, Consumer<PacketBuffer> payloadWriter) {
int widgetId = modularUI.guiWidgets.inverse().get(widget);
PacketBuffer packetBuffer = new PacketBuffer(Unpooled.buffer());
packetBuffer.writeVarInt(updateId);
payloadWriter.accept(packetBuffer);
if (modularUI.entityPlayer instanceof EntityPlayerSP) {
PacketUIClientAction widgetUpdate = new PacketUIClientAction(windowId, widgetId, packetBuffer);
NetworkHandler.channel.sendToServer(NetworkHandler.packet2proxy(widgetUpdate));
}
}
use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.
the class ModularUIContainer method writeUpdateInfo.
@Override
public void writeUpdateInfo(Widget widget, int updateId, Consumer<PacketBuffer> payloadWriter) {
int widgetId = modularUI.guiWidgets.inverse().get(widget);
PacketBuffer packetBuffer = new PacketBuffer(Unpooled.buffer());
packetBuffer.writeVarInt(updateId);
payloadWriter.accept(packetBuffer);
if (modularUI.entityPlayer instanceof EntityPlayerMP) {
PacketUIWidgetUpdate widgetUpdate = new PacketUIWidgetUpdate(windowId, widgetId, packetBuffer);
if (!accumulateWidgetUpdateData) {
NetworkHandler.channel.sendTo(NetworkHandler.packet2proxy(widgetUpdate), (EntityPlayerMP) modularUI.entityPlayer);
} else {
accumulatedUpdates.add(widgetUpdate);
}
}
}
use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.
the class SyncedTileEntityBase method getUpdateTag.
@Override
public NBTTagCompound getUpdateTag() {
NBTTagCompound updateTag = super.getUpdateTag();
ByteBuf backedBuffer = Unpooled.buffer();
writeInitialSyncData(new PacketBuffer(backedBuffer));
byte[] updateData = Arrays.copyOfRange(backedBuffer.array(), 0, backedBuffer.writerIndex());
updateTag.setByteArray("d", updateData);
return updateTag;
}
use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.
the class SyncedTileEntityBase method handleUpdateTag.
@Override
public void handleUpdateTag(@Nonnull NBTTagCompound tag) {
// deserializes Forge data and capabilities
super.readFromNBT(tag);
byte[] updateData = tag.getByteArray("d");
ByteBuf backedBuffer = Unpooled.copiedBuffer(updateData);
receiveInitialSyncData(new PacketBuffer(backedBuffer));
}
use of net.minecraft.network.PacketBuffer in project GregTech by GregTechCE.
the class NetworkHandler method proxy2packet.
@SuppressWarnings("unchecked")
public static Packet proxy2packet(FMLProxyPacket packet) {
PacketBuffer payload = (PacketBuffer) packet.payload();
Class<Packet> packetClass = (Class<Packet>) packetMap.get(payload.readVarInt());
PacketCodec<Packet> codec = (PacketCodec<Packet>) codecMap.get(packetClass);
return codec.decoder.decode(payload);
}
Aggregations