Example usage for io.netty.buffer ByteBuf readUnsignedShort

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

Introduction

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

Prototype

public abstract int readUnsignedShort();

Source Link

Document

Gets an unsigned 16-bit short integer at the current readerIndex and increases the readerIndex by 2 in this buffer.

Usage

From source file:buildcraft.core.builders.TileAbstractBuilder.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf stream) {
    int size = stream.readUnsignedShort();
    pathLasers.clear();//  w ww  .java2 s  .co  m
    for (int i = 0; i < size; i++) {
        LaserData ld = new LaserData();
        ld.readData(stream);
        pathLasers.add(ld);
    }
}

From source file:buildcraft.core.lib.network.PacketNBT.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    super.readData(data);

    int length = data.readUnsignedShort();
    byte[] compressed = new byte[length];
    data.readBytes(compressed);//from  w  w w.  java 2 s. c o  m

    try {
        this.nbttagcompound = CompressedStreamTools.func_152457_a(compressed, NBTSizeTracker.field_152451_a);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:buildcraft.core.lib.network.PacketSlotChange.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    super.readData(data);

    this.slot = data.readUnsignedShort();
    stack = NetworkUtils.readStack(data);
}

From source file:buildcraft.core.lib.network.PacketTileState.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    super.readData(data);

    state = Unpooled.buffer();//w w  w  .  ja v a 2  s  .co  m
    int length = data.readUnsignedShort();
    state.writeBytes(data.readBytes(length));
}

From source file:buildcraft.factory.TileQuarry.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf stream) {
    super.readData(stream);
    box.readData(stream);/*from   w w  w .j av a2 s .c o m*/
    targetX = stream.readInt();
    targetY = stream.readUnsignedShort();
    targetZ = stream.readInt();
    headPosX = stream.readDouble();
    headPosY = stream.readDouble();
    headPosZ = stream.readDouble();
    speed = stream.readFloat();
    headTrajectory = stream.readFloat();
    int flags = stream.readUnsignedByte();
    stage = Stage.values()[flags & 0x07];
    movingHorizontally = (flags & 0x10) != 0;
    movingVertically = (flags & 0x20) != 0;

    createUtilsIfNeeded();

    if (arm != null) {
        arm.setHead(headPosX, headPosY, headPosZ);
        arm.updatePosition();
    }
}

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

License:Mozilla Public License

@Override
public void handleUpdateTag(NBTTagCompound tag) {
    super.readFromNBT(tag);
    byte[] bytes = tag.getByteArray("d");
    ByteBuf buf = Unpooled.copiedBuffer(bytes);

    try {/*from ww  w .  ja  va 2 s .c  om*/
        int id = buf.readUnsignedShort();
        readPayload(id, new PacketBufferBC(buf), world.isRemote ? Side.CLIENT : Side.SERVER, null);
        // Make sure that we actually read the entire message rather than just discarding it
        MessageUtil.ensureEmpty(buf, world.isRemote, getClass().getSimpleName());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    spawnReceiveParticles();
}

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;// w ww . j a v a 2  s. co  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.ContainerZonePlan.java

License:Minecraft Mod Public

@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    if (side.isClient()) {
        if ("areaLoaded".equals(command)) {
            currentAreaSelection = new ZonePlan();
            currentAreaSelection.readData(stream);
            gui.refreshSelectedArea();//from   w  w  w.  j  a va2s. co  m
        } else if ("receiveImage".equals(command)) {
            int size = stream.readUnsignedMedium();
            int pos = stream.readUnsignedMedium();

            for (int i = 0; i < Math.min(size - pos, MAX_PACKET_LENGTH); ++i) {
                mapTexture.colorMap[pos + i] = 0xFF000000
                        | MapColor.mapColorArray[stream.readUnsignedByte()].colorValue;
            }
        }
    } else if (side.isServer()) {
        if ("loadArea".equals(command)) {
            final int index = stream.readUnsignedByte();
            BuildCraftCore.instance.sendToPlayer((EntityPlayer) sender,
                    new PacketCommand(this, "areaLoaded", new CommandWriter() {
                        public void write(ByteBuf data) {
                            map.selectArea(index).writeData(data);
                        }
                    }));
        } else if ("saveArea".equals(command)) {
            final int index = stream.readUnsignedByte();
            ZonePlan plan = new ZonePlan();
            plan.readData(stream);
            map.setArea(index, plan);
        } else if ("computeMap".equals(command)) {
            computeMap(stream.readInt(), stream.readInt(), stream.readUnsignedShort(),
                    stream.readUnsignedShort(), stream.readFloat(), (EntityPlayer) sender);
        } else if ("setName".equals(command)) {
            map.mapName = NetworkUtils.readUTF(stream);
        }
    }
}

From source file:buildcraft.robots.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 = Utils.readStack(stream);
        } else if ("clientSetInventory".equals(command)) {
            int slot = stream.readUnsignedShort();
            inv[slot] = Utils.readStack(stream);
        } else if ("initialize".equals(command)) {
            itemInUse = Utils.readStack(stream);
            itemActive = stream.readBoolean();
        } else if ("setItemActive".equals(command)) {
            itemActive = stream.readBoolean();
            itemActiveStage = 0;//www. ja v  a2  s.co 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 (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) {
                    Utils.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);
                                Utils.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:com.cloudhopper.smpp.util.ChannelBufferUtil.java

License:Apache License

/**
 * Reads a TLV from a buffer. This method is greedy and will read bytes
 * even if it won't be able to successfully complete.  It's assumed this
 * method will only be called if its known ahead of time that all bytes
 * will be available ahead of time.//w  w  w .  j ava  2s .  c o m
 * @param buffer The buffer to read from
 * @return A new TLV instance
 * @throws NotEnoughDataInBufferException
 */
static public Tlv readTlv(ByteBuf buffer) throws NotEnoughDataInBufferException {
    // a TLV is at least 4 bytes (tag+length)
    if (buffer.readableBytes() < 4) {
        throw new NotEnoughDataInBufferException("Parsing TLV tag and length", buffer.readableBytes(), 4);
    }

    short tag = buffer.readShort();
    int length = buffer.readUnsignedShort();

    // check if we have enough data for the TLV
    if (buffer.readableBytes() < length) {
        throw new NotEnoughDataInBufferException("Parsing TLV value", buffer.readableBytes(), length);
    }

    byte[] value = new byte[length];
    buffer.readBytes(value);

    return new Tlv(tag, value);
}