Example usage for io.netty.buffer ByteBuf writeByte

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

Introduction

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

Prototype

public abstract ByteBuf writeByte(int value);

Source Link

Document

Sets the specified byte at the current writerIndex and increases the writerIndex by 1 in this buffer.

Usage

From source file:appeng.tile.misc.TileInscriber.java

License:Open Source License

@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileInscriber(final ByteBuf data) throws IOException {
    int slot = this.isSmash() ? 64 : 0;

    for (int num = 0; num < this.inv.getSizeInventory(); num++) {
        if (this.inv.getStackInSlot(num) != null) {
            slot |= (1 << num);// ww  w .  ja  v a2s .com
        }
    }

    data.writeByte(slot);
    for (int num = 0; num < this.inv.getSizeInventory(); num++) {
        if ((slot & (1 << num)) > 0) {
            final AEItemStack st = AEItemStack.create(this.inv.getStackInSlot(num));
            st.writeToPacket(data);
        }
    }
}

From source file:appeng.tile.misc.TilePaint.java

License:Open Source License

private void writeBuffer(final ByteBuf out) {
    if (this.dots == null) {
        out.writeByte(0);
        return;//from   w  w w. jav  a2  s  .  co  m
    }

    out.writeByte(this.dots.size());

    for (final Splotch s : this.dots) {
        s.writeToStream(out);
    }
}

From source file:appeng.tile.misc.TileSecurity.java

License:Open Source License

@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileSecurity(final ByteBuf data) {
    data.writeBoolean(this.getProxy().isActive());
    data.writeByte(this.paintedColor.ordinal());
}

From source file:appeng.tile.networking.TileWireless.java

License:Open Source License

@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileWireless(final ByteBuf data) {
    this.setClientFlags(0);

    try {/*from w  w  w . jav a 2 s . c  o m*/
        if (this.getProxy().getEnergy().isNetworkPowered()) {
            this.setClientFlags(this.getClientFlags() | POWERED_FLAG);
        }

        if (this.getProxy().getNode().meetsChannelRequirements()) {
            this.setClientFlags(this.getClientFlags() | CHANNEL_FLAG);
        }
    } catch (final GridAccessException e) {
        // meh
    }

    data.writeByte((byte) this.getClientFlags());
}

From source file:appeng.tile.qnb.TileQuantumBridge.java

License:Open Source License

@TileEvent(TileEventType.NETWORK_WRITE)
public void onNetworkWriteEvent(final ByteBuf data) {
    int out = this.constructed;

    if (this.getStackInSlot(0) != null && this.constructed != -1) {
        out |= this.hasSingularity;
    }//from w  ww.j a va2 s .  c o  m

    if (this.getProxy().isActive() && this.constructed != -1) {
        out |= this.powered;
    }

    data.writeByte((byte) out);
}

From source file:appeng.tile.spatial.TileSpatialPylon.java

License:Open Source License

@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileSpatialPylon(final ByteBuf data) {
    data.writeByte(this.displayBits);
}

From source file:appeng.tile.storage.TileChest.java

License:Open Source License

@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileChest(final ByteBuf data) {
    if (this.worldObj.getTotalWorldTime() - this.lastStateChange > 8) {
        this.state = 0;
    } else {/*  w  ww  .j av a 2s .  co  m*/
        this.state &= 0x24924924; // just keep the blinks...
    }

    for (int x = 0; x < this.getCellCount(); x++) {
        this.state |= (this.getCellStatus(x) << (3 * x));
    }

    if (this.isPowered()) {
        this.state |= 0x40;
    } else {
        this.state &= ~0x40;
    }

    data.writeByte(this.state);
    data.writeByte(this.paintedColor.ordinal());

    final ItemStack is = this.inv.getStackInSlot(1);

    if (is == null) {
        data.writeInt(0);
    } else {
        data.writeInt((is.getItemDamage() << Platform.DEF_OFFSET) | Item.getIdFromItem(is.getItem()));
    }
}

From source file:appeng.util.item.AEFluidStack.java

License:Open Source License

@Override
void writeIdentity(final ByteBuf i) throws IOException {
    final byte[] name = this.fluid.getName().getBytes("UTF-8");
    i.writeByte((byte) name.length);
    i.writeBytes(name);//from  www . j  a v a2  s. co m
}

From source file:appeng.util.item.AEStack.java

License:Open Source License

@Override
public void writeToPacket(final ByteBuf i) throws IOException {
    final byte mask = (byte) (this.getType(0) | (this.getType(this.stackSize) << 2)
            | (this.getType(this.countRequestable) << 4) | ((byte) (this.isCraftable ? 1 : 0) << 6)
            | (this.hasTagCompound() ? 1 : 0) << 7);

    i.writeByte(mask);
    this.writeIdentity(i);

    this.readNBT(i);

    // putPacketValue( i, priority );
    this.putPacketValue(i, this.stackSize);
    this.putPacketValue(i, this.countRequestable);
}

From source file:appeng.util.item.AEStack.java

License:Open Source License

private void putPacketValue(final ByteBuf tag, final long num) {
    if (num <= 255) {
        tag.writeByte((byte) (num + Byte.MIN_VALUE));
    } else if (num <= 65535) {
        tag.writeShort((short) (num + Short.MIN_VALUE));
    } else if (num <= 4294967295L) {
        tag.writeInt((int) (num + Integer.MIN_VALUE));
    } else {/*from ww  w. jav a 2 s.co m*/
        tag.writeLong(num);
    }
}