use of buildcraft.lib.net.PacketBufferBC in project BuildCraft by BuildCraft.
the class PacketBufferBcTest method testEnums.
@Test
public void testEnums() {
PacketBufferBC buffer = new PrintingByteBuf(Unpooled.buffer());
buffer.writeBoolean(true);
buffer.writeEnumValue(EnumFacing.DOWN);
buffer.writeEnumValue(EnumFacing.SOUTH);
buffer.writeEnumValue(EnumDyeColor.BROWN);
buffer.writeEnumValue(EnumDyeColor.CYAN);
Assert.assertTrue(buffer.readBoolean());
Assert.assertEquals(EnumFacing.DOWN, buffer.readEnumValue(EnumFacing.class));
Assert.assertEquals(EnumFacing.SOUTH, buffer.readEnumValue(EnumFacing.class));
Assert.assertEquals(EnumDyeColor.BROWN, buffer.readEnumValue(EnumDyeColor.class));
Assert.assertEquals(EnumDyeColor.CYAN, buffer.readEnumValue(EnumDyeColor.class));
Assert.assertEquals(2, buffer.readerIndex());
Assert.assertEquals(2, buffer.writerIndex());
}
use of buildcraft.lib.net.PacketBufferBC in project BuildCraft by BuildCraft.
the class PacketBufferBcTest method testFixedBits.
@Test
public void testFixedBits() {
PacketBufferBC buffer = new PrintingByteBuf(Unpooled.buffer());
int value = 0xA4;
int value2 = 1;
int value3 = 0xF_81_67;
int value4 = 0x7E_DC_A9_87;
buffer.writeFixedBits(value, 10);
buffer.writeFixedBits(value2, 2);
buffer.writeBoolean(true);
buffer.writeFixedBits(value3, 20);
buffer.writeFixedBits(value4, 31);
int read = buffer.readFixedBits(10);
Assert.assertEquals(value, read);
int read2 = buffer.readFixedBits(2);
Assert.assertEquals(value2, read2);
Assert.assertTrue(buffer.readBoolean());
int read3 = buffer.readFixedBits(20);
Assert.assertEquals(value3, read3);
int read4 = buffer.readFixedBits(31);
Assert.assertEquals(value4, read4);
Assert.assertEquals(8, buffer.readerIndex());
Assert.assertEquals(8, buffer.writerIndex());
}
use of buildcraft.lib.net.PacketBufferBC in project BuildCraft by BuildCraft.
the class TriggerParameterSignal method readFromBuf.
public static TriggerParameterSignal readFromBuf(PacketBuffer buffer) {
PacketBufferBC buf = PacketBufferBC.asPacketBufferBc(buffer);
EnumDyeColor colour = MessageUtil.readEnumOrNull(buf, EnumDyeColor.class);
if (colour == null) {
return EMPTY;
} else {
return get(buf.readBoolean(), colour);
}
}
use of buildcraft.lib.net.PacketBufferBC in project BuildCraft by BuildCraft.
the class MessageVolumeBoxes method toBytes.
@Override
public void toBytes(ByteBuf buffer) {
PacketBufferBC buf = PacketBufferBC.asPacketBufferBc(buffer);
buf.writeInt(buffers.size());
for (PacketBufferBC localBuffer : buffers) {
buf.writeVarInt(localBuffer.readableBytes());
buf.writeBytes(localBuffer, 0, localBuffer.readableBytes());
}
}
use of buildcraft.lib.net.PacketBufferBC in project BuildCraft by BuildCraft.
the class MessageVolumeBoxes method fromBytes.
@Override
public void fromBytes(ByteBuf buffer) {
PacketBufferBC buf = PacketBufferBC.asPacketBufferBc(buffer);
buffers.clear();
int count = buf.readInt();
for (int i = 0; i < count; i++) {
int bytes = buf.readVarInt();
PacketBufferBC packet = new PacketBufferBC(buf.readBytes(bytes));
buffers.add(packet);
}
}
Aggregations