List of usage examples for io.netty.buffer ByteBuf writeByte
public abstract ByteBuf writeByte(int value);
From source file:appeng.facade.FacadeContainer.java
License:Open Source License
@Override public void writeToStream(final ByteBuf out) throws IOException { int facadeSides = 0; for (int x = 0; x < this.facades; x++) { if (this.getFacade(AEPartLocation.fromOrdinal(x)) != null) { facadeSides |= (1 << x); }// w ww . ja v a2s. co m } out.writeByte((byte) facadeSides); for (int x = 0; x < this.facades; x++) { final IFacadePart part = this.getFacade(AEPartLocation.fromOrdinal(x)); if (part != null) { final int itemID = Item.getIdFromItem(part.getItem()); final int dmgValue = part.getItemDamage(); out.writeInt(itemID * (part.notAEFacade() ? -1 : 1)); out.writeInt(dmgValue); } } }
From source file:appeng.helpers.Splotch.java
License:Open Source License
public void writeToStream(final ByteBuf stream) { stream.writeByte(this.pos); final int val = this.getSide().ordinal() | (this.getColor().ordinal() << 3) | (this.isLumen() ? 0x80 : 0x00); stream.writeByte(val); }
From source file:appeng.parts.CableBusContainer.java
License:Open Source License
public void writeToStream(final ByteBuf data) throws IOException { int sides = 0; for (int x = 0; x < 7; x++) { final IPart p = this.getPart(AEPartLocation.fromOrdinal(x)); if (p != null) { sides |= (1 << x);//from w w w .j av a2 s .c om } } data.writeByte((byte) sides); for (int x = 0; x < 7; x++) { final IPart p = this.getPart(AEPartLocation.fromOrdinal(x)); if (p != null) { final ItemStack is = p.getItemStack(PartItemStack.NETWORK); data.writeShort(Item.getIdFromItem(is.getItem())); data.writeShort(is.getItemDamage()); p.writeToStream(data); } } this.getFacadeContainer().writeToStream(data); }
From source file:appeng.parts.networking.PartCable.java
License:Open Source License
@Override public void writeToStream(final ByteBuf data) throws IOException { int flags = 0; boolean[] writeSide = new boolean[EnumFacing.values().length]; int[] channelsPerSide = new int[EnumFacing.values().length]; for (EnumFacing thisSide : EnumFacing.values()) { final IPart part = this.getHost().getPart(thisSide); if (part != null) { writeSide[thisSide.ordinal()] = true; int channels = 0; if (part.getGridNode() != null) { final IReadOnlyCollection<IGridConnection> set = part.getGridNode().getConnections(); for (final IGridConnection gc : set) { channels = Math.max(channels, gc.getUsedChannels()); }/*from ww w . java 2 s.c o m*/ } channelsPerSide[thisSide.ordinal()] = channels; } } IGridNode n = this.getGridNode(); if (n != null) { for (final IGridConnection gc : n.getConnections()) { final AEPartLocation side = gc.getDirection(n); if (side != AEPartLocation.INTERNAL) { writeSide[side.ordinal()] = true; channelsPerSide[side.ordinal()] = gc.getUsedChannels(); flags |= (1 << side.ordinal()); } } } try { if (this.getProxy().getEnergy().isNetworkPowered()) { flags |= (1 << AEPartLocation.INTERNAL.ordinal()); } } catch (final GridAccessException e) { // aww... } data.writeByte((byte) flags); // Only write the used channels for sides where we have a part or another cable for (int i = 0; i < writeSide.length; i++) { if (writeSide[i]) { data.writeByte(channelsPerSide[i]); } } }
From source file:appeng.parts.PartBasicState.java
License:Open Source License
@Override public void writeToStream(final ByteBuf data) throws IOException { super.writeToStream(data); this.setClientFlags(0); try {//from ww w. ja v a2 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); } this.setClientFlags(this.populateFlags(this.getClientFlags())); } catch (final GridAccessException e) { // meh } data.writeByte((byte) this.getClientFlags()); }
From source file:appeng.parts.reporting.AbstractPartReporting.java
License:Open Source License
@Override public void writeToStream(final ByteBuf data) throws IOException { super.writeToStream(data); this.clientFlags = this.getSpin() & 3; try {/* ww w . j a v a2s .c o m*/ if (this.getProxy().getEnergy().isNetworkPowered()) { this.clientFlags = this.getClientFlags() | AbstractPartReporting.POWERED_FLAG; } if (this.getProxy().getPath().isNetworkBooting()) { this.clientFlags = this.getClientFlags() | AbstractPartReporting.BOOTING_FLAG; } if (this.getProxy().getNode().meetsChannelRequirements()) { this.clientFlags = this.getClientFlags() | AbstractPartReporting.CHANNEL_FLAG; } } catch (final GridAccessException e) { // um.. nothing. } data.writeByte((byte) this.getClientFlags()); }
From source file:appeng.parts.reporting.PartMonitor.java
License:Open Source License
@Override public void writeToStream(ByteBuf data) throws IOException { super.writeToStream(data); this.clientFlags = this.spin & 3; try {/*from ww w .java 2 s. c om*/ if (this.proxy.getEnergy().isNetworkPowered()) { this.clientFlags |= this.POWERED_FLAG; } if (this.proxy.getPath().isNetworkBooting()) { this.clientFlags |= this.BOOTING_FLAG; } if (this.proxy.getNode().meetsChannelRequirements()) { this.clientFlags |= this.CHANNEL_FLAG; } } catch (GridAccessException e) { // um.. nothing. } data.writeByte((byte) this.clientFlags); }
From source file:appeng.parts.reporting.PartStorageMonitor.java
License:Open Source License
@Override public void writeToStream(ByteBuf data) throws IOException { super.writeToStream(data); data.writeByte(this.spin); data.writeBoolean(this.isLocked); data.writeBoolean(this.configuredItem != null); if (this.configuredItem != null) { this.configuredItem.writeToPacket(data); }/*from ww w . j av a2 s . c o m*/ }
From source file:appeng.tile.AEBaseTile.java
License:Open Source License
private final void writeToStream(final ByteBuf data) { try {/*ww w . j a va 2 s. com*/ if (this.canBeRotated()) { final byte orientation = (byte) ((this.up.ordinal() << 3) | this.forward.ordinal()); data.writeByte(orientation); } for (final AETileEventHandler h : this.getHandlerListFor(TileEventType.NETWORK_WRITE)) { h.writeToStream(this, data); } } catch (final Throwable t) { AELog.debug(t); } }
From source file:appeng.tile.crafting.TileCraftingMonitorTile.java
License:Open Source License
@TileEvent(TileEventType.NETWORK_WRITE) public void writeToStream_TileCraftingMonitorTile(final ByteBuf data) throws IOException { data.writeByte(this.paintedColor.ordinal()); if (this.dspPlay == null) { data.writeBoolean(false);/*from w w w.ja va 2 s.c om*/ } else { data.writeBoolean(true); this.dspPlay.writeToPacket(data); } }