List of usage examples for io.netty.buffer ByteBuf readShort
public abstract short readShort();
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;//ww w.jav a2s .c om 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 readData(ByteBuf stream) { laser = new LaserData(); laser.readData(stream);//from w w w.j a v a2 s . c o m powerAverage = stream.readShort(); }
From source file:buildcraft.transport.network.PacketFluidUpdate.java
License:Minecraft Mod Public
@Override public void readData(ByteBuf data) { super.readData(data); World world = CoreProxy.proxy.getClientWorld(); if (!world.blockExists(posX, posY, posZ)) { return;//from w ww. j a v a2 s. co m } TileEntity entity = world.getTileEntity(posX, posY, posZ); if (!(entity instanceof TileGenericPipe)) { return; } TileGenericPipe pipe = (TileGenericPipe) entity; if (pipe.pipe == null) { return; } if (!(pipe.pipe.transport instanceof PipeTransportFluids)) { return; } PipeTransportFluids transLiq = (PipeTransportFluids) pipe.pipe.transport; renderCache = transLiq.renderCache; colorRenderCache = transLiq.colorRenderCache; byte[] dBytes = new byte[2]; data.readBytes(dBytes); delta = fromByteArray(dBytes); // System.out.printf("read %d, %d, %d = %s, %s%n", posX, posY, posZ, Arrays.toString(dBytes), delta); for (ForgeDirection dir : ForgeDirection.values()) { if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_ID_BIT)) { int amt = renderCache[dir.ordinal()] != null ? renderCache[dir.ordinal()].amount : 0; renderCache[dir.ordinal()] = new FluidStack(data.readShort(), amt); colorRenderCache[dir.ordinal()] = data.readInt(); } if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_AMOUNT_BIT)) { if (renderCache[dir.ordinal()] == null) { renderCache[dir.ordinal()] = new FluidStack(0, 0); } renderCache[dir.ordinal()].amount = Math.min(transLiq.getCapacity(), data.readInt()); } } }
From source file:buildcraft.transport.network.PacketPipeTransportItemStackRequest.java
License:Minecraft Mod Public
@Override public void readData(ByteBuf data) { travelerID = data.readShort(); TravelingItem.TravelingItemCache cache = TravelingItem.serverCache; item = cache.get(travelerID);/* w w w . jav a2s. co m*/ }
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); }// ww w .j a v a 2s . c o m this.speed = data.readFloat(); this.forceStackRefresh = data.readBoolean(); }
From source file:buildcraft.transport.utils.FacadeMatrix.java
License:Minecraft Mod Public
public void readData(ByteBuf data) { for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { short id = data.readShort(); Block block;/*from www. j a v a 2 s . co m*/ if (id == 0) { block = null; } else { block = (Block) Block.blockRegistry.getObjectById(id); } if (blocks[i] != block) { blocks[i] = block; dirty = true; } byte meta = data.readByte(); if (blockMetas[i] != meta) { blockMetas[i] = meta; dirty = true; } } }
From source file:cn.academy.core.block.dev.MsgDeveloper.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { x = buf.readInt();/*ww w . j a v a2s. c om*/ y = buf.readShort(); z = buf.readInt(); energy = buf.readInt(); isStimulating = buf.readBoolean(); stimSuccess = buf.readByte(); stimFailure = buf.readByte(); nMagIncr = buf.readByte(); userID = buf.readInt(); }
From source file:cn.academy.energy.msg.node.MsgNodeLoadList.java
License:Open Source License
@Override public void fromBytes(ByteBuf buf) { cns = new ArrayList(); int n = buf.readShort(); while (n-- > 0) { cns.add(ByteBufUtils.readUTF8String(buf)); }// w ww .j a va 2 s.c om }
From source file:cn.lambdalib.s11n.network.NetworkS11n.java
License:MIT License
private static Class readTypeIndex(ByteBuf buf) { short idx = buf.readShort(); if (idx == IDX_NULL) { return null; } else if (idx == IDX_ARRAY) { return getArrayClass(readTypeIndex(buf)); } else {/* w w w .j av a 2s .c om*/ return serTypes.get(idx); } }
From source file:cn.lambdalib.s11n.network.NetworkS11n.java
License:MIT License
/** * Deserialize an object with given type hint. * @return The deserialized object of type T. * @throws ContextException if deserialization is interrupted. That is, the object can't be restored out of * contextual difference (e.g. Some entity exists on server, but not created in one client). * @throws RuntimeException if deserialization failed non-trivially. *//*from ww w . j a v a2 s .co m*/ public static <T, U extends T> T deserializeWithHint(ByteBuf buf, Class<U> type) { NetS11nAdaptor<? super U> adaptor = (NetS11nAdaptor) _adaptor(type); // System.out.println("adaptor " + type + " is " + adaptor); if (adaptor != null) { // Note that if adaptor's real type doesn't extend T there will be a cast exception. // With type erasure we can't do much about it. return (T) adaptor.read(buf); } else if (type.isArray()) { // Deserialize array int size = buf.readShort(); Class componentType = type.getComponentType(); Object ret = Array.newInstance(componentType, size); for (int i = 0; i < size; ++i) { Array.set(ret, i, deserialize(buf)); } return (T) ret; } else if (type.isEnum()) { // Deserialize enum return type.getEnumConstants()[buf.readByte()]; } else { // Recursive deserialization return deserializeRecursively(buf, type); } }