Example usage for io.netty.buffer ByteBuf readInt

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

Introduction

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

Prototype

public abstract int readInt();

Source Link

Document

Gets a 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.

Usage

From source file:books.netty.protocol.netty.codec.TestCodeC.java

License:Apache License

public NettyMessage decode(ByteBuf in) throws Exception {
    NettyMessage message = new NettyMessage();
    Header header = new Header();
    header.setCrcCode(in.readInt());
    header.setLength(in.readInt());/*from  w  w  w .  j  a v  a 2s  . com*/
    header.setSessionID(in.readLong());
    header.setType(in.readByte());
    header.setPriority(in.readByte());

    int size = in.readInt();
    if (size > 0) {
        Map<String, Object> attch = new HashMap<String, Object>(size);
        int keySize = 0;
        byte[] keyArray = null;
        String key = null;
        for (int i = 0; i < size; i++) {
            keySize = in.readInt();
            keyArray = new byte[keySize];
            in.readBytes(keyArray);
            key = new String(keyArray, "UTF-8");
            attch.put(key, marshallingDecoder.decode(in));
        }
        keyArray = null;
        key = null;
        header.setAttachment(attch);
    }
    if (in.readableBytes() > 4) {
        message.setBody(marshallingDecoder.decode(in));
    }
    message.setHeader(header);
    return message;
}

From source file:buildcraft.builders.network.PacketLibraryAction.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    actionId = data.readInt();
    super.readData(data);
}

From source file:buildcraft.builders.TileBuilder.java

License:Minecraft Mod Public

@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    super.receiveCommand(command, side, sender, stream);
    if (side.isClient()) {
        if ("clearItemRequirements".equals(command)) {
            requiredToBuild = null;/*from  w w w  .  j  a va  2 s  .com*/
        } else if ("setItemRequirements".equals(command)) {
            int size = stream.readUnsignedShort();
            requiredToBuild = new ArrayList<ItemStack>();
            for (int i = 0; i < size; i++) {
                ItemStack stack = Utils.readStack(stream);
                stack.stackSize = Math.min(999, stream.readUnsignedShort());
                requiredToBuild.add(stack);
            }
        }
    } else if (side.isServer()) {
        EntityPlayer player = (EntityPlayer) sender;
        if ("eraseFluidTank".equals(command)) {
            int id = stream.readInt();
            if (id < 0 || id >= fluidTanks.length) {
                return;
            }
            if (isUseableByPlayer(player) && player.getDistanceSq(xCoord, yCoord, zCoord) <= 64) {
                fluidTanks[id].setFluid(null);
                sendNetworkUpdate();
            }
        }
    }
}

From source file:buildcraft.builders.TileQuarry.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf stream) {
    super.readData(stream);
    box.readData(stream);/*w  w w  .  j av a  2 s . c om*/
    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;
    int newLedState = stream.readUnsignedByte();
    if (newLedState != ledState) {
        ledState = newLedState;
        worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
    }

    createUtilsIfNeeded();

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

From source file:buildcraft.builders.urbanism.AnchoredBox.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf stream) {
    box.readData(stream);
    x1 = stream.readInt();
    y1 = stream.readShort();
    z1 = stream.readInt();
}

From source file:buildcraft.builders.urbanism.TileUrbanist.java

License:Minecraft Mod Public

@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    // Non-XYZ commands go here
    if (side.isClient() && "setFrameKind".equals(command)) {
        setFrameKind(stream.readInt(), stream.readInt());
    } else if (side.isServer() && "startFiller".equals(command)) {
        String fillerTag = Utils.readUTF(stream);
        Box box = new Box();
        box.readData(stream);/*  w w  w  . jav a 2 s  .  c o  m*/

        startFiller(fillerTag, box);
    } else {
        // XYZ commands go here
        int x = stream.readInt();
        int y = stream.readInt();
        int z = stream.readInt();

        if (side.isServer() && "setBlock".equals(command)) {
            worldObj.setBlock(x, y, z, Blocks.brick_block);
        } else if (side.isServer() && "eraseBlock".equals(command)) {
            // tasks.add(new UrbanistTaskErase(this, x, y, z));
        } else if ("createFrame".equals(command)) {
            createFrame(x, y, z);
        } else if ("moveFrame".equals(command)) {
            moveFrame(x, y, z);
        }
    }
}

From source file:buildcraft.commander.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 ww  .ja va2  s .com
        } else if ("receiveImage".equals(command)) {
            int size = stream.readUnsignedMedium();

            for (int i = 0; i < size; ++i) {
                mapTexture.colorMap[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.readUnsignedByte(), (EntityPlayer) sender);
        }
    }
}

From source file:buildcraft.core.Box.java

License:Minecraft Mod Public

public void readFromStream(ByteBuf stream) {
    initialized = stream.readBoolean();/* w w w .  j  a v a 2s  . co  m*/

    xMin = stream.readInt();
    yMin = stream.readInt();
    zMin = stream.readInt();

    xMax = stream.readInt();
    yMax = stream.readInt();
    zMax = stream.readInt();
}

From source file:buildcraft.core.ChunkIndex.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf stream) {
    x = stream.readInt();
    z = stream.readInt();
}

From source file:buildcraft.core.EntityRobot.java

License:Minecraft Mod Public

@Override
public void readSpawnData(ByteBuf data) {

    box = new Box();
    box.xMin = data.readInt();
    box.yMin = data.readInt();/*from   ww w . ja va 2 s . co m*/
    box.zMin = data.readInt();
    box.xMax = data.readInt();
    box.yMax = data.readInt();
    box.zMax = data.readInt();

    init();
}