List of usage examples for io.netty.buffer ByteBuf writeBytes
public abstract ByteBuf writeBytes(ByteBuffer src);
From source file:buildcraft.core.lib.network.PacketNBT.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { super.writeData(data); try {// w w w . j av a 2 s.com byte[] compressed = CompressedStreamTools.compress(nbttagcompound); if (compressed.length > 65535) { BCLog.logger.error("NBT data is too large (" + compressed.length + " > 65535)! Please report!"); } data.writeShort(compressed.length); data.writeBytes(compressed); } catch (IOException e) { e.printStackTrace(); } }
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 .jav a 2 s. co m*/ data.writeShort((short) tmpState.readableBytes()); data.writeBytes(tmpState.readBytes(tmpState.readableBytes())); }
From source file:buildcraft.core.network.PacketNBT.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { super.writeData(data); try {//from w ww . j av a2 s .c o m byte[] compressed = CompressedStreamTools.compress(nbttagcompound); data.writeShort(compressed.length); data.writeBytes(compressed); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:buildcraft.core.network.PacketRPC.java
License:Minecraft Mod Public
public void call(EntityPlayer sender) { if (bufferedPackets.containsKey(id)) { ByteBuf data = bufferedPackets.remove(id); if (data != null) { contents = data.writeBytes(contents); }/* w w w . j a va2 s . c o m*/ } }
From source file:buildcraft.core.network.PacketRPC.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { data.writeInt(id); data.writeInt(contents.readableBytes()); data.writeBytes(contents); }
From source file:buildcraft.core.network.PacketRPCPipe.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { data.writeBytes(contents); }
From source file:buildcraft.core.network.PacketRPCTile.java
License:Minecraft Mod Public
public void call(EntityPlayer sender) { World world = null;//from w ww.j a va 2 s . co m if (!sender.worldObj.isRemote) { // if this is a server, then get the world world = DimensionManager.getProvider(dimId).worldObj; } else if (sender.worldObj.provider.dimensionId == dimId) { // if the player is on this world, then synchronize things world = sender.worldObj; } TileEntity localTile = world.getTileEntity(x, y, z); setTile(localTile); RPCMessageInfo info = new RPCMessageInfo(); info.sender = sender; ByteBuf previousData = bufferedPackets.get(id); bufferedPackets.remove(id); ByteBuf completeData; if (previousData != null) { completeData = previousData.writeBytes(contents); } else { completeData = Unpooled.buffer(); completeData.writeBytes(contents); } if (!moreDataToCome) { RPCHandler.receiveRPC(localTile, info, completeData); } else { bufferedPackets.put(id, completeData); } }
From source file:buildcraft.core.network.PacketRPCTile.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { // In order to save space on message, we assuming dimensions ids // small. Maybe worth using a varint instead data.writeShort(tile.getWorldObj().provider.dimensionId); data.writeInt(tile.xCoord);//from w w w. ja v a 2 s .c o m data.writeInt(tile.yCoord); data.writeInt(tile.zCoord); data.writeInt(id); data.writeBoolean(moreDataToCome); data.writeBytes(contents); }
From source file:buildcraft.core.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); }//www .j av a2 s. c om data.writeInt(tmpState.readableBytes()); data.writeBytes(tmpState.readBytes(tmpState.readableBytes())); }
From source file:buildcraft.core.network.serializers.ClassMapping.java
License:Minecraft Mod Public
private void writeArray(Object obj, ByteBuf data, SerializationContext context) throws IllegalArgumentException, IllegalAccessException { Class<? extends Object> cpt = mappedClass.getComponentType(); switch (cptType) { case Byte: { byte[] arr = (byte[]) obj; data.writeInt(arr.length);/*from w w w . ja v a 2s .c o m*/ data.writeBytes(arr); break; } case Float: { float[] arr = (float[]) obj; data.writeInt(arr.length); for (float element : arr) { data.writeFloat(element); } break; } case Double: { double[] arr = (double[]) obj; data.writeInt(arr.length); for (double element : arr) { data.writeDouble(element); } break; } case Short: { short[] arr = (short[]) obj; data.writeInt(arr.length); for (short element : arr) { data.writeShort(element); } break; } case Int: { int[] arr = (int[]) obj; data.writeInt(arr.length); for (int element : arr) { data.writeInt(element); } break; } case Boolean: { boolean[] arr = (boolean[]) obj; data.writeInt(arr.length); for (boolean element : arr) { data.writeBoolean(element); } break; } case Object: { Object[] arr = (Object[]) obj; data.writeInt(arr.length); for (Object element : arr) { cptMapping.write(data, element, context); } break; } } }