From 3ef191226773ed6dc05eb173f60011f268c19fa6 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Thu, 9 Jul 2020 14:31:19 +0200 Subject: [PATCH] Map biomes, fix registry sending --- .../api/data/MappingDataLoader.java | 5 - .../api/minecraft/nbt/BinaryTagIO.java | 144 ++++++++++++++++++ .../Protocol1_16_2To1_16_1.java | 4 +- .../data/BiomeMappings.java | 48 ++++++ .../data/MappingData.java | 5 +- .../packets/WorldPackets.java | 11 +- 6 files changed, 207 insertions(+), 10 deletions(-) create mode 100644 common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16_2to1_16_1/data/BiomeMappings.java diff --git a/common/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java b/common/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java index 6caae609a..0433ddb75 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java +++ b/common/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java @@ -14,7 +14,6 @@ import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.net.URL; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -209,8 +208,4 @@ public class MappingDataLoader { public static InputStream getResource(String name) { return MappingDataLoader.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name); } - - public static URL getResourceUrl(String name) { - return MappingDataLoader.class.getClassLoader().getResource("assets/viaversion/data/" + name); - } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/nbt/BinaryTagIO.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/nbt/BinaryTagIO.java index 7c7a4aba5..19bba5e7f 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/nbt/BinaryTagIO.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/nbt/BinaryTagIO.java @@ -23,10 +23,21 @@ */ package us.myles.ViaVersion.api.minecraft.nbt; +import com.github.steveice10.opennbt.tag.TagRegistry; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import org.jetbrains.annotations.NotNull; +import java.io.DataInput; +import java.io.DataInputStream; +import java.io.DataOutput; +import java.io.DataOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; /** * See https://github.com/KyoriPowered/adventure. @@ -35,6 +46,139 @@ public final class BinaryTagIO { private BinaryTagIO() { } + /** + * Reads a compound tag from {@code path}. + * + * @param path the path + * @return the compound tag + * @throws IOException if an exception was encountered while reading a compound tag + */ + @NotNull + public static CompoundTag readPath(final @NotNull Path path) throws IOException { + return readInputStream(Files.newInputStream(path)); + } + + /** + * Reads a compound tag from an input stream. + * + * @param input the input stream + * @return the compound tag + * @throws IOException if an exception was encountered while reading a compound tag + */ + @NotNull + public static CompoundTag readInputStream(final @NotNull InputStream input) throws IOException { + try (final DataInputStream dis = new DataInputStream(input)) { + return readDataInput(dis); + } + } + + /** + * Reads a compound tag from {@code path} using GZIP decompression. + * + * @param path the path + * @return the compound tag + * @throws IOException if an exception was encountered while reading a compound tag + */ + @NotNull + public static CompoundTag readCompressedPath(final @NotNull Path path) throws IOException { + return readCompressedInputStream(Files.newInputStream(path)); + } + + /** + * Reads a compound tag from an input stream using GZIP decompression. + * + * @param input the input stream + * @return the compound tag + * @throws IOException if an exception was encountered while reading a compound tag + */ + @NotNull + public static CompoundTag readCompressedInputStream(final @NotNull InputStream input) throws IOException { + try (final DataInputStream dis = new DataInputStream(new GZIPInputStream(input))) { + return readDataInput(dis); + } + } + + /** + * Reads a compound tag from {@code input}. + * + * @param input the input + * @return the compound tag + * @throws IOException if an exception was encountered while reading a compound tag + */ + @NotNull + public static CompoundTag readDataInput(final @NotNull DataInput input) throws IOException { + byte type = input.readByte(); + if (type != TagRegistry.getIdFor(CompoundTag.class)) { + throw new IOException(String.format("Expected root tag to be a CompoundTag, was %s", type)); + } + input.skipBytes(input.readUnsignedShort()); // read empty name + + final CompoundTag compoundTag = new CompoundTag(""); + compoundTag.read(input); + return compoundTag; + } + + /** + * Writes a compound tag to {@code path}. + * + * @param tag the compound tag + * @param path the path + * @throws IOException if an exception was encountered while writing the compound tag + */ + public static void writePath(final @NotNull CompoundTag tag, final @NotNull Path path) throws IOException { + writeOutputStream(tag, Files.newOutputStream(path)); + } + + /** + * Writes a compound tag to an output stream. + * + * @param tag the compound tag + * @param output the output stream + * @throws IOException if an exception was encountered while writing the compound tag + */ + public static void writeOutputStream(final @NotNull CompoundTag tag, final @NotNull OutputStream output) throws IOException { + try (final DataOutputStream dos = new DataOutputStream(output)) { + writeDataOutput(tag, dos); + } + } + + /** + * Writes a compound tag to {@code path} using GZIP compression. + * + * @param tag the compound tag + * @param path the path + * @throws IOException if an exception was encountered while writing the compound tag + */ + public static void writeCompressedPath(final @NotNull CompoundTag tag, final @NotNull Path path) throws IOException { + writeCompressedOutputStream(tag, Files.newOutputStream(path)); + } + + /** + * Writes a compound tag to an output stream using GZIP compression. + * + * @param tag the compound tag + * @param output the output stream + * @throws IOException if an exception was encountered while writing the compound tag + */ + public static void writeCompressedOutputStream(final @NotNull CompoundTag tag, final @NotNull OutputStream output) throws IOException { + try (final DataOutputStream dos = new DataOutputStream(new GZIPOutputStream(output))) { + writeDataOutput(tag, dos); + } + } + + /** + * Writes a compound tag to {@code output}. + * + * @param tag the compound tag + * @param output the output + * @throws IOException if an exception was encountered while writing the compound tag + */ + public static void writeDataOutput(final @NotNull CompoundTag tag, final @NotNull DataOutput output) throws IOException { + output.writeByte(TagRegistry.getIdFor(CompoundTag.class)); + output.writeUTF(""); // write empty name + tag.write(output); + } + /** * Reads a compound tag from a {@link String}. * diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16_2to1_16_1/Protocol1_16_2To1_16_1.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16_2to1_16_1/Protocol1_16_2To1_16_1.java index 73eb4bd0e..6772fc3eb 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16_2to1_16_1/Protocol1_16_2To1_16_1.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_16_2to1_16_1/Protocol1_16_2To1_16_1.java @@ -77,6 +77,7 @@ public class Protocol1_16_2To1_16_1 extends Protocol @@ -87,7 +88,8 @@ public class Protocol1_16_2To1_16_1 extends Protocol relative chunk section y - int blockId = Protocol1_16_2To1_16_1.getNewBlockId(record.getBlockId()); + int blockId = Protocol1_16_2To1_16_1.getNewBlockStateId(record.getBlockId()); list.add(new BlockChangeRecord1_16_2(record.getSectionX(), record.getSectionY(), record.getSectionZ(), blockId)); }