Example usage for io.netty.buffer ByteBuf readBoolean

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

Introduction

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

Prototype

public abstract boolean readBoolean();

Source Link

Document

Gets a boolean at the current readerIndex and increases the readerIndex by 1 in this buffer.

Usage

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

License:Minecraft Mod Public

@Override
public Object read(ByteBuf data, Object o, SerializationContext context) {
    if (!data.readBoolean()) {
        return null;
    } else {//from   ww w.jav a  2 s  .  c  o m
        return Utils.readNBT(data);
    }
}

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

License:Minecraft Mod Public

@Override
public Object read(ByteBuf data, Object o, SerializationContext context) throws IllegalArgumentException,
        IllegalAccessException, InstantiationException, ClassNotFoundException {

    if (!data.readBoolean()) {
        return null;
    } else {//from   w  w w. j  a va 2s  .  c  om
        int index = data.readByte();

        ClassSerializer delegateMapping;

        if (context.idToClass.size() < index) {
            String className = Utils.readUTF(data);

            Class cls = Class.forName(className);
            delegateMapping = ClassMapping.get(cls);

            context.idToClass.add(ClassMapping.get(cls));
        } else {
            delegateMapping = context.idToClass.get(index - 1);
        }

        if (delegateMapping instanceof ClassMapping) {
            return ((ClassMapping) delegateMapping).readClass(o, data, context);
        } else {
            return delegateMapping.read(data, o, context);
        }
    }
}

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

License:Minecraft Mod Public

@Override
public Object read(ByteBuf data, Object o, SerializationContext context) {
    if (!data.readBoolean()) {
        return null;
    } else {//from w  w w.ja va2 s.c  o  m
        return Utils.readUTF(data);
    }
}

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

License:Minecraft Mod Public

public static ItemStack readStack(ByteBuf data) {
    if (!data.readBoolean()) {
        return null;
    } else {/*  www . j  ava2 s  .c  o m*/
        NBTTagCompound nbt = readNBT(data);
        return ItemStack.loadItemStackFromNBT(nbt);
    }
}

From source file:buildcraft.core.ZoneChunk.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf stream) {
    if (stream.readBoolean()) {
        property = BitSetUtils.fromByteArray(Utils.readByteArray(stream));
    }//from w  w w. j  ava2s. c  o  m
    fullSet = stream.readBoolean();
}

From source file:buildcraft.factory.TilePump.java

License:Minecraft Mod Public

@Override
public void handleUpdatePacket(PacketUpdate packet) throws IOException {
    PacketPayload payload = packet.payload;
    ByteBuf data = payload.stream;
    aimY = data.readInt();//from   w  ww . ja  v a2s . c  om
    tubeY = data.readFloat();
    powered = data.readBoolean();

    setTubePosition();
}

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 w w w .j a  va  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.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;/*from ww w.  j  a v a2s  .  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:buildcraft.silicon.TileAssemblyTable.java

License:Minecraft Mod Public

@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    if (side.isServer() && "select".equals(command)) {
        String id = Utils.readUTF(stream);
        boolean select = stream.readBoolean();

        IFlexibleRecipe<ItemStack> recipe = AssemblyRecipeManager.INSTANCE.getRecipe(id);

        if (recipe != null) {
            if (select) {
                planOutput(recipe);/* w w  w.ja  v  a  2  s  .  c om*/
            } else {
                cancelPlanOutput(recipe);
            }
        }
    }
}

From source file:buildcraft.transport.network.PacketPipeTransportTraveler.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    this.itemX = data.readFloat();
    this.itemY = data.readFloat();
    this.itemZ = data.readFloat();

    posX = MathHelper.floor_float(itemX);
    posY = MathHelper.floor_float(itemY);
    posZ = MathHelper.floor_float(itemZ);

    this.entityId = data.readShort();

    this.input = ForgeDirection.getOrientation(data.readByte());
    this.output = ForgeDirection.getOrientation(data.readByte());

    byte c = data.readByte();
    if (c != -1) {
        this.color = EnumColor.fromId(c);
    }/*www.ja  va 2s  . c o  m*/

    this.speed = data.readFloat();

    this.forceStackRefresh = data.readBoolean();
}