Search in sources :

Example 21 with PacketBufferBC

use of buildcraft.lib.net.PacketBufferBC in project BuildCraft by BuildCraft.

the class PipeFlowFluids method writePayload.

@Override
public void writePayload(int id, PacketBuffer buf, Side side) {
    PacketBufferBC buffer = PacketBufferBC.asPacketBufferBc(buf);
    if (side == Side.SERVER) {
        if (id == NET_FLUID_AMOUNTS || id == NET_ID_FULL_STATE) {
            boolean full = id == NET_ID_FULL_STATE;
            if (currentFluid == null) {
                buffer.writeBoolean(false);
            } else {
                buffer.writeBoolean(true);
                buffer.writeInt(BuildCraftObjectCaches.CACHE_FLUIDS.server().store(currentFluid));
            }
            for (EnumPipePart part : EnumPipePart.VALUES) {
                Section section = sections.get(part);
                if (full) {
                    buffer.writeShort(section.amount);
                } else if (section.amount == section.lastSentAmount) {
                    buffer.writeBoolean(false);
                } else {
                    buffer.writeBoolean(true);
                    buffer.writeShort(section.amount);
                    section.lastSentAmount = section.amount;
                }
                Dir should = Dir.get(section.ticksInDirection);
                // This writes out 2 bits so don't bother with a boolean flag
                buffer.writeEnumValue(should);
                section.lastSentDirection = should;
            }
        }
    }
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC) EnumPipePart(buildcraft.api.core.EnumPipePart)

Example 22 with PacketBufferBC

use of buildcraft.lib.net.PacketBufferBC in project BuildCraft by BuildCraft.

the class PluggablePulsar method writeData.

private void writeData(PacketBuffer b) {
    PacketBufferBC buffer = PacketBufferBC.asPacketBufferBc(b);
    buffer.writeBoolean(isPulsing());
    buffer.writeBoolean(gateEnabledTicks > 0 || gateSinglePulses > 0);
    buffer.writeBoolean(manuallyEnabled);
    buffer.writeByte(pulseStage);
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC)

Example 23 with PacketBufferBC

use of buildcraft.lib.net.PacketBufferBC in project BuildCraft by BuildCraft.

the class PluggablePulsar method readData.

private void readData(PacketBuffer b) {
    PacketBufferBC buffer = PacketBufferBC.asPacketBufferBc(b);
    isPulsing = buffer.readBoolean();
    autoEnabled = buffer.readBoolean();
    manuallyEnabled = buffer.readBoolean();
    pulseStage = buffer.readByte();
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC)

Example 24 with PacketBufferBC

use of buildcraft.lib.net.PacketBufferBC in project BuildCraft by BuildCraft.

the class ContainerBC_Neptune method sendMessage.

public final void sendMessage(int id, IPayloadWriter writer) {
    PacketBufferBC payload = PacketBufferBC.write(writer);
    MessageContainer message = new MessageContainer(windowId, id, payload);
    if (player.world.isRemote) {
        MessageManager.sendToServer(message);
    } else {
        MessageManager.sendTo(message, (EntityPlayerMP) player);
    }
}
Also used : MessageContainer(buildcraft.lib.net.MessageContainer) PacketBufferBC(buildcraft.lib.net.PacketBufferBC)

Example 25 with PacketBufferBC

use of buildcraft.lib.net.PacketBufferBC in project BuildCraft by BuildCraft.

the class PacketBufferBcTest method testAmongst.

@Test
public void testAmongst() {
    PacketBufferBC buffer = new PrintingByteBuf(Unpooled.buffer());
    buffer.writeInt(49);
    buffer.writeBoolean(true);
    buffer.writeShort(95);
    buffer.writeBoolean(false);
    buffer.writeByte(11);
    buffer.writeBoolean(true);
    byte[] expected = { // writeInt(49)
    0, 0, 0, 49, // flag(true, false, true)
    1 + 4, // writeShort(95)
    0, 95, // writeByte(11)
    11 };
    byte[] read = new byte[expected.length];
    buffer.getBytes(0, read);
    Assert.assertArrayEquals(expected, read);
    Assert.assertEquals(49, buffer.readInt());
    Assert.assertTrue(buffer.readBoolean());
    Assert.assertEquals(95, buffer.readShort());
    Assert.assertFalse(buffer.readBoolean());
    Assert.assertEquals(11, buffer.readByte());
    Assert.assertTrue(buffer.readBoolean());
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC) Test(org.junit.Test)

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