public static NBTReader createBigEndianReader(InputStream stream) { Objects.requireNonNull(stream, "stream"); return new NBTReader(new DataInputStream(stream)); } }
public Tag<?> readTag() throws IOException { return readTag(0); }
private Tag<?> readTag(int depth) throws IOException { if (closed) { throw new IllegalStateException("Trying to read from a closed reader!"); } int typeId = input.readByte() & 0xFF; TagType type = TagType.fromId(typeId); if (type == null) { throw new IOException("Invalid encoding ID " + typeId); } return deserialize(type, false, depth); }
public static ItemStack readItemStack(ByteBuf buf) { int id = Varints.decodeSigned(buf); if (id == 0) { return new VoxelwindItemStack(BlockTypes.AIR, 1, null); } int aux = Varints.decodeSigned(buf); int damage = aux >> 8; int count = aux & 0xff; short nbtSize = buf.readShortLE(); ItemType type = ItemTypes.forId(id); ItemStackBuilder builder = new VoxelwindItemStackBuilder() .itemType(type) .itemData(MetadataSerializer.deserializeMetadata(type, (short) damage)) .amount(count); if (nbtSize > 0) { try (NBTReader reader = new NBTReader(new LittleEndianByteBufInputStream(buf.readSlice(nbtSize)))) { Tag<?> tag = reader.readTag(); if (tag instanceof CompoundTag) { VoxelwindNBTUtils.applyItemData(builder, ((CompoundTag) tag).getValue()); } } catch (IOException e) { throw new IllegalStateException("Unable to load NBT data", e); } } return builder.build(); }
Map<String, Tag<?>> map = new HashMap<>(); Tag<?> inTag1; while ((inTag1 = readTag(depth + 1)) != EndTag.INSTANCE) { map.put(inTag1.getName(), inTag1); int listLength = encoding == MCPE_0_16_NETWORK ? Varints.decodeSigned(input) : input.readInt(); for (int i = 0; i < listLength; i++) { list.add(deserialize(listType, true, depth + 1));
public static AnvilLevelDataProvider load(@NonNull Path levelDatPath) throws IOException { // level.dat is Notchian, so it's big-endian and GZIP compressed CompoundTag tag; try (NBTReader reader = NBTReaders.createBigEndianReader(new GZIPInputStream(Files.newInputStream(levelDatPath)))) { tag = (CompoundTag) reader.readTag(); } CompoundTag dataTag = (CompoundTag) tag.getValue().get("Data"); Map<String, Tag<?>> map = dataTag.getValue(); Vector3i out = new Vector3i(((IntTag) map.get("SpawnX")).getPrimitiveValue(), ((IntTag) map.get("SpawnY")).getPrimitiveValue(), ((IntTag) map.get("SpawnZ")).getPrimitiveValue()); long dayTime = ((LongTag) map.get("DayTime")).getPrimitiveValue(); long seed = ((LongTag) map.get("RandomSeed")).getPrimitiveValue(); return new AnvilLevelDataProvider(out.toFloat(), (int) dayTime, seed); }
public static NBTReader createLittleEndianReader(InputStream stream) { Objects.requireNonNull(stream, "stream"); return new NBTReader(new SwappedDataInputStream(stream)); }
Tag<?> tag; try (NBTReader stream = NBTReaders.createBigEndianReader(regionReader.readChunk(irXZ.x, irXZ.z))) { tag = stream.readTag();