From 4a7df2f5b55904edafccc2ab97b1cba92052d36e Mon Sep 17 00:00:00 2001 From: Mirco Kroon <23699979+mircokroon@users.noreply.github.com> Date: Sat, 29 Jun 2024 17:46:01 +0200 Subject: [PATCH 1/3] Disabled villager trade saving --- src/main/java/game/data/entity/specific/Villager.java | 2 +- src/main/java/game/data/villagers/VillagerManager.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/game/data/entity/specific/Villager.java b/src/main/java/game/data/entity/specific/Villager.java index 1c7aa1a..3752085 100644 --- a/src/main/java/game/data/entity/specific/Villager.java +++ b/src/main/java/game/data/entity/specific/Villager.java @@ -71,7 +71,7 @@ public void updateTrades(List trades, int villagerLevel, int vill } private void addTradeNbtTags(CompoundTag root) { - if (trades == null || trades.size() == 0) { + if (trades == null || trades.isEmpty()) { return; } diff --git a/src/main/java/game/data/villagers/VillagerManager.java b/src/main/java/game/data/villagers/VillagerManager.java index d4edb6e..cafb0ad 100644 --- a/src/main/java/game/data/villagers/VillagerManager.java +++ b/src/main/java/game/data/villagers/VillagerManager.java @@ -43,6 +43,12 @@ public void lastInteractedWith(DataTypeProvider provider) { } public void parseAndStoreVillagerTrade(DataTypeProvider provider) { + // TODO: villager trades cannot be saved since readSlot is broken in 1.20.2+ due to the + // new item components + if (Config.versionReporter().isAtLeast(Version.V1_20_2)) { + return; + } + if (lastInteractedWith == null) { return; // This should be impossible } From 0fb0e15d152e9be9f029a6ea900f60ddd5aa029a Mon Sep 17 00:00:00 2001 From: Mirco Kroon <23699979+mircokroon@users.noreply.github.com> Date: Sat, 29 Jun 2024 21:28:32 +0200 Subject: [PATCH 2/3] Prevent some errors on 1.21 --- src/main/java/config/Version.java | 1 + .../java/game/data/RenderDistanceExtender.java | 5 +++++ src/main/java/game/data/WorldManager.java | 6 ++++++ .../game/data/dimension/DimensionRegistry.java | 9 ++++++++- src/test/java/game/data/chunk/ChunkTest.java | 6 ++++++ src/test/resources/chunkdata_1_21 | Bin 0 -> 8322 bytes 6 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/chunkdata_1_21 diff --git a/src/main/java/config/Version.java b/src/main/java/config/Version.java index 17081c7..f25682d 100644 --- a/src/main/java/config/Version.java +++ b/src/main/java/config/Version.java @@ -15,6 +15,7 @@ public enum Version { V1_20_2(764, 3578), V1_20_4(765, 3698), V1_20_6(766, 3839), + V1_21(767, 3953), ANY(0, 0); public final int dataVersion; diff --git a/src/main/java/game/data/RenderDistanceExtender.java b/src/main/java/game/data/RenderDistanceExtender.java index f4dd3d6..27620b7 100644 --- a/src/main/java/game/data/RenderDistanceExtender.java +++ b/src/main/java/game/data/RenderDistanceExtender.java @@ -88,6 +88,11 @@ public void updatePlayerPos(Coordinate2D newPos) { if (this.extendedDistance == 0) { return; } + // TODO: for 1.21, fix client unable to read chunk data packets generated by downloader for some reason + if (Config.versionReporter().isAtLeast(Version.V1_21)) { + return; + } + int dist = this.extendedDistance; if (oldPos.isInRangeChebyshev(newChunkPos, 1)) { diff --git a/src/main/java/game/data/WorldManager.java b/src/main/java/game/data/WorldManager.java index da7e0ac..6e416e2 100644 --- a/src/main/java/game/data/WorldManager.java +++ b/src/main/java/game/data/WorldManager.java @@ -604,7 +604,13 @@ public Set sendChunksToPlayer(Collection desired) { // send a packet with the chunk to the client Chunk chunk = chunkBinary.toChunk(withDim); + // skip chunks loaded in an earlier version + if (chunk.getDataVersion() != Config.versionReporter().getDataVersion()) { + continue; + } + try { + System.out.println("Sending chunk of version " + chunk.getDataVersion() + " (running " + Config.versionReporter().getDataVersion() + ")"); PacketBuilder chunkData = chunk.toPacket(); PacketBuilder light = chunk.toLightPacket(); if (light != null) { diff --git a/src/main/java/game/data/dimension/DimensionRegistry.java b/src/main/java/game/data/dimension/DimensionRegistry.java index ac9a2c8..998e20f 100644 --- a/src/main/java/game/data/dimension/DimensionRegistry.java +++ b/src/main/java/game/data/dimension/DimensionRegistry.java @@ -141,7 +141,14 @@ private void readBiomes(ListTag biomeList) { } public Dimension getDimension(String name) { - return dimensions.get(name); + var dim = dimensions.get(name); + + if (dim == null) { + System.out.println("Warning: Dimension " + name + " not found, using overworld"); + return Dimension.OVERWORLD; + } + + return dim; } /** diff --git a/src/test/java/game/data/chunk/ChunkTest.java b/src/test/java/game/data/chunk/ChunkTest.java index 89bf5ca..228bea5 100644 --- a/src/test/java/game/data/chunk/ChunkTest.java +++ b/src/test/java/game/data/chunk/ChunkTest.java @@ -48,6 +48,7 @@ private void testFor(int protocolVersion, String dataFile) throws IOException, C biomeMap.put("minecraft:badlands", new Biome(0)); biomeMap.put("minecraft:forest", new Biome(1)); biomeMap.put("minecraft:river", new Biome(2)); + biomeMap.put("minecraft:plains", new Biome(3)); when(codecMock.getBiomeRegistry()).thenReturn(new BiomeRegistry(biomeMap)); when(mock.getDimensionRegistry()).thenReturn(codecMock); @@ -184,4 +185,9 @@ void chunk_1_17() throws IOException, ClassNotFoundException { void chunk_1_19() throws IOException, ClassNotFoundException { testFor(Version.V1_19.protocolVersion, "chunkdata_1_19"); } + + @Test + void chunk_1_21() throws IOException, ClassNotFoundException { + testFor(Version.V1_21.protocolVersion, "chunkdata_1_21"); + } } \ No newline at end of file diff --git a/src/test/resources/chunkdata_1_21 b/src/test/resources/chunkdata_1_21 new file mode 100644 index 0000000000000000000000000000000000000000..d02572708d1fd0fff7091ab0588718e42bd7fcc2 GIT binary patch literal 8322 zcmeI1*H;tllgB9{AP6c|DWM926pZ_*P%0g)0Z(xnJeq&HDo=s`;8 zARq(?JwWIr5W>E{-Lv~g?0KJyIdkSaGZ&wWIcMgn+#{jz_ak9*vG;TmePthDFY4$T z=;bb|`X8&}=4I~}@+@)a+YnlXnvCRzHVKu7x1)W4o41!X$qj$EP$z8?>Hs%SC;tF@ zPai81>i;fQ`=?C+37M5jun!3dsSybY37PX-!=XUG|HLYfS#US0jF-tsNd6;p{iCvS zkOk-NS%W>SW<%gf&L*8{#45(!XsVU(D+()YQGI(f6pMG2w&iwYdZ(XV zO*dSPDqMc?|N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kHthyzd*a!ntSM}N zMZ99@yzmWv$Yd34Yhkldm5vp=J1Ue2C#*}9zAFhodC}+viP4oNPPdy|avKy|w8Ogx z!|>th+uqO3SMyENDZGEXwFdgE@gA?HBqG#Yt~N&Gj?5Nw!7IBRjqTtSoK85o%I`r@ z&H5v8a+Ci%p>ihe6-*Turf2`}Y2)m3Ge=tX?$R?$GI=dsG~L8Rk8x(h0Lb?P}RmK_T%G2Y~g-$n{nn@51<9?fD?>3#cym dME0K_f`8w?1pX!PFM)pv{7c|p0{_1V{1+3d Date: Sat, 29 Jun 2024 21:33:24 +0200 Subject: [PATCH 3/3] Removed print --- src/main/java/game/data/WorldManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/game/data/WorldManager.java b/src/main/java/game/data/WorldManager.java index 6e416e2..061d817 100644 --- a/src/main/java/game/data/WorldManager.java +++ b/src/main/java/game/data/WorldManager.java @@ -610,7 +610,6 @@ public Set sendChunksToPlayer(Collection desired) { } try { - System.out.println("Sending chunk of version " + chunk.getDataVersion() + " (running " + Config.versionReporter().getDataVersion() + ")"); PacketBuilder chunkData = chunk.toPacket(); PacketBuilder light = chunk.toLightPacket(); if (light != null) {