From 3f229c4cb9bc8b47fb6ea5c6605fcaaa062f5c1a Mon Sep 17 00:00:00 2001 From: _tomcraft <936063+tomcraft@users.noreply.github.com> Date: Mon, 11 Oct 2021 21:00:32 +0200 Subject: [PATCH 1/2] Minor improvements (#2709) --- .../packets/WorldPackets.java | 56 ++++--------------- .../types/ChunkBulk1_8Type.java | 9 ++- 2 files changed, 14 insertions(+), 51 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java index c6075bd8d..7cd631d87 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -141,6 +141,8 @@ public class WorldPackets { ClientChunks clientChunks = wrapper.user().get(ClientChunks.class); Chunk chunk = wrapper.read(new Chunk1_8Type(clientWorld)); + long chunkHash = ClientChunks.toLong(chunk.getX(), chunk.getZ()); + // Check if the chunk should be handled as an unload packet if (chunk.isFullChunk() && chunk.getBitmask() == 0) { wrapper.setPacketType(ClientboundPackets1_9.UNLOAD_CHUNK); @@ -151,7 +153,7 @@ public class WorldPackets { CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class); provider.unloadChunk(wrapper.user(), chunk.getX(), chunk.getZ()); - clientChunks.getLoadedChunks().remove(ClientChunks.toLong(chunk.getX(), chunk.getZ())); + clientChunks.getLoadedChunks().remove(chunkHash); // Unload the empty chunks if (Via.getConfig().isChunkBorderFix()) { @@ -167,9 +169,10 @@ public class WorldPackets { } } } else { - wrapper.write(new Chunk1_9_1_2Type(clientWorld), chunk); + Type chunkType = new Chunk1_9_1_2Type(clientWorld); + wrapper.write(chunkType, chunk); - clientChunks.getLoadedChunks().add(ClientChunks.toLong(chunk.getX(), chunk.getZ())); + clientChunks.getLoadedChunks().add(chunkHash); // Send empty chunks surrounding the loaded chunk to force 1.9+ clients to render the new chunk if (Via.getConfig().isChunkBorderFix()) { @@ -179,7 +182,7 @@ public class WorldPackets { if (!clientChunks.getLoadedChunks().contains(ClientChunks.toLong(chunkX, chunkZ))) { PacketWrapper emptyChunk = wrapper.create(ClientboundPackets1_9.CHUNK_DATA); Chunk c = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], new int[256], new ArrayList<>()); - emptyChunk.write(new Chunk1_9_1_2Type(wrapper.user().get(ClientWorld.class)), c); + emptyChunk.write(chunkType, c); emptyChunk.send(Protocol1_9To1_8.class); } } @@ -199,10 +202,11 @@ public class WorldPackets { ClientChunks clientChunks = wrapper.user().get(ClientChunks.class); Chunk[] chunks = wrapper.read(new ChunkBulk1_8Type(clientWorld)); + Type chunkType = new Chunk1_9_1_2Type(clientWorld); // Split into multiple chunk packets for (Chunk chunk : chunks) { PacketWrapper chunkData = wrapper.create(ClientboundPackets1_9.CHUNK_DATA); - chunkData.write(new Chunk1_9_1_2Type(clientWorld), chunk); + chunkData.write(chunkType, chunk); chunkData.send(Protocol1_9To1_8.class); clientChunks.getLoadedChunks().add(ClientChunks.toLong(chunk.getX(), chunk.getZ())); @@ -215,7 +219,7 @@ public class WorldPackets { if (!clientChunks.getLoadedChunks().contains(ClientChunks.toLong(chunkX, chunkZ))) { PacketWrapper emptyChunk = wrapper.create(ClientboundPackets1_9.CHUNK_DATA); Chunk c = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], new int[256], new ArrayList<>()); - emptyChunk.write(new Chunk1_9_1_2Type(wrapper.user().get(ClientWorld.class)), c); + emptyChunk.write(chunkType, c); emptyChunk.send(Protocol1_9To1_8.class); } } @@ -459,44 +463,4 @@ public class WorldPackets { }); } - public static final class ChunkBulkSection { - private final int x; - private final int z; - private final int bitMask; - private final int length; - private byte[] data; - - public ChunkBulkSection(PacketWrapper wrapper, boolean skylight) throws Exception { - x = wrapper.read(Type.INT); - z = wrapper.read(Type.INT); - bitMask = wrapper.read(Type.UNSIGNED_SHORT); - - int bitCount = Integer.bitCount(bitMask); - length = (bitCount * ((4096 * 2) + 2048)) + (skylight ? bitCount * 2048 : 0) + 256; // Thanks MCProtocolLib - } - - public int getX() { - return x; - } - - public int getZ() { - return z; - } - - public int getBitMask() { - return bitMask; - } - - public int getLength() { - return length; - } - - public byte @Nullable [] getData() { - return data; - } - - public void setData(byte[] data) { - this.data = data; - } - } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/types/ChunkBulk1_8Type.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/types/ChunkBulk1_8Type.java index c628fba75..4a882db91 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/types/ChunkBulk1_8Type.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/types/ChunkBulk1_8Type.java @@ -65,12 +65,11 @@ public class ChunkBulk1_8Type extends PartialType { @Override public void write(ByteBuf output, ClientWorld world, Chunk[] chunks) throws Exception { boolean skyLight = false; - for (Chunk c : chunks) { + loop1: for (Chunk c : chunks) { for (ChunkSection section : c.getSections()) { - if (section != null) { - if (section.getLight().hasSkyLight()) { - skyLight = true; - } + if (section != null && section.getLight().hasSkyLight()) { + skyLight = true; + break loop1; } } } From e7e1ee7a2bec2b5a70b1fd98306e9d1f53dc9dc7 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 11 Oct 2021 21:03:11 +0200 Subject: [PATCH 2/2] Update shadow --- build-logic/build.gradle.kts | 2 +- settings.gradle.kts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index c0d998653..7ce1f3b36 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -8,5 +8,5 @@ repositories { dependencies { // version must be manually kept in sync with the one in root project settings.gradle.kts - implementation("gradle.plugin.com.github.jengelman.gradle.plugins", "shadow", "7.0.0") + implementation("gradle.plugin.com.github.johnrengelman", "shadow", "7.1.0") } diff --git a/settings.gradle.kts b/settings.gradle.kts index 995a746ed..a4c2cbb14 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -20,7 +20,7 @@ pluginManagement { // default plugin versions plugins { id("net.kyori.blossom") version "1.2.0" - id("com.github.johnrengelman.shadow") version "7.0.0" + id("com.github.johnrengelman.shadow") version "7.1.0" } }