From 809a0c58f2eaec0c91effe0da574ec8781ca9e4b Mon Sep 17 00:00:00 2001 From: David Mayr Date: Wed, 20 Dec 2023 22:54:45 +0100 Subject: [PATCH] Fix DataPalette index & deprecate unused globalPaletteBits (#775) * fix: datapalette not working correctly * feat: deprecate global palette bits * chore: redirect deprecated createEmpty call to new one --- .../protocol/data/game/chunk/DataPalette.java | 53 +++++++++++++++---- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/DataPalette.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/DataPalette.java index f4ea269f..d0858c8c 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/DataPalette.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/chunk/DataPalette.java @@ -9,34 +9,67 @@ import lombok.*; @EqualsAndHashCode @ToString public class DataPalette { + + /* + * @deprecated globalPaletteBits is no longer in use. + */ + @Deprecated(forRemoval = true) public static final int GLOBAL_PALETTE_BITS_PER_ENTRY = 14; private @NonNull Palette palette; private BitStorage storage; private final PaletteType paletteType; - private final int globalPaletteBits; + + /* + * @deprecated globalPaletteBits is no longer in use, use {@link #DataPalette(Palette, BitStorage, PaletteType)} instead. + */ + @Deprecated(forRemoval = true) + public DataPalette(@NonNull Palette palette, BitStorage storage, PaletteType paletteType, int globalPaletteBits) { + this(palette, storage, paletteType); + } public DataPalette(DataPalette original) { - this(original.palette.copy(), original.storage == null ? null : new BitStorage(original.storage), original.paletteType, original.globalPaletteBits); + this(original.palette.copy(), original.storage == null ? null : new BitStorage(original.storage), original.paletteType); } public static DataPalette createForChunk() { - return createForChunk(GLOBAL_PALETTE_BITS_PER_ENTRY); + return createEmpty(PaletteType.CHUNK); } + /* + * @deprecated globalPaletteBits is no longer in use, use {@link #createForChunk()} instead. + */ + @Deprecated(forRemoval = true) public static DataPalette createForChunk(int globalPaletteBits) { - return createEmpty(PaletteType.CHUNK, globalPaletteBits); + return createForChunk(); } + /* + * @deprecated globalPaletteBits is no longer in use, use {@link #createForBiome()} instead. + */ + @Deprecated(forRemoval = true) public static DataPalette createForBiome(int globalPaletteBits) { - return createEmpty(PaletteType.BIOME, globalPaletteBits); + return createForBiome(); } - public static DataPalette createEmpty(PaletteType paletteType, int globalPaletteBits) { - return new DataPalette(new ListPalette(paletteType.getMinBitsPerEntry()), - new BitStorage(paletteType.getMinBitsPerEntry(), paletteType.getStorageSize()), paletteType, globalPaletteBits); + public static DataPalette createForBiome() { + return createEmpty(PaletteType.BIOME); } + public static DataPalette createEmpty(PaletteType paletteType) { + return new DataPalette(new ListPalette(paletteType.getMinBitsPerEntry()), + new BitStorage(paletteType.getMinBitsPerEntry(), paletteType.getStorageSize()), paletteType); + } + + /* + * @deprecated globalPaletteBits is no longer in use, use {@link #createEmpty(PaletteType)} instead. + */ + @Deprecated(forRemoval = true) + public static DataPalette createEmpty(PaletteType paletteType, int globalPaletteBits) { + return createEmpty(paletteType); + } + + public int get(int x, int y, int z) { if (storage != null) { int id = this.storage.get(index(x, y, z)); @@ -103,7 +136,7 @@ public class DataPalette { } } - private static int index(int x, int y, int z) { - return y << 8 | z << 4 | x; + private int index(int x, int y, int z) { + return y << paletteType.getMaxBitsPerEntry() | z << paletteType.getMinBitsPerEntry() | x; } }