Example usage for io.netty.buffer ByteBuf writeShort

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

Introduction

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

Prototype

public abstract ByteBuf writeShort(int value);

Source Link

Document

Sets the specified 16-bit short integer at the current writerIndex and increases the writerIndex by 2 in this buffer.

Usage

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

License:Minecraft Mod Public

@Override
public void write(ByteBuf data, Object o, SerializationContext context)
        throws IllegalArgumentException, IllegalAccessException {
    HashSet<?> set = (HashSet<?>) o;

    if (o == null) {
        data.writeBoolean(false);//from w w w. j ava2s  .  c  o  m
    } else {
        data.writeBoolean(true);
        data.writeShort(set.size());

        for (Object item : set) {
            anonymousSerializer.write(data, item, context);
        }
    }
}

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);//from  w  w w  . j a v  a  2s . co m
    } else {
        data.writeBoolean(true);
        data.writeShort(list.size());

        for (Object val : list) {
            anonymousSerializer.write(data, val, context);
        }
    }
}

From source file:buildcraft.factory.gui.ContainerRefinery.java

License:Minecraft Mod Public

public void setFilter(final int slot, final Fluid filter) {

    refinery.setFilter(slot, filter);/*from   w w w .j a v a2  s  .  c om*/

    if (refinery.getWorldObj().isRemote) {
        PacketPayload payload = new PacketPayload(new PacketPayload.StreamWriter() {
            @Override
            public void writeData(ByteBuf data) {
                data.writeByte(slot);
                data.writeShort(filter != null ? filter.getID() : -1);
            }
        });
        BuildCraftFactory.instance.sendToServer(new PacketUpdate(PacketIds.REFINERY_FILTER_SET, refinery.xCoord,
                refinery.yCoord, refinery.zCoord, payload));
    }
}

From source file:buildcraft.factory.TileQuarry.java

License:Minecraft Mod Public

@Override
public void writeData(ByteBuf stream) {
    super.writeData(stream);
    box.writeData(stream);//from  w  w w  .  j ava2s.  c o  m
    stream.writeInt(targetX);
    stream.writeShort(targetY);
    stream.writeInt(targetZ);
    stream.writeDouble(headPosX);
    stream.writeDouble(headPosY);
    stream.writeDouble(headPosZ);
    stream.writeFloat((float) speed);
    stream.writeFloat((float) headTrajectory);
    int flags = stage.ordinal();
    flags |= movingHorizontally ? 0x10 : 0;
    flags |= movingVertically ? 0x20 : 0;
    stream.writeByte(flags);
}

From source file:buildcraft.lib.tile.TileBC_Neptune.java

License:Mozilla Public License

@Override
public NBTTagCompound getUpdateTag() {
    ByteBuf buf = Unpooled.buffer();
    buf.writeShort(NET_RENDER_DATA);
    writePayload(NET_RENDER_DATA, new PacketBufferBC(buf), world.isRemote ? Side.CLIENT : Side.SERVER);
    byte[] bytes = new byte[buf.readableBytes()];
    buf.readBytes(bytes);/* w  w  w  .  j a  v a  2s. c  om*/

    NBTTagCompound nbt = super.getUpdateTag();
    nbt.setByteArray("d", bytes);
    return nbt;
}

From source file:buildcraft.robotics.EntityRobot.java

License:Minecraft Mod Public

public void updateClientSlot(final int slot) {
    BuildCraftCore.instance.sendToEntity(new PacketCommand(this, "clientSetInventory", new CommandWriter() {
        public void write(ByteBuf data) {
            data.writeShort(slot);
            NetworkUtils.writeStack(data, inv[slot]);
        }//from   w w  w . j  a  va2  s  . c om
    }), this);
}

From source file:buildcraft.robotics.EntityRobot.java

License:Minecraft Mod Public

private void setSteamDirection(final int x, final int y, final int z) {
    if (!worldObj.isRemote) {
        BuildCraftCore.instance.sendToEntity(new PacketCommand(this, "setSteamDirection", new CommandWriter() {
            public void write(ByteBuf data) {
                data.writeInt(x);//  w  ww.ja  v a2 s .com
                data.writeShort(y);
                data.writeInt(z);
            }
        }), this);
    } else {
        Vec3 v = Vec3.createVectorHelper(x, y, z);
        v = v.normalize();

        steamDx = (int) v.xCoord;
        steamDy = (int) v.yCoord;
        steamDz = (int) v.zCoord;
    }
}

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 www  .j  a v a  2s.  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.gui.GuiZonePlan.java

License:Minecraft Mod Public

private void uploadMap() {
    BuildCraftCore.instance.sendToServer(new PacketCommand(getContainer(), "computeMap", new CommandWriter() {
        public void write(ByteBuf data) {
            data.writeInt(cx);/*from w  ww . j a v a 2  s . co  m*/
            data.writeInt(cz);
            data.writeShort(getContainer().mapTexture.width);
            data.writeShort(getContainer().mapTexture.height);
            data.writeFloat(blocksPerPixel);
        }
    }));
}

From source file:buildcraft.robotics.TileZonePlan.java

License:Minecraft Mod Public

@Override
public void writeData(ByteBuf stream) {
    stream.writeShort(progress);
    NetworkUtils.writeUTF(stream, mapName);
    stream.writeBytes(previewColors, 0, 80);
}