From 21eb8243953f600053b09e4e03dae8c401d65b48 Mon Sep 17 00:00:00 2001 From: Myles Date: Wed, 17 May 2017 19:43:48 +0100 Subject: [PATCH] Better support for nbt arrays rereading in chunks --- .../Protocol1_9_3TO1_9_1_2.java | 6 +++--- .../protocol1_9_3to1_9_1_2/chunks/Chunk1_9_1_2.java | 2 +- .../protocol1_9to1_8/chunks/Chunk1_9to1_8.java | 11 ++++------- .../protocols/protocol1_9to1_8/types/ChunkType.java | 8 +++----- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3TO1_9_1_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3TO1_9_1_2.java index fb8bb8c54..2069f1fb1 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3TO1_9_1_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/Protocol1_9_3TO1_9_1_2.java @@ -17,7 +17,6 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.chunks.FakeTileEntit import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.types.Chunk1_9_1_2Type; -import java.util.ArrayList; import java.util.List; public class Protocol1_9_3TO1_9_1_2 extends Protocol { @@ -80,7 +79,7 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol { Chunk1_9_1_2Type type = new Chunk1_9_1_2Type(clientWorld); Chunk chunk = wrapper.passthrough(type); - List tags = new ArrayList<>(); + List tags = chunk.getBlockEntities(); for (int i = 0; i < chunk.getSections().length; i++) { ChunkSection section = chunk.getSections()[i]; if (section == null) @@ -98,7 +97,8 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol { } } - wrapper.write(Type.NBT_ARRAY, tags.toArray(new CompoundTag[0])); + // Send (for clients on this version) + wrapper.write(Type.NBT_ARRAY, chunk.getBlockEntities().toArray(new CompoundTag[0])); } }); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/Chunk1_9_1_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/Chunk1_9_1_2.java index 078686be9..5da9fa4c9 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/Chunk1_9_1_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9_3to1_9_1_2/chunks/Chunk1_9_1_2.java @@ -16,7 +16,7 @@ public class Chunk1_9_1_2 implements Chunk { private int bitmask; private final ChunkSection1_9_1_2[] sections; private byte[] biomeData; - List blockEntities; + private List blockEntities; public boolean isBiomeData() { return biomeData != null; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/Chunk1_9to1_8.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/Chunk1_9to1_8.java index 41ec9fbc7..b80cecf30 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/Chunk1_9to1_8.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/chunks/Chunk1_9to1_8.java @@ -6,7 +6,7 @@ import lombok.RequiredArgsConstructor; import lombok.ToString; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; -import java.util.Collections; +import java.util.ArrayList; import java.util.List; @RequiredArgsConstructor @@ -19,6 +19,7 @@ public class Chunk1_9to1_8 implements Chunk { private final int primaryBitmask; private final ChunkSection1_9to1_8[] sections; private final byte[] biomeData; + private final List blockEntities; private boolean unloadPacket = false; /** @@ -28,7 +29,8 @@ public class Chunk1_9to1_8 implements Chunk { * @param z coord */ public Chunk1_9to1_8(int x, int z) { - this(x, z, true, 0, new ChunkSection1_9to1_8[16], null); + this(x, z, true, 0, new ChunkSection1_9to1_8[16], null, + new ArrayList()); this.unloadPacket = true; } @@ -50,9 +52,4 @@ public class Chunk1_9to1_8 implements Chunk { public int getBitmask() { return primaryBitmask; } - - @Override - public List getBlockEntities() { - return Collections.emptyList(); - } } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java index 8ac1c6303..fe6934e40 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/types/ChunkType.java @@ -1,5 +1,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.types; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import us.myles.ViaVersion.api.Via; @@ -16,6 +17,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ShortBuffer; +import java.util.ArrayList; import java.util.BitSet; import java.util.logging.Level; @@ -137,7 +139,7 @@ public class ChunkType extends PartialType { } // Return chunks - return new Chunk1_9to1_8(chunkX, chunkZ, groundUp, bitmask, sections, biomeData); + return new Chunk1_9to1_8(chunkX, chunkZ, groundUp, bitmask, sections, biomeData, new ArrayList()); } @Override @@ -172,9 +174,5 @@ public class ChunkType extends PartialType { if (chunk.hasBiomeData()) { output.writeBytes(chunk.getBiomeData()); } - - } - - }