List of usage examples for io.netty.buffer ByteBuf writeBoolean
public abstract ByteBuf writeBoolean(boolean value);
From source file:buildcraft.core.network.serializers.SerializerItemStack.java
License:Minecraft Mod Public
@Override public void write(ByteBuf data, Object o, SerializationContext context) { ItemStack stack = (ItemStack) o;/*from www . j av a 2 s .com*/ if (stack == null) { data.writeBoolean(false); } else { data.writeBoolean(true); NBTTagCompound nbt = new NBTTagCompound(); stack.writeToNBT(nbt); Utils.writeNBT(data, nbt); } }
From source file:buildcraft.core.network.serializers.SerializerLinkedList.java
License:Minecraft Mod Public
@Override public void write(ByteBuf data, Object o, SerializationContext context) throws IllegalArgumentException, IllegalAccessException { LinkedList list = (LinkedList) o; if (o == null) { data.writeBoolean(false); } else {//from w ww . j av a 2s .c o m data.writeBoolean(true); data.writeShort(list.size()); for (Object val : list) { anonymousSerializer.write(data, val, context); } } }
From source file:buildcraft.core.network.serializers.SerializerNBT.java
License:Minecraft Mod Public
@Override public void write(ByteBuf data, Object o, SerializationContext context) { NBTTagCompound nbt = (NBTTagCompound) o; if (nbt == null) { data.writeBoolean(false); } else {/*from w ww. j a v a 2s . co m*/ data.writeBoolean(true); Utils.writeNBT(data, nbt); } }
From source file:buildcraft.core.network.serializers.SerializerObject.java
License:Minecraft Mod Public
@Override public void write(ByteBuf data, Object o, SerializationContext context) throws IllegalArgumentException, IllegalAccessException { if (o == null) { data.writeBoolean(false); } else {/*from ww w . j a va2 s .com*/ data.writeBoolean(true); Class realClass = o.getClass(); ClassSerializer delegateMapping; if (context.classToId.containsKey(realClass.getCanonicalName())) { int index = context.classToId.get(realClass.getCanonicalName()) + 1; data.writeByte(index); delegateMapping = context.idToClass.get(index - 1); } else { int index = context.classToId.size() + 1; delegateMapping = ClassMapping.get(realClass); data.writeByte(index); Utils.writeUTF(data, realClass.getCanonicalName()); context.classToId.put(realClass.getCanonicalName(), context.classToId.size()); context.idToClass.add(delegateMapping); } if (delegateMapping instanceof ClassMapping) { ((ClassMapping) delegateMapping).writeClass(o, data, context); } else { delegateMapping.write(data, o, context); } } }
From source file:buildcraft.core.network.serializers.SerializerString.java
License:Minecraft Mod Public
@Override public void write(ByteBuf data, Object o, SerializationContext context) { String s = (String) o; if (s == null) { data.writeBoolean(false); } else {// w w w .j a v a2s . c o m data.writeBoolean(true); Utils.writeUTF(data, s); } }
From source file:buildcraft.core.utils.Utils.java
License:Minecraft Mod Public
public static void writeStack(ByteBuf data, ItemStack stack) { if (stack == null) { data.writeBoolean(false); } else {//from w w w.j a v a 2s. com data.writeBoolean(true); NBTTagCompound nbt = new NBTTagCompound(); stack.writeToNBT(nbt); Utils.writeNBT(data, nbt); } }
From source file:buildcraft.core.ZoneChunk.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf stream) { if (property != null) { stream.writeBoolean(true); Utils.writeByteArray(stream, BitSetUtils.toByteArray(property)); } else {//from w ww. jav a 2s . c o m stream.writeBoolean(false); } stream.writeBoolean(fullSet); }
From source file:buildcraft.factory.TilePump.java
License:Minecraft Mod Public
@Override public PacketPayload getPacketPayload() { PacketPayload payload = new PacketPayload(new PacketPayload.StreamWriter() { @Override/* w w w.j a v a 2 s . c o m*/ public void writeData(ByteBuf buf) { buf.writeInt(aimY); buf.writeFloat((float) tubeY); buf.writeBoolean(powered); } }); return payload; }
From source file:buildcraft.robotics.EntityRobot.java
License:Minecraft Mod Public
@Override public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) { if (side.isClient()) { if ("clientSetItemInUse".equals(command)) { itemInUse = NetworkUtils.readStack(stream); } else if ("clientSetInventory".equals(command)) { int slot = stream.readUnsignedShort(); inv[slot] = NetworkUtils.readStack(stream); } else if ("initialize".equals(command)) { itemInUse = NetworkUtils.readStack(stream); itemActive = stream.readBoolean(); } else if ("setItemActive".equals(command)) { itemActive = stream.readBoolean(); itemActiveStage = 0;/*from w w w. jav a2 s . c o m*/ lastUpdateTime = new Date().getTime(); if (!itemActive) { setSteamDirection(0, -1, 0); } } else if ("setSteamDirection".equals(command)) { setSteamDirection(stream.readInt(), stream.readShort(), stream.readInt()); } else if ("syncWearables".equals(command)) { wearables.clear(); int amount = stream.readUnsignedByte(); while (amount > 0) { wearables.add(NetworkUtils.readStack(stream)); amount--; } } } else if (side.isServer()) { EntityPlayer p = (EntityPlayer) sender; if ("requestInitialization".equals(command)) { BuildCraftCore.instance.sendToPlayer(p, new PacketCommand(this, "initialize", new CommandWriter() { public void write(ByteBuf data) { NetworkUtils.writeStack(data, itemInUse); data.writeBoolean(itemActive); } })); for (int i = 0; i < inv.length; ++i) { final int j = i; BuildCraftCore.instance.sendToPlayer(p, new PacketCommand(this, "clientSetInventory", new CommandWriter() { public void write(ByteBuf data) { data.writeShort(j); NetworkUtils.writeStack(data, inv[j]); } })); } if (currentDockingStation != null) { setSteamDirection(currentDockingStation.side.offsetX, currentDockingStation.side.offsetY, currentDockingStation.side.offsetZ); } else { setSteamDirection(0, -1, 0); } } } }
From source file:buildcraft.robotics.EntityRobot.java
License:Minecraft Mod Public
@Override public void setItemActive(final boolean isActive) { if (isActive != itemActive) { itemActive = isActive;//from ww w . j a v a 2 s. co m BuildCraftCore.instance.sendToEntity(new PacketCommand(this, "setItemActive", new CommandWriter() { public void write(ByteBuf data) { data.writeBoolean(isActive); } }), this); } }