Search in sources :

Example 11 with PacketBufferBC

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

the class PipeFlowItems method sendItemDataToClient.

void sendItemDataToClient(TravellingItem item) {
    final int stackId = BuildCraftObjectCaches.storeItemStack(item.stack);
    sendCustomPayload(NET_CREATE_ITEM, (buffer) -> {
        PacketBufferBC buf = PacketBufferBC.asPacketBufferBc(buffer);
        buf.writeInt(stackId);
        buf.writeShort(item.stack.getCount());
        buf.writeBoolean(item.toCenter);
        buf.writeEnumValue(item.side);
        MessageUtil.writeEnumOrNull(buf, item.colour);
        buf.writeShort(item.timeToDest > Short.MAX_VALUE ? Short.MAX_VALUE : item.timeToDest);
    });
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC)

Example 12 with PacketBufferBC

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

the class Lock method toBytes.

public void toBytes(PacketBuffer buf) {
    new PacketBufferBC(buf).writeEnumValue(Cause.EnumCause.getForClass(cause.getClass()));
    cause.toBytes(buf);
    buf.writeInt(targets.size());
    targets.forEach(target -> {
        new PacketBuffer(buf).writeEnumValue(Target.EnumTarget.getForClass(target.getClass()));
        target.toBytes(buf);
    });
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 13 with PacketBufferBC

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

the class Lock method fromBytes.

public void fromBytes(PacketBuffer buf) {
    cause = new PacketBufferBC(buf).readEnumValue(Cause.EnumCause.class).supplier.get();
    cause.fromBytes(buf);
    targets.clear();
    IntStream.range(0, buf.readInt()).mapToObj(i -> {
        Target target;
        target = new PacketBufferBC(buf).readEnumValue(Target.EnumTarget.class).supplier.get();
        target.fromBytes(buf);
        return target;
    }).forEach(targets::add);
}
Also used : IntStream(java.util.stream.IntStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketBufferBC(buildcraft.lib.net.PacketBufferBC) Arrays(java.util.Arrays) World(net.minecraft.world.World) LaserData_BC8(buildcraft.lib.client.render.laser.LaserData_BC8) BlockPos(net.minecraft.util.math.BlockPos) Supplier(java.util.function.Supplier) BuildCraftLaserManager(buildcraft.core.client.BuildCraftLaserManager) ArrayList(java.util.ArrayList) NBTUtilBC(buildcraft.lib.misc.NBTUtilBC) List(java.util.List) Block(net.minecraft.block.Block) Side(net.minecraftforge.fml.relauncher.Side) MessageUtil(buildcraft.lib.misc.MessageUtil) ResourceLocation(net.minecraft.util.ResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) NBTUtil(net.minecraft.nbt.NBTUtil) PacketBuffer(net.minecraft.network.PacketBuffer) PacketBufferBC(buildcraft.lib.net.PacketBufferBC)

Example 14 with PacketBufferBC

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

the class VolumeBox method fromBytes.

public void fromBytes(PacketBufferBC buf) throws IOException {
    id = buf.readUniqueId();
    box = new Box();
    box.readData(buf);
    player = buf.readBoolean() ? buf.readUniqueId() : null;
    Map<EnumAddonSlot, Addon> newAddons = new EnumMap<>(EnumAddonSlot.class);
    int count = buf.readInt();
    for (int i = 0; i < count; i++) {
        EnumAddonSlot slot = buf.readEnumValue(EnumAddonSlot.class);
        ResourceLocation rl = new ResourceLocation(buf.readString(1024));
        Class<? extends Addon> addonClass = AddonsRegistry.INSTANCE.getClassByName(rl);
        try {
            if (addonClass == null) {
                throw new IOException("Unknown addon class " + rl);
            }
            Addon addon = addonClass.newInstance();
            addon.volumeBox = this;
            addon.onAdded();
            addon.fromBytes(buf);
            newAddons.put(slot, addon);
        } catch (InstantiationException | IllegalAccessException e) {
            throw new IOException("Failed to deserialize addon!", e);
        }
    }
    addons.keySet().removeIf(slot -> !newAddons.containsKey(slot));
    newAddons.entrySet().stream().filter(slotAddon -> !addons.containsKey(slotAddon.getKey())).forEach(slotAddon -> addons.put(slotAddon.getKey(), slotAddon.getValue()));
    for (Map.Entry<EnumAddonSlot, Addon> slotAddon : newAddons.entrySet()) {
        PacketBufferBC buffer = new PacketBufferBC(Unpooled.buffer());
        slotAddon.getValue().toBytes(buffer);
        addons.get(slotAddon.getKey()).fromBytes(buffer);
    }
    locks.clear();
    IntStream.range(0, buf.readInt()).mapToObj(i -> {
        Lock lock = new Lock();
        lock.fromBytes(buf);
        return lock;
    }).forEach(locks::add);
}
Also used : IntStream(java.util.stream.IntStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Box(buildcraft.lib.misc.data.Box) PacketBufferBC(buildcraft.lib.net.PacketBufferBC) EnumMap(java.util.EnumMap) World(net.minecraft.world.World) IOException(java.io.IOException) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) ArrayList(java.util.ArrayList) Unpooled(io.netty.buffer.Unpooled) Objects(java.util.Objects) NBTUtilBC(buildcraft.lib.misc.NBTUtilBC) List(java.util.List) Stream(java.util.stream.Stream) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Map(java.util.Map) ResourceLocation(net.minecraft.util.ResourceLocation) NBTUtil(net.minecraft.nbt.NBTUtil) Box(buildcraft.lib.misc.data.Box) IOException(java.io.IOException) PacketBufferBC(buildcraft.lib.net.PacketBufferBC) ResourceLocation(net.minecraft.util.ResourceLocation) EnumMap(java.util.EnumMap) EnumMap(java.util.EnumMap) Map(java.util.Map)

Example 15 with PacketBufferBC

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

the class PacketBufferBcTest method testMultiple.

@Test
public void testMultiple() {
    PacketBufferBC buffer = new PrintingByteBuf(Unpooled.buffer());
    for (int i = 0; i < 17; i++) {
        boolean value = i % 2 == 0;
        buffer.writeBoolean(value);
    }
    PrintingByteBuf print = new PrintingByteBuf(Unpooled.buffer());
    print.writeBytes(buffer, 0, buffer.readableBytes());
    Assert.assertEquals(3, buffer.writerIndex());
    for (int i = 0; i < 17; i++) {
        boolean value = i % 2 == 0;
        Assert.assertTrue(value == buffer.readBoolean());
    }
    Assert.assertEquals(3, buffer.readerIndex());
}
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