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);
});
}
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);
});
}
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);
}
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);
}
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());
}
Aggregations