Search in sources :

Example 16 with PacketBufferBC

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());
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC) EnumFacing(net.minecraft.util.EnumFacing) EnumDyeColor(net.minecraft.item.EnumDyeColor) Test(org.junit.Test)

Example 17 with PacketBufferBC

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());
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC) Test(org.junit.Test)

Example 18 with PacketBufferBC

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);
    }
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC) EnumDyeColor(net.minecraft.item.EnumDyeColor)

Example 19 with PacketBufferBC

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());
    }
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC)

Example 20 with PacketBufferBC

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);
    }
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC)

Aggregations

PacketBufferBC (buildcraft.lib.net.PacketBufferBC)31 Test (org.junit.Test)6 EnumPipePart (buildcraft.api.core.EnumPipePart)4 IOException (java.io.IOException)4 List (java.util.List)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTUtilBC (buildcraft.lib.misc.NBTUtilBC)3 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 IntStream (java.util.stream.IntStream)3 EnumDyeColor (net.minecraft.item.EnumDyeColor)3 EnumFacing (net.minecraft.util.EnumFacing)3 BlockPos (net.minecraft.util.math.BlockPos)3 World (net.minecraft.world.World)3 Side (net.minecraftforge.fml.relauncher.Side)3 Box (buildcraft.lib.misc.data.Box)2 ByteBuf (io.netty.buffer.ByteBuf)2 ItemStack (net.minecraft.item.ItemStack)2 NBTUtil (net.minecraft.nbt.NBTUtil)2 PacketBuffer (net.minecraft.network.PacketBuffer)2