From d3cc9d47dfea246c18806d2d7a83fa623141db2a Mon Sep 17 00:00:00 2001 From: Kas-tle <26531652+Kas-tle@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:57:58 -0800 Subject: [PATCH] Resolve fallout from globalPaletteBits removal (#777) Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> --- .../protocol/codec/MinecraftCodecHelper.java | 26 +++++++++++++++---- .../data/game/chunk/ChunkSection.java | 2 +- .../mc/protocol/data/ChunkTest.java | 6 ++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java index ae01befc9..23eae6631 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java +++ b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java @@ -736,7 +736,7 @@ public void writeRecipeIngredient(ByteBuf buf, Ingredient ingredient) throws IOE } } - public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType, int globalPaletteBits) throws IOException { + public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType) throws IOException { int bitsPerEntry = buf.readByte() & 0xFF; Palette palette = this.readPalette(buf, paletteType, bitsPerEntry); BitStorage storage; @@ -751,7 +751,15 @@ public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType, int glo storage = null; } - return new DataPalette(palette, storage, paletteType, globalPaletteBits); + return new DataPalette(palette, storage, paletteType); + } + + /** + * @deprecated globalPaletteBits is no longer in use, use {@link #readDataPalette(ByteBuf, PaletteType)} instead. + */ + @Deprecated(forRemoval = true) + public DataPalette readDataPalette(ByteBuf buf, PaletteType paletteType, int globalPaletteBits) throws IOException { + return this.readDataPalette(buf, paletteType); } public void writeDataPalette(ByteBuf buf, DataPalette palette) { @@ -789,14 +797,22 @@ private Palette readPalette(ByteBuf buf, PaletteType paletteType, int bitsPerEnt } } - public ChunkSection readChunkSection(ByteBuf buf, int globalBiomePaletteBits) throws IOException { + public ChunkSection readChunkSection(ByteBuf buf) throws IOException { int blockCount = buf.readShort(); - DataPalette chunkPalette = this.readDataPalette(buf, PaletteType.CHUNK, DataPalette.GLOBAL_PALETTE_BITS_PER_ENTRY); - DataPalette biomePalette = this.readDataPalette(buf, PaletteType.BIOME, globalBiomePaletteBits); + DataPalette chunkPalette = this.readDataPalette(buf, PaletteType.CHUNK); + DataPalette biomePalette = this.readDataPalette(buf, PaletteType.BIOME); return new ChunkSection(blockCount, chunkPalette, biomePalette); } + /** + * @deprecated globalBiomePaletteBits is no longer in use, use {@link #readChunkSection(ByteBuf)} instead. + */ + @Deprecated(forRemoval = true) + public ChunkSection readChunkSection(ByteBuf buf, int globalBiomePaletteBits) throws IOException { + return this.readChunkSection(buf); + } + public void writeChunkSection(ByteBuf buf, ChunkSection section) { buf.writeShort(section.getBlockCount()); this.writeDataPalette(buf, section.getChunkData()); diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/ChunkSection.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/ChunkSection.java index 99685601d..bbdcae3ee 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/ChunkSection.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/ChunkSection.java @@ -16,7 +16,7 @@ public class ChunkSection { private @NonNull DataPalette biomeData; public ChunkSection() { - this(0, DataPalette.createForChunk(), DataPalette.createForBiome(4)); + this(0, DataPalette.createForChunk(), DataPalette.createForBiome()); } public ChunkSection(ChunkSection original) { diff --git a/src/test/java/com/github/steveice10/mc/protocol/data/ChunkTest.java b/src/test/java/com/github/steveice10/mc/protocol/data/ChunkTest.java index a636aa50d..13c8ea129 100644 --- a/src/test/java/com/github/steveice10/mc/protocol/data/ChunkTest.java +++ b/src/test/java/com/github/steveice10/mc/protocol/data/ChunkTest.java @@ -31,8 +31,8 @@ public void setup() { chunkSectionsToTest.add(section); SingletonPalette singletonPalette = new SingletonPalette(20); - DataPalette dataPalette = new DataPalette(singletonPalette, null, PaletteType.CHUNK, DataPalette.GLOBAL_PALETTE_BITS_PER_ENTRY); - DataPalette biomePalette = new DataPalette(singletonPalette, null, PaletteType.BIOME, 4); + DataPalette dataPalette = new DataPalette(singletonPalette, null, PaletteType.CHUNK); + DataPalette biomePalette = new DataPalette(singletonPalette, null, PaletteType.BIOME); section = new ChunkSection(4096, dataPalette, biomePalette); chunkSectionsToTest.add(section); } @@ -45,7 +45,7 @@ public void testChunkSectionEncoding() throws IOException { helper.writeChunkSection(buf, section); ChunkSection decoded; try { - decoded = helper.readChunkSection(buf, 4); + decoded = helper.readChunkSection(buf); } catch (Exception e) { System.out.println(section); e.printStackTrace();