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:buildcraft.core.gui.ContainerList.java

License:Minecraft Mod Public

public void setStack(final int lineIndex, final int slotIndex, final ItemStack stack) {
    lines[lineIndex].setStack(slotIndex, stack);
    ItemList.saveLine(player.getCurrentEquippedItem(), lines[lineIndex], lineIndex);

    if (player.worldObj.isRemote) {
        BuildCraftCore.instance.sendToServer(new PacketCommand(this, "setStack", new CommandWriter() {
            public void write(ByteBuf data) {
                data.writeByte(lineIndex);
                data.writeByte(slotIndex);
                Utils.writeStack(data, stack);
            }/*ww w .  j a v  a 2s.c  o m*/
        }));
    }
}

From source file:buildcraft.core.gui.ContainerList.java

License:Minecraft Mod Public

public void switchButton(final int lineIndex, final int button) {
    if (button == 0) {
        lines[lineIndex].oreWildcard = false;
        lines[lineIndex].subitemsWildcard = !lines[lineIndex].subitemsWildcard;
    } else if (button == 1 && lines[lineIndex].isOre) {
        lines[lineIndex].subitemsWildcard = false;
        lines[lineIndex].oreWildcard = !lines[lineIndex].oreWildcard;
    }/*from w  w  w .j av a  2 s.co m*/

    ItemList.saveLine(player.getCurrentEquippedItem(), lines[lineIndex], lineIndex);

    if (player.worldObj.isRemote) {
        BuildCraftCore.instance.sendToServer(new PacketCommand(this, "switchButton", new CommandWriter() {
            public void write(ByteBuf data) {
                data.writeByte(lineIndex);
                data.writeByte(button);
            }
        }));
    }
}

From source file:buildcraft.core.lib.engines.TileEngineBase.java

License:Minecraft Mod Public

@Override
public void writeData(ByteBuf stream) {
    stream.writeByte(energyStage.ordinal() | (isPumping ? 8 : 0));
    stream.writeByte(orientation.ordinal());
}

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

License:Minecraft Mod Public

@Override
protected void encode(ChannelHandlerContext ctx, Packet msg, List<Object> out) throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    Class<? extends Packet> clazz = msg.getClass();
    byte discriminator = types.get(clazz);
    buffer.writeByte(discriminator);
    msg.writeData(buffer);//w w w  . ja v a2  s .  c o m
    FMLProxyPacket proxy = new FMLProxyPacket(buffer.copy(),
            ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    WeakReference<FMLProxyPacket> ref = ctx.attr(INBOUNDPACKETTRACKER).get().get();
    FMLProxyPacket old = ref == null ? null : ref.get();
    if (old != null) {
        proxy.setDispatcher(old.getDispatcher());
    }
    out.add(proxy);
}

From source file:buildcraft.core.lib.network.command.PacketCommand.java

License:Minecraft Mod Public

@Override
public void writeData(ByteBuf data) {
    NetworkUtils.writeUTF(data, command);
    data.writeByte(targets.indexOf(handler));
    handler.write(data, target);/*from   ww w  . j a  va 2s  . c  o  m*/
    if (writer != null) {
        writer.write(data);
    }
}

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

License:Minecraft Mod Public

@Override
public void writeData(ByteBuf data) {
    data.writeByte(id);
    data.writeInt(posX);
    data.writeShort(posY);
    data.writeInt(posZ);
}

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

License:Minecraft Mod Public

@Override
public void writeData(ByteBuf data) {
    data.writeByte(windowId);
    data.writeByte(widgetId);
    data.writeBytes(payload);
}

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

License:Minecraft Mod Public

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

    ByteBuf tmpState = Unpooled.buffer();

    tmpState.writeByte(stateList.size());
    for (StateWithId stateWithId : stateList) {
        tmpState.writeByte(stateWithId.stateId);
        stateWithId.state.writeData(tmpState);
    }//  w  w w  . j  a v  a  2s. c om

    data.writeShort((short) tmpState.readableBytes());
    data.writeBytes(tmpState.readBytes(tmpState.readableBytes()));
}

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

License:Minecraft Mod Public

@Override
public void writeData(ByteBuf data) {
    data.writeByte(packetId);
    writeIdentificationData(data);/*from w ww .j a v a  2  s  .c  om*/

    if (payload != null) {
        payload.writeData(data);
    }
}

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

License:Minecraft Mod Public

/**
 * This subprogram transforms a packet into a FML packet to be send in the
 * minecraft default packet mechanism. This always use BC-CORE as a
 * channel, and as a result, should use discriminators declared there.
 *
 * WARNING! The implementation of this subprogram relies on the internal
 * behavior of #FMLIndexedMessageToMessageCodec (in particular the encode
 * member). It is probably opening a maintenance issue and should be
 * replaced eventually by some more solid mechanism.
 */// w  w w . j a va2 s . c  om
public static FMLProxyPacket toPacket(Packet packet, int discriminator) {
    ByteBuf buf = Unpooled.buffer();

    buf.writeByte((byte) discriminator);
    packet.writeData(buf);

    return new FMLProxyPacket(buf, DefaultProps.NET_CHANNEL_NAME + "-CORE");
}