use of net.minecraft.network.PacketBuffer in project Railcraft by Railcraft.
the class RailcraftPacket method getPacket.
public FMLProxyPacket getPacket() {
ByteBuf byteBuf = Unpooled.buffer();
try (ByteBufOutputStream out = new ByteBufOutputStream(byteBuf);
RailcraftOutputStream data = new RailcraftOutputStream(out)) {
data.writeByte(getID());
writeData(data);
return new FMLProxyPacket(new PacketBuffer(byteBuf), CHANNEL_NAME);
} catch (IOException e) {
Game.log().throwable("Error constructing packet: {0}", e, getClass());
if (Game.DEVELOPMENT_VERSION)
throw new RuntimeException(e);
}
PacketBuffer buffer = new PacketBuffer(byteBuf);
buffer.writeByte(-1);
return new FMLProxyPacket(buffer, CHANNEL_NAME);
}
use of net.minecraft.network.PacketBuffer in project LogisticsPipes by RS485.
the class PacketHandler method toFMLPacket.
private static FMLProxyPacket toFMLPacket(ModernPacket msg, String channel) {
ByteBuf buffer = Unpooled.buffer();
fillByteBuf(msg, buffer);
return new FMLProxyPacket(new PacketBuffer(buffer), channel);
}
use of net.minecraft.network.PacketBuffer in project pnc-repressurized by TeamPneumatic.
the class PacketUpdateGui method readField.
public static Object readField(ByteBuf buf, int type) {
switch(type) {
case 0:
return buf.readInt();
case 1:
return buf.readFloat();
case 2:
return buf.readDouble();
case 3:
return buf.readBoolean();
case 4:
return ByteBufUtils.readUTF8String(buf);
case 5:
return buf.readByte();
case 6:
return ByteBufUtils.readItemStack(buf);
case 7:
if (!buf.readBoolean())
return null;
return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf));
case 8:
try {
PacketBuffer packetBuffer = new PacketBuffer(buf);
NBTTagCompound tag = packetBuffer.readCompoundTag();
if (tag == null)
return EmptyHandler.INSTANCE;
ItemStackHandler handler = new ItemStackHandler();
handler.deserializeNBT(tag);
return handler;
} catch (IOException e) {
return EmptyHandler.INSTANCE;
}
}
throw new IllegalArgumentException("Invalid sync type! " + type);
}
use of net.minecraft.network.PacketBuffer in project pnc-repressurized by TeamPneumatic.
the class PacketUpdateGui method writeField.
public static void writeField(ByteBuf buf, Object value, int type) {
switch(type) {
case 0:
buf.writeInt((Integer) value);
break;
case 1:
buf.writeFloat((Float) value);
break;
case 2:
buf.writeDouble((Double) value);
break;
case 3:
buf.writeBoolean((Boolean) value);
break;
case 4:
ByteBufUtils.writeUTF8String(buf, (String) value);
break;
case 5:
buf.writeByte((Byte) value);
break;
case 6:
ByteBufUtils.writeItemStack(buf, (ItemStack) value);
break;
case 7:
buf.writeBoolean(value != null);
if (value != null) {
FluidStack stack = (FluidStack) value;
ByteBufUtils.writeUTF8String(buf, stack.getFluid().getName());
buf.writeInt(stack.amount);
ByteBufUtils.writeTag(buf, stack.tag);
}
break;
case 8:
NBTTagCompound tag = ((ItemStackHandler) value).serializeNBT();
PacketBuffer packetBuffer = new PacketBuffer(buf);
packetBuffer.writeCompoundTag(tag);
break;
}
}
use of net.minecraft.network.PacketBuffer in project pnc-repressurized by TeamPneumatic.
the class DescPacketHandler method getPacket.
public static FMLProxyPacket getPacket(PacketDescription packet) {
ByteBuf buf = Unpooled.buffer();
packet.toBytes(buf);
return new FMLProxyPacket(new PacketBuffer(buf), CHANNEL);
}
Aggregations