Example usage for io.netty.buffer ByteBuf readUnsignedByte

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

Introduction

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

Prototype

public abstract short readUnsignedByte();

Source Link

Document

Gets an unsigned byte at the current readerIndex and increases the readerIndex by 1 in this buffer.

Usage

From source file:org.spout.vanilla.protocol.codec.window.WindowPropertyCodec.java

License:Open Source License

@Override
public WindowPropertyMessage decode(ByteBuf buffer) throws IOException {
    int id = buffer.readUnsignedByte();
    int progressBar = buffer.readUnsignedShort();
    int value = buffer.readUnsignedShort();
    return new WindowPropertyMessage(id, progressBar, value);
}

From source file:org.spout.vanilla.protocol.codec.window.WindowSlotCodec.java

License:Open Source License

@Override
public WindowSlotMessage decode(ByteBuf buffer) throws IOException {
    int id = buffer.readUnsignedByte();
    int slot = buffer.readUnsignedShort();
    ItemStack item = VanillaByteBufUtils.readItemStack(buffer);
    return new WindowSlotMessage(id, slot, item);
}

From source file:org.spout.vanilla.protocol.codec.window.WindowTransactionCodec.java

License:Open Source License

@Override
public WindowTransactionMessage decode(ByteBuf buffer) throws IOException {
    int id = buffer.readUnsignedByte();
    int transaction = buffer.readUnsignedShort();
    boolean accepted = buffer.readUnsignedByte() != 0;
    return new WindowTransactionMessage(id, transaction, accepted);
}

From source file:org.spout.vanilla.protocol.codec.world.block.BlockChangeCodec.java

License:Open Source License

@Override
public BlockChangeMessage decode(ByteBuf buffer) throws IOException {
    int x = buffer.readInt();
    int y = buffer.readUnsignedByte();
    int z = buffer.readInt();
    short type = buffer.readShort();
    int metadata = buffer.readUnsignedByte();
    return new BlockChangeMessage(x, y, z, type, metadata, NullRepositionManager.getInstance());
}

From source file:org.spout.vanilla.protocol.codec.world.EffectCodec.java

License:Open Source License

@Override
public EffectMessage decode(ByteBuf buffer) throws IOException {
    int id = buffer.readInt();
    int x = buffer.readInt();
    int y = buffer.readUnsignedByte();
    int z = buffer.readInt();
    int data = buffer.readInt();
    boolean volumeDecrease = buffer.readByte() != 0;
    return new EffectMessage(id, x, y, z, data, volumeDecrease, NullRepositionManager.getInstance());
}

From source file:org.spout.vanilla.protocol.codec.world.SoundEffectCodec.java

License:Open Source License

@Override
public SoundEffectMessage decode(ByteBuf buffer) throws IOException {
    String soundName = VanillaByteBufUtils.readString(buffer);
    float x = (float) buffer.readInt() / 8.0f;
    float y = (float) buffer.readInt() / 8.0f;
    float z = (float) buffer.readInt() / 8.0f;
    float volume = buffer.readFloat();
    float pitch = 63f / (float) buffer.readUnsignedByte();
    return new SoundEffectMessage(soundName, x, y, z, volume, pitch, NullRepositionManager.getInstance());
}

From source file:org.spout.vanilla.protocol.VanillaByteBufUtils.java

License:Open Source License

/**
 * Reads a list of parameters from the buffer.
 *
 * @param buf The buffer./*from  ww w .  j  a  v  a 2  s .  co  m*/
 * @return The parameters.
 */
public static List<Parameter<?>> readParameters(ByteBuf buf) throws IOException {
    List<Parameter<?>> parameters = new ArrayList<Parameter<?>>();

    for (int b = buf.readUnsignedByte(); b != 127; b = buf.readUnsignedByte()) {
        int type = (b & 0xE0) >> 5;
        int index = b & 0x1F;

        switch (type) {
        case Parameter.TYPE_BYTE:
            parameters.add(new Parameter<Byte>(type, index, buf.readByte()));
            break;
        case Parameter.TYPE_SHORT:
            parameters.add(new Parameter<Short>(type, index, buf.readShort()));
            break;
        case Parameter.TYPE_INT:
            parameters.add(new Parameter<Integer>(type, index, buf.readInt()));
            break;
        case Parameter.TYPE_FLOAT:
            parameters.add(new Parameter<Float>(type, index, buf.readFloat()));
            break;
        case Parameter.TYPE_STRING:
            parameters.add(new Parameter<String>(type, index, readString(buf)));
            break;
        case Parameter.TYPE_ITEM:
            parameters.add(new Parameter<ItemStack>(type, index, readItemStack(buf)));
            break;
        }
    }

    return parameters;
}

From source file:org.spout.vanilla.protocol.VanillaByteBufUtils.java

License:Open Source License

public static ItemStack readItemStack(ByteBuf buffer) throws IOException {
    short id = buffer.readShort();
    if (id < 0) {
        return null;
    } else {//from   ww  w  .  j  a v a  2s  .com
        Material material = VanillaMaterials.getMaterial(id);
        if (material == null) {
            throw new IOException("Unknown material with id of " + id);
        }
        int count = buffer.readUnsignedByte();
        int damage = buffer.readUnsignedShort();
        CompoundMap nbtData = readCompound(buffer);
        return new ItemStack(material, damage, count).setNBTData(nbtData);
    }
}

From source file:org.spout.vanilla.protocol.VanillaProtocol.java

License:Open Source License

@Override
public MessageCodec<?> readHeader(ByteBuf buf) throws UnknownPacketException {
    int opcode = buf.readUnsignedByte();
    MessageCodec<?> codec = getCodecLookupService().find(opcode);
    if (codec == null) {
        throw new UnknownPacketException(opcode);
    }/*from  w  ww  . j av  a  2 s.c om*/
    return codec;
}