List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:buildcraft.robots.EntityRobot.java
License:Minecraft Mod Public
public void updateClientSlot(final int slot) { BuildCraftCore.instance.sendToWorld(new PacketCommand(this, "clientSetInventory", new CommandWriter() { public void write(ByteBuf data) { data.writeShort(slot); Utils.writeStack(data, inv[slot]); }/*from w w w .j a v a 2 s. c o m*/ }), worldObj); }
From source file:buildcraft.robots.EntityRobot.java
License:Minecraft Mod Public
private void setSteamDirection(final int x, final int y, final int z) { if (!worldObj.isRemote) { BuildCraftCore.instance.sendToWorld(new PacketCommand(this, "setSteamDirection", new CommandWriter() { public void write(ByteBuf data) { data.writeInt(x);/*from w w w. java 2 s .c o m*/ data.writeShort(y); data.writeInt(z); } }), worldObj); } else { Vec3 v = Vec3.createVectorHelper(x, y, z); v = v.normalize(); steamDx = (int) v.xCoord; steamDy = (int) v.yCoord; steamDz = (int) v.zCoord; } }
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 www . ja v a 2 s . 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 (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.TileLaser.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf stream) { laser.writeData(stream); stream.writeShort(powerAverage); }
From source file:buildcraft.transport.network.PacketFluidUpdate.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { super.writeData(data); byte[] dBytes = toByteArray(delta); // System.out.printf("write %d, %d, %d = %s, %s%n", posX, posY, posZ, Arrays.toString(dBytes), delta); data.writeBytes(dBytes);/* ww w .j a v a 2 s .com*/ for (ForgeDirection dir : ForgeDirection.values()) { FluidStack liquid = renderCache[dir.ordinal()]; if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_ID_BIT)) { if (liquid != null) { data.writeShort(liquid.fluidID); data.writeInt(colorRenderCache[dir.ordinal()]); } else { data.writeShort(0); data.writeInt(0xFFFFFF); } } if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_AMOUNT_BIT)) { if (liquid != null) { data.writeInt(liquid.amount); } else { data.writeInt(0); } } } }
From source file:buildcraft.transport.network.PacketPipeTransportItemStackRequest.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { data.writeShort(travelerID); }
From source file:buildcraft.transport.network.PacketPipeTransportTraveler.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { data.writeFloat((float) item.xCoord); data.writeFloat((float) item.yCoord); data.writeFloat((float) item.zCoord); data.writeShort(item.id); data.writeByte((byte) item.input.ordinal()); data.writeByte((byte) item.output.ordinal()); data.writeByte(item.color != null ? item.color.ordinal() : -1); data.writeFloat(item.getSpeed());//from ww w. j a va 2 s .c o m data.writeBoolean(forceStackRefresh); }
From source file:buildcraft.transport.utils.FacadeMatrix.java
License:Minecraft Mod Public
public void writeData(ByteBuf data) { for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { if (blocks[i] == null) { data.writeShort(0); } else {/*from w w w . j av a 2s . co m*/ data.writeShort(Block.blockRegistry.getIDForObject(blocks[i])); } data.writeByte(blockMetas[i]); } }
From source file:cc.blynk.integration.model.websocket.AppWebSocketClient.java
License:Apache License
private static WebSocketFrame produceWebSocketFrame(MessageBase msg) { byte[] data = msg.getBytes(); ByteBuf bb = ByteBufAllocator.DEFAULT.buffer(3 + data.length); bb.writeByte(msg.command);/* www . j a v a2s . c o m*/ bb.writeShort(msg.id); bb.writeBytes(data); return new BinaryWebSocketFrame(bb); }
From source file:cc.blynk.integration.model.websocket.WebSocketClient.java
License:Apache License
private static WebSocketFrame produceWebSocketFrame(MessageBase msg) { ByteBuf bb = PooledByteBufAllocator.DEFAULT.heapBuffer(5 + msg.length); bb.writeByte(msg.command);//w ww . j a v a 2 s. c o m bb.writeShort(msg.id); bb.writeShort(msg.length); byte[] data = msg.getBytes(); if (data != null) { bb.writeBytes(data); } return new BinaryWebSocketFrame(bb); }