net.minecraftforge.fml.common.network.ByteBufUtils Java Examples
The following examples show how to use
net.minecraftforge.fml.common.network.ByteBufUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageSendServerTab.java From IGW-mod with GNU General Public License v2.0 | 6 votes |
@Override public void toBytes(ByteBuf buf){ File[] files = serverFolder.listFiles(); buf.writeInt(files.length); for(File file : files) { try { ByteBufUtils.writeUTF8String(buf, file.getName()); FileInputStream stream = new FileInputStream(file); byte[] byteArray = IOUtils.toByteArray(stream); buf.writeInt(byteArray.length); buf.writeBytes(byteArray); stream.close(); } catch(Exception e) { e.printStackTrace(); } } }
Example #2
Source File: InventoryCommandsImplementation.java From malmo with MIT License | 6 votes |
@Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, this.invA); buf.writeInt(this.slotA); ByteBufUtils.writeUTF8String(buf, this.invB); buf.writeInt(this.slotB); buf.writeBoolean(this.combine); buf.writeBoolean(this.containerPos != null); if (this.containerPos != null) { buf.writeInt(this.containerPos.getX()); buf.writeInt(this.containerPos.getY()); buf.writeInt(this.containerPos.getZ()); } }
Example #3
Source File: PacketUpdateGui.java From Signals with GNU General Public License v3.0 | 6 votes |
public static Object readField(ByteBuf buf, int type){ switch(type){ case 0: return buf.readInt(); case 1: return buf.readFloat(); case 2: return buf.readDouble(); case 3: return buf.readBoolean(); case 4: return ByteBufUtils.readUTF8String(buf); case 5: return buf.readByte(); case 6: return ByteBufUtils.readItemStack(buf); case 7: if(!buf.readBoolean()) return null; return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf)); default: throw new IllegalArgumentException("Invalid sync type! " + type); } }
Example #4
Source File: ObservationFromGridImplementation.java From malmo with MIT License | 6 votes |
@Override void persistState(ByteBuf buf) { buf.writeInt(this.environs.size()); for (SimpleGridDef sgd : this.environs) { buf.writeInt(sgd.xMin); buf.writeInt(sgd.yMin); buf.writeInt(sgd.zMin); buf.writeInt(sgd.xMax); buf.writeInt(sgd.yMax); buf.writeInt(sgd.zMax); ByteBufUtils.writeUTF8String(buf, sgd.name); buf.writeBoolean(sgd.absoluteCoords); } }
Example #5
Source File: MessageSendServerTab.java From IGW-mod with GNU General Public License v2.0 | 6 votes |
@Override public void fromBytes(ByteBuf buf){ File folder = new File(IGWMod.proxy.getSaveLocation() + File.separator + "igwmod" + File.separator); folder.mkdirs(); try { FileUtils.deleteDirectory(folder);//clear the folder } catch(IOException e1) { e1.printStackTrace(); } folder.mkdirs(); int fileAmount = buf.readInt(); for(int i = 0; i < fileAmount; i++) { try { File file = new File(folder.getAbsolutePath() + File.separator + ByteBufUtils.readUTF8String(buf)); byte[] fileBytes = new byte[buf.readInt()]; buf.readBytes(fileBytes); FileOutputStream stream = new FileOutputStream(file); IOUtils.write(fileBytes, stream); stream.close(); } catch(Exception e) { e.printStackTrace(); } } }
Example #6
Source File: PacketSyncContainerFluid.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buf) { buf.writeByte(windowId); buf.writeByte(tank); NBTTagCompound fluidNbt = fluid == null ? null : fluid.writeToNBT(new NBTTagCompound()); ByteBufUtils.writeTag(buf, fluidNbt); }
Example #7
Source File: PlainInventory.java From HoloInventory with MIT License | 5 votes |
@Override public void fromBytes(ByteBuf buf) { super.fromBytes(buf); name = ByteBufUtils.readUTF8String(buf); int size = buf.readInt(); stacks = new ArrayList<>(size); for (int i = 0; i < size; i++) add(ByteBufUtils.readItemStack(buf)); }
Example #8
Source File: MessagePlayerCivilizationSetInCiv.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buf) { if (province == null) { ByteBufUtils.writeTag(buf, new NBTTagCompound()); } else { ByteBufUtils.writeTag(buf, province.writeNBT()); } }
Example #9
Source File: PacketUpdateGui.java From Signals with GNU General Public License v3.0 | 5 votes |
public static void writeField(ByteBuf buf, Object value, int type){ switch(type){ case 0: buf.writeInt((Integer)value); break; case 1: buf.writeFloat((Float)value); break; case 2: buf.writeDouble((Double)value); break; case 3: buf.writeBoolean((Boolean)value); break; case 4: ByteBufUtils.writeUTF8String(buf, (String)value); break; case 5: buf.writeByte((Byte)value); break; case 6: ByteBufUtils.writeItemStack(buf, (ItemStack)value); break; case 7: buf.writeBoolean(value != null); if(value != null) { FluidStack stack = (FluidStack)value; ByteBufUtils.writeUTF8String(buf, stack.getFluid().getName()); buf.writeInt(stack.amount); ByteBufUtils.writeTag(buf, stack.tag); } break; } }
Example #10
Source File: PacketDescription.java From Signals with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buf){ super.toBytes(buf); buf.writeByte(type.ordinal()); buf.writeInt(values.length); for(int i = 0; i < types.length; i++) { buf.writeByte(types[i]); PacketUpdateGui.writeField(buf, values[i], types[i]); } ByteBufUtils.writeTag(buf, extraData); }
Example #11
Source File: RewardForItemBase.java From malmo with MIT License | 5 votes |
protected static void sendItemStackToClient(EntityPlayerMP player, MalmoMessageType message, ItemStack is) { ByteBuf buf = Unpooled.buffer(); ByteBufUtils.writeItemStack(buf, is); byte[] bytes = new byte[buf.readableBytes()]; buf.getBytes(0, bytes); String data = DatatypeConverter.printBase64Binary(bytes); MalmoMod.MalmoMessage msg = new MalmoMod.MalmoMessage(message, data); MalmoMod.network.sendTo(msg, player); }
Example #12
Source File: PacketUpdateMessage.java From Signals with GNU General Public License v3.0 | 5 votes |
@Override public void fromBytes(ByteBuf buf){ super.fromBytes(buf); entityId = buf.readInt(); message = ByteBufUtils.readUTF8String(buf); args = new String[buf.readInt()]; for(int i = 0; i < args.length; i++) { args[i] = ByteBufUtils.readUTF8String(buf); } }
Example #13
Source File: PacketUpdateMessage.java From Signals with GNU General Public License v3.0 | 5 votes |
@Override public void toBytes(ByteBuf buf){ super.toBytes(buf); buf.writeInt(entityId); ByteBufUtils.writeUTF8String(buf, message); buf.writeInt(args.length); for(String arg : args) ByteBufUtils.writeUTF8String(buf, arg); }
Example #14
Source File: PlainInventory.java From HoloInventory with MIT License | 5 votes |
@Override public void toBytes(ByteBuf buf) { super.toBytes(buf); ByteBufUtils.writeUTF8String(buf, Strings.nullToEmpty(name)); buf.writeInt(stacks.size()); for (ItemStack stack : stacks) ByteBufUtils.writeItemStack(buf, stack); }
Example #15
Source File: RewardForCollectingItemImplementation.java From malmo with MIT License | 5 votes |
@Override public void onMessage(MalmoMessageType messageType, Map<String, String> data) { String bufstring = data.get("message"); ByteBuf buf = Unpooled.copiedBuffer(DatatypeConverter.parseBase64Binary(bufstring)); ItemStack itemStack = ByteBufUtils.readItemStack(buf); if (itemStack != null && itemStack.getItem() != null) { accumulateReward(this.params.getDimension(), itemStack); } else { System.out.println("Error - couldn't understand the itemstack we received."); } }
Example #16
Source File: DiscreteMovementCommandsImplementation.java From malmo with MIT License | 5 votes |
@Override public void fromBytes(ByteBuf buf) { this.pos = new BlockPos( buf.readInt(), buf.readInt(), buf.readInt() ); this.itemStack = ByteBufUtils.readItemStack(buf); this.face = EnumFacing.values()[buf.readInt()]; this.standOnPlacedBlock = buf.readBoolean(); this.hitVec = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble()); }
Example #17
Source File: DiscreteMovementCommandsImplementation.java From malmo with MIT License | 5 votes |
@Override public void toBytes(ByteBuf buf) { buf.writeInt(this.pos.getX()); buf.writeInt(this.pos.getY()); buf.writeInt(this.pos.getZ()); ByteBufUtils.writeItemStack(buf, this.itemStack); buf.writeInt(this.face.ordinal()); buf.writeBoolean(this.standOnPlacedBlock); buf.writeDouble(this.hitVec.xCoord); buf.writeDouble(this.hitVec.yCoord); buf.writeDouble(this.hitVec.zCoord); }
Example #18
Source File: InventoryCommandsImplementation.java From malmo with MIT License | 5 votes |
@Override public void fromBytes(ByteBuf buf) { boolean gainedItems = buf.readBoolean(); if (gainedItems) this.itemsGained = ByteBufUtils.readItemStack(buf); boolean lostItems = buf.readBoolean(); if (lostItems) this.itemsLost = ByteBufUtils.readItemStack(buf); }
Example #19
Source File: InventoryCommandsImplementation.java From malmo with MIT License | 5 votes |
@Override public void toBytes(ByteBuf buf) { buf.writeBoolean(this.itemsGained != null); if (this.itemsGained != null) ByteBufUtils.writeItemStack(buf, this.itemsGained); buf.writeBoolean(this.itemsLost != null); if (this.itemsLost != null) ByteBufUtils.writeItemStack(buf, this.itemsLost); }
Example #20
Source File: InventoryCommandsImplementation.java From malmo with MIT License | 5 votes |
@Override public void fromBytes(ByteBuf buf) { this.invA = ByteBufUtils.readUTF8String(buf); this.slotA = buf.readInt(); this.invB = ByteBufUtils.readUTF8String(buf); this.slotB = buf.readInt(); this.combine = buf.readBoolean(); if (buf.readBoolean()) this.containerPos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt()); }
Example #21
Source File: MessageFluidUpdate.java From ExNihiloAdscensio with MIT License | 5 votes |
@Override public void toBytes(ByteBuf buf) { buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); buf.writeInt(fillAmount); ByteBufUtils.writeUTF8String(buf, fluidName); }
Example #22
Source File: MessageFluidUpdate.java From ExNihiloAdscensio with MIT License | 5 votes |
@Override public void fromBytes(ByteBuf buf) { this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); this.fillAmount = buf.readInt(); this.fluidName = ByteBufUtils.readUTF8String(buf); }
Example #23
Source File: MessageBarrelModeUpdate.java From ExNihiloAdscensio with MIT License | 5 votes |
@Override public void toBytes(ByteBuf buf) { buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); ByteBufUtils.writeUTF8String(buf, modeName); }
Example #24
Source File: MessageBarrelModeUpdate.java From ExNihiloAdscensio with MIT License | 5 votes |
@Override public void fromBytes(ByteBuf buf) { this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); this.modeName = ByteBufUtils.readUTF8String(buf); }
Example #25
Source File: MessageNBTUpdate.java From ExNihiloAdscensio with MIT License | 5 votes |
@Override public void toBytes(ByteBuf buf) { buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); ByteBufUtils.writeTag(buf, tag); }
Example #26
Source File: MessageNBTUpdate.java From ExNihiloAdscensio with MIT License | 5 votes |
@Override public void fromBytes(ByteBuf buf) { this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); this.tag = ByteBufUtils.readTag(buf); }
Example #27
Source File: PacketDescription.java From Signals with GNU General Public License v3.0 | 5 votes |
@Override public void fromBytes(ByteBuf buf){ super.fromBytes(buf); type = IDescSynced.Type.values()[buf.readByte()]; int dataAmount = buf.readInt(); types = new byte[dataAmount]; values = new Object[dataAmount]; for(int i = 0; i < dataAmount; i++) { types[i] = buf.readByte(); values[i] = PacketUpdateGui.readField(buf, types[i]); } extraData = ByteBufUtils.readTag(buf); }
Example #28
Source File: MCNetworkRail.java From Signals with GNU General Public License v3.0 | 5 votes |
public static MCNetworkRail fromByteBuf(ByteBuf b){ MCPos pos = new MCPos(b); EnumRailDirection curDir = ALL_RAIL_DIRECTIONS_ARRAY[b.readByte()]; String type = ByteBufUtils.readUTF8String(b); if(type.equals(NORMAL_RAIL_STRING)) { return new MCNetworkRail(pos, (String)null, curDir, ALL_RAIL_DIRECTIONS); } else { EnumSet<EnumRailDirection> validRailDirs = EnumSetUtils.toEnumSet(EnumRailDirection.class, ALL_RAIL_DIRECTIONS_ARRAY, b.readShort()); return new MCNetworkRail(pos, type, curDir, validRailDirs); } }
Example #29
Source File: MCNetworkRail.java From Signals with GNU General Public License v3.0 | 5 votes |
public static <T> T fromByteBuf(ByteBuf b, IRailCreator<T> factory){ MCPos pos = new MCPos(b); EnumRailDirection curDir = ALL_RAIL_DIRECTIONS_ARRAY[b.readByte()]; String type = ByteBufUtils.readUTF8String(b); if(type.equals(NORMAL_RAIL_STRING)) { return factory.create(pos, (String)null, curDir, ALL_RAIL_DIRECTIONS); } else { EnumSet<EnumRailDirection> validRailDirs = EnumSetUtils.toEnumSet(EnumRailDirection.class, ALL_RAIL_DIRECTIONS_ARRAY, b.readShort()); return factory.create(pos, type, curDir, validRailDirs); } }
Example #30
Source File: MCNetworkRail.java From Signals with GNU General Public License v3.0 | 5 votes |
@Override public void writeToBuf(ByteBuf b){ getPos().writeToBuf(b); b.writeByte(curDir.ordinal()); ByteBufUtils.writeUTF8String(b, railType == null ? NORMAL_RAIL_STRING : railType); if(railType != null) { b.writeShort(EnumSetUtils.toShort(validRailDirs)); } }