Example usage for io.netty.buffer ByteBuf writeInt

List of usage examples for io.netty.buffer ByteBuf writeInt

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeInt.

Prototype

public abstract ByteBuf writeInt(int value);

Source Link

Document

Sets the specified 32-bit integer at the current writerIndex and increases the writerIndex by 4 in this buffer.

Usage

From source file:buildcraft.core.network.serializers.SerializerBitSet.java

License:Minecraft Mod Public

@Override
public void write(ByteBuf data, Object o, SerializationContext context) {
    if (o == null) {
        data.writeBoolean(false);// w w  w  .  jav  a  2  s.c o m
    } else {
        data.writeBoolean(true);

        BitSet set = (BitSet) o;
        byte[] bytes = BitSetUtils.toByteArray(set);
        data.writeInt(bytes.length);
        data.writeBytes(bytes);
    }
}

From source file:buildcraft.core.network.serializers.SerializerBlock.java

License:Minecraft Mod Public

@Override
public void write(ByteBuf data, Object o, SerializationContext context) {
    Block b = (Block) o;/*from w w  w .  j a  v  a 2s .  c om*/

    if (b == null) {
        data.writeBoolean(false);
    } else {
        data.writeBoolean(true);
        data.writeInt(Block.getIdFromBlock(b));
    }
}

From source file:buildcraft.core.network.serializers.SerializerFluidStack.java

License:Minecraft Mod Public

@Override
public void write(ByteBuf data, Object o, SerializationContext context) {
    FluidStack stack = (FluidStack) o;/*w  w w  .  jav a2s. c o  m*/

    if (stack == null) {
        data.writeBoolean(false);
    } else {
        data.writeShort(stack.getFluid().getID());
        data.writeInt(stack.amount);

        if (stack.tag == null) {
            data.writeBoolean(false);
        } else {
            data.writeBoolean(true);
            Utils.writeNBT(data, stack.tag);
        }
    }

}

From source file:buildcraft.core.network.serializers.SerializerInteger.java

License:Minecraft Mod Public

@Override
public void write(ByteBuf data, Object o, SerializationContext context) {
    Integer i = (Integer) o;

    data.writeInt(i);
}

From source file:buildcraft.core.network.serializers.SerializerItem.java

License:Minecraft Mod Public

@Override
public void write(ByteBuf data, Object o, SerializationContext context) {
    Item i = (Item) o;//from  w  w  w  . j av  a 2s .  c  om

    if (i == null) {
        data.writeBoolean(false);
    } else {
        data.writeBoolean(true);
        data.writeInt(Item.getIdFromItem(i));
    }
}

From source file:buildcraft.core.network.TilePacketWrapper.java

License:Minecraft Mod Public

public PacketPayload toPayload(final TileEntity tile) {
    return new PacketPayload(new PacketPayload.StreamWriter() {
        @Override/*from   w ww  .  j  av  a 2  s .  c  o  m*/
        public void writeData(ByteBuf data) {
            data.writeInt(tile.xCoord);
            data.writeInt(tile.yCoord);
            data.writeInt(tile.zCoord);

            try {
                SerializationContext context = new SerializationContext();
                rootMappings[0].write(data, tile, context);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:buildcraft.core.network.TilePacketWrapper.java

License:Minecraft Mod Public

public PacketPayload toPayload(final int x, final int y, final int z, final Object[] obj) {
    return new PacketPayload(new PacketPayload.StreamWriter() {
        @Override// w  w w  . j  av a2s . c om
        public void writeData(ByteBuf data) {
            data.writeInt(x);
            data.writeInt(y);
            data.writeInt(z);

            for (int i = 0; i < rootMappings.length; ++i) {
                try {
                    SerializationContext context = new SerializationContext();
                    rootMappings[0].write(data, obj[i], context);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }

        }
    });
}

From source file:buildcraft.core.utils.Utils.java

License:Minecraft Mod Public

public static void writeUTF(ByteBuf data, String str) {
    try {//from   w  ww  . java 2  s.c om
        byte[] b = str.getBytes("UTF-8");
        data.writeInt(b.length);
        data.writeBytes(b);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        data.writeInt(0);
    }
}

From source file:buildcraft.core.utils.Utils.java

License:Minecraft Mod Public

public static void writeNBT(ByteBuf data, NBTTagCompound nbt) {
    try {/*from  w ww  .  j a v  a2s .  c o m*/
        byte[] compressed = CompressedStreamTools.compress(nbt);
        data.writeInt(compressed.length);
        data.writeBytes(compressed);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:buildcraft.core.ZonePlan.java

License:Minecraft Mod Public

@Override
public void writeData(ByteBuf stream) {
    stream.writeInt(chunkMapping.size());
    for (Map.Entry<ChunkIndex, ZoneChunk> e : chunkMapping.entrySet()) {
        e.getKey().writeData(stream);/*from  w ww.j  a v a  2s. c  o m*/
        e.getValue().writeData(stream);
    }
}