List of usage examples for io.netty.buffer ByteBuf writeInt
public abstract ByteBuf writeInt(int value);
From source file:com.builtbroken.atomic.network.packet.PacketBase.java
/** * Called to write data without manually defining the write * * @param object - object to write/* w w w . ja v a2 s . c om*/ * @param buffer - location to write to */ protected void writeData(Object object, ByteBuf buffer) { if (object.getClass().isArray()) { for (int i = 0; i < Array.getLength(object); i++) { writeData(Array.get(object, i), buffer); } } else if (object instanceof Collection) { for (Object o : (Collection) object) { writeData(o, buffer); } } else if (object instanceof Byte) { buffer.writeByte((Byte) object); } else if (object instanceof Integer) { buffer.writeInt((Integer) object); } else if (object instanceof Short) { buffer.writeShort((Short) object); } else if (object instanceof Long) { buffer.writeLong((Long) object); } else if (object instanceof Float) { buffer.writeFloat((Float) object); } else if (object instanceof Double) { buffer.writeDouble((Double) object); } else if (object instanceof Boolean) { buffer.writeBoolean((Boolean) object); } else if (object instanceof String) { ByteBufUtils.writeUTF8String(buffer, (String) object); } else if (object instanceof NBTTagCompound) { ByteBufUtils.writeTag(buffer, (NBTTagCompound) object); } else if (object instanceof ItemStack) { ByteBufUtils.writeItemStack(buffer, (ItemStack) object); } else if (object instanceof FluidTank) { ByteBufUtils.writeTag(buffer, ((FluidTank) object).writeToNBT(new NBTTagCompound())); } else if (object instanceof Pos) { ((Pos) object).writeByteBuf(buffer); } else if (object instanceof IByteBufWriter) { ((IByteBufWriter) object).writeBytes(buffer); } else if (object instanceof Enum) { buffer.writeInt(((Enum) object).ordinal()); } else { throw new IllegalArgumentException("PacketBase: Unsupported write data type " + object); } }
From source file:com.builtbroken.atomic.network.packet.sync.PacketPlayerRadiation.java
@Override public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { buffer.writeFloat(rads);/*from w ww. j ava 2 s. c o m*/ buffer.writeFloat(rads_area); buffer.writeInt(rad_remove_timer); }
From source file:com.builtbroken.atomic.network.packet.trigger.PacketMouse.java
@Override public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { buffer.writeInt(slot); buffer.writeBoolean(forward);/*from w w w . j a v a 2 s . c o m*/ buffer.writeBoolean(ctrl); }
From source file:com.builtbroken.grappling.network.packets.PacketMouseClick.java
@Override public void write(ByteBuf buffer) { buffer.writeInt(slot); buffer.writeInt(button); buffer.writeInt(dwheel); buffer.writeBoolean(state); }
From source file:com.builtbroken.icbm.content.blast.entity.slime.EntitySlimeRain.java
@Override public void writeSpawnData(ByteBuf buffer) { buffer.writeInt(color.getRed()); buffer.writeInt(color.getGreen());//from ww w .j a v a 2 s . c o m buffer.writeInt(color.getBlue()); }
From source file:com.builtbroken.icbm.content.fragments.EntityFragment.java
@Override public void writeSpawnData(ByteBuf buffer) { if (fragmentType != null) { buffer.writeByte(fragmentType.ordinal()); } else {/* w ww . j a v a 2 s. c o m*/ buffer.writeByte(-1); } if (fragmentMaterial != null) { buffer.writeInt(Block.getIdFromBlock(fragmentMaterial)); } else { buffer.writeByte(-1); } if (renderShape != null) { buffer.writeBoolean(true); renderShape.writeBytes(buffer); } else { buffer.writeBoolean(false); } }
From source file:com.builtbroken.icbm.content.launcher.controller.remote.display.TileSiloInterface.java
protected void writeConnectorSet(TileCommandController controller, ByteBuf data) { ByteBufUtils.writeUTF8String(data, controller.getControllerDisplayName() == null ? "--" : controller.getControllerDisplayName()); data.writeInt(controller.siloConnectors != null ? controller.siloConnectors.entrySet().size() : 0); for (Map.Entry<Pos, TileCommandSiloConnector> entry : controller.siloConnectors.entrySet()) { writeCommandSiloConnector(entry, data); }/* ww w . j a v a2s.c o m*/ }
From source file:com.builtbroken.icbm.content.launcher.controller.remote.display.TileSiloInterface.java
protected void writeCommandSiloConnector(Map.Entry<Pos, TileCommandSiloConnector> entry, ByteBuf data) { //Write location data so it can be pulled data.writeInt(entry.getKey().xi()); data.writeInt(entry.getKey().yi());// w ww . j a v a2s.c o m data.writeInt(entry.getKey().zi()); if (entry.getValue() != null) { List<ISiloConnectionData> list = entry.getValue().getSiloConnectionData(); if (list != null && list.size() > 0) { //Write size of data list data.writeInt(list.size()); //Convert data to NBT as this is the easiest way to load it NBTTagCompound save = new NBTTagCompound(); NBTTagList tagList = new NBTTagList(); for (ISiloConnectionData siloData : list) { tagList.appendTag(siloData.save(new NBTTagCompound())); } save.setTag("data", tagList); ByteBufUtils.writeTag(data, save); } else { data.writeInt(0); //Empty connection } } else { data.writeInt(-1); //No connection } }
From source file:com.builtbroken.icbm.content.launcher.launcher.standard.StandardMissileCrafting.java
@Override public ByteBuf writeBytes(ByteBuf buf) { buf.writeInt(rodsContained); buf.writeInt(platesContained);// ww w.j a va2 s . c om ByteBufUtils.writeItemStack(buf, warhead != null ? warhead : new ItemStack(Blocks.stone)); ByteBufUtils.writeItemStack(buf, rocketComputer != null ? rocketComputer : new ItemStack(Blocks.stone)); ByteBufUtils.writeItemStack(buf, rocketEngine != null ? rocketEngine : new ItemStack(Blocks.stone)); return buf; }
From source file:com.builtbroken.icbm.content.rail.EntityMissileCart.java
@Override public void writeSpawnData(ByteBuf buffer) { super.writeSpawnData(buffer); buffer.writeInt(getType().ordinal()); buffer.writeBoolean(cargoStack != null); if (cargoStack != null) { ByteBufUtils.writeItemStack(buffer, cargoStack); }/* w ww . ja va 2 s. co m*/ }