From 7edde72416ddffed55942ecdbb0e886b2aa3e96c Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 20 Oct 2023 12:43:46 +1000 Subject: [PATCH] Reuse 1.15, 1.16 and 1.16.2 chunk types as well --- .../viaversion/api/type/types/chunk/ChunkType1_15.java | 1 + .../viaversion/api/type/types/chunk/ChunkType1_16.java | 1 + .../api/type/types/chunk/ChunkType1_16_2.java | 1 + .../protocol1_15to1_14_4/packets/WorldPackets.java | 2 +- .../protocol1_16_2to1_16_1/packets/WorldPackets.java | 4 ++-- .../protocol1_16to1_15_2/packets/WorldPackets.java | 4 ++-- .../protocol1_17to1_16_4/packets/WorldPackets.java | 2 +- .../protocol1_19_4to1_19_3/Protocol1_19_4To1_19_3.java | 2 +- .../protocol1_19_4to1_19_3/packets/EntityPackets.java | 2 +- .../storage/PlayerVehicleTracker.java | 10 ++-------- 10 files changed, 13 insertions(+), 16 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java index 8cf7b8198..580927399 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_15.java @@ -35,6 +35,7 @@ import java.util.Arrays; import java.util.List; public class ChunkType1_15 extends Type { + public static final Type TYPE = new ChunkType1_15(); private static final CompoundTag[] EMPTY_COMPOUNDS = new CompoundTag[0]; public ChunkType1_15() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java index 39642580f..1f7c5b794 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16.java @@ -35,6 +35,7 @@ import java.util.Arrays; import java.util.List; public class ChunkType1_16 extends Type { + public static final Type TYPE = new ChunkType1_16(); private static final CompoundTag[] EMPTY_COMPOUNDS = new CompoundTag[0]; public ChunkType1_16() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java index a2aa0a882..659e3ed34 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/chunk/ChunkType1_16_2.java @@ -35,6 +35,7 @@ import java.util.Arrays; import java.util.List; public class ChunkType1_16_2 extends Type { + public static final Type TYPE = new ChunkType1_16_2(); private static final CompoundTag[] EMPTY_COMPOUNDS = new CompoundTag[0]; public ChunkType1_16_2() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java index b7f8eead7..51cc5b171 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java @@ -41,7 +41,7 @@ public final class WorldPackets { protocol.registerClientbound(ClientboundPackets1_14_4.CHUNK_DATA, wrapper -> { Chunk chunk = wrapper.read(ChunkType1_14.TYPE); - wrapper.write(new ChunkType1_15(), chunk); + wrapper.write(ChunkType1_15.TYPE, chunk); if (chunk.isFullChunk()) { int[] biomeData = chunk.getBiomeData(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java index 31aff57b5..ae69523ad 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java @@ -46,8 +46,8 @@ public class WorldPackets { blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING); protocol.registerClientbound(ClientboundPackets1_16.CHUNK_DATA, wrapper -> { - Chunk chunk = wrapper.read(new ChunkType1_16()); - wrapper.write(new ChunkType1_16_2(), chunk); + Chunk chunk = wrapper.read(ChunkType1_16.TYPE); + wrapper.write(ChunkType1_16_2.TYPE, chunk); for (int s = 0; s < chunk.getSections().length; s++) { ChunkSection section = chunk.getSections()[s]; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java index bb24bec88..27350beb2 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java @@ -59,8 +59,8 @@ public class WorldPackets { }); protocol.registerClientbound(ClientboundPackets1_15.CHUNK_DATA, wrapper -> { - Chunk chunk = wrapper.read(new ChunkType1_15()); - wrapper.write(new ChunkType1_16(), chunk); + Chunk chunk = wrapper.read(ChunkType1_15.TYPE); + wrapper.write(ChunkType1_16.TYPE, chunk); chunk.setIgnoreOldLightData(chunk.isFullChunk()); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java index b22a37410..c0516db0b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java @@ -122,7 +122,7 @@ public final class WorldPackets { }); protocol.registerClientbound(ClientboundPackets1_16_2.CHUNK_DATA, wrapper -> { - Chunk chunk = wrapper.read(new ChunkType1_16_2()); + Chunk chunk = wrapper.read(ChunkType1_16_2.TYPE); if (!chunk.isFullChunk()) { // All chunks are full chunk packets now (1.16 already stopped sending non-full chunks) // Construct multi block change packets instead diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/Protocol1_19_4To1_19_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/Protocol1_19_4To1_19_3.java index c5976fcfb..db1d40983 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/Protocol1_19_4To1_19_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/Protocol1_19_4To1_19_3.java @@ -110,7 +110,7 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol wrapper.user().put(new PlayerVehicleTracker(wrapper.user()))); + handler(wrapper -> wrapper.user().put(new PlayerVehicleTracker())); } }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/storage/PlayerVehicleTracker.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/storage/PlayerVehicleTracker.java index deb081d48..6873f0ed2 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/storage/PlayerVehicleTracker.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19_4to1_19_3/storage/PlayerVehicleTracker.java @@ -17,17 +17,12 @@ */ package com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.storage; -import com.viaversion.viaversion.api.connection.StoredObject; -import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.connection.StorableObject; -public class PlayerVehicleTracker extends StoredObject { +public class PlayerVehicleTracker implements StorableObject { private int vehicleId = -1; - public PlayerVehicleTracker(final UserConnection user) { - super(user); - } - public int getVehicleId() { return this.vehicleId; } @@ -35,5 +30,4 @@ public class PlayerVehicleTracker extends StoredObject { public void setVehicleId(final int vehicleId) { this.vehicleId = vehicleId; } - }