|
1 | 1 | package org.geysermc.mcprotocollib.protocol.data.game.chunk; |
2 | 2 |
|
3 | | -import lombok.AllArgsConstructor; |
4 | 3 | import lombok.EqualsAndHashCode; |
5 | 4 | import lombok.Getter; |
6 | 5 | import lombok.NonNull; |
7 | | -import lombok.Setter; |
8 | 6 | import lombok.ToString; |
9 | 7 | import org.geysermc.mcprotocollib.protocol.data.game.chunk.palette.GlobalPalette; |
10 | 8 | import org.geysermc.mcprotocollib.protocol.data.game.chunk.palette.ListPalette; |
|
14 | 12 | import org.geysermc.mcprotocollib.protocol.data.game.chunk.palette.SingletonPalette; |
15 | 13 |
|
16 | 14 | @Getter |
17 | | -@Setter |
18 | | -@AllArgsConstructor |
19 | 15 | @EqualsAndHashCode |
20 | 16 | @ToString |
21 | 17 | public class DataPalette { |
22 | | - |
23 | | - /* |
24 | | - * @deprecated globalPaletteBits is no longer in use. |
25 | | - */ |
26 | | - @Deprecated(forRemoval = true) |
27 | | - public static final int GLOBAL_PALETTE_BITS_PER_ENTRY = 14; |
| 18 | + private static final double LOG_2 = Math.log(2.0); |
28 | 19 |
|
29 | 20 | private @NonNull Palette palette; |
30 | 21 | private BitStorage storage; |
31 | 22 | private final PaletteType paletteType; |
| 23 | + private final int globalPaletteBitsPerEntry; |
32 | 24 |
|
33 | | - /* |
34 | | - * @deprecated globalPaletteBits is no longer in use, use {@link #DataPalette(Palette, BitStorage, PaletteType)} instead. |
35 | | - */ |
36 | | - @Deprecated(forRemoval = true) |
37 | | - public DataPalette(@NonNull Palette palette, BitStorage storage, PaletteType paletteType, int globalPaletteBits) { |
38 | | - this(palette, storage, paletteType); |
| 25 | + private DataPalette(@NonNull Palette palette, BitStorage storage, PaletteType paletteType, int globalPaletteBitsPerEntry) { |
| 26 | + this.palette = palette; |
| 27 | + this.storage = storage; |
| 28 | + this.paletteType = paletteType; |
| 29 | + this.globalPaletteBitsPerEntry = globalPaletteBitsPerEntry; |
39 | 30 | } |
40 | 31 |
|
41 | 32 | public DataPalette(DataPalette original) { |
42 | | - this(original.palette.copy(), original.storage == null ? null : new BitStorage(original.storage), original.paletteType); |
| 33 | + this(original.palette.copy(), original.storage == null ? null : new BitStorage(original.storage), original.paletteType, original.globalPaletteBitsPerEntry); |
43 | 34 | } |
44 | 35 |
|
45 | | - public static DataPalette createForChunk() { |
46 | | - return createEmpty(PaletteType.CHUNK); |
| 36 | + public static DataPalette createForBlockState(int initialState, int blockStateRegistrySize) { |
| 37 | + return createEmpty(PaletteType.BLOCK_STATE, initialState, blockStateRegistrySize); |
47 | 38 | } |
48 | 39 |
|
49 | | - /* |
50 | | - * @deprecated globalPaletteBits is no longer in use, use {@link #createForChunk()} instead. |
51 | | - */ |
52 | | - @Deprecated(forRemoval = true) |
53 | | - public static DataPalette createForChunk(int globalPaletteBits) { |
54 | | - return createForChunk(); |
55 | | - } |
56 | | - |
57 | | - /* |
58 | | - * @deprecated globalPaletteBits is no longer in use, use {@link #createForBiome()} instead. |
59 | | - */ |
60 | | - @Deprecated(forRemoval = true) |
61 | | - public static DataPalette createForBiome(int globalPaletteBits) { |
62 | | - return createForBiome(); |
| 40 | + public static DataPalette createForBiome(int initialBiome, int biomeRegistrySize) { |
| 41 | + return createEmpty(PaletteType.BIOME, initialBiome, biomeRegistrySize); |
63 | 42 | } |
64 | 43 |
|
65 | | - public static DataPalette createForBiome() { |
66 | | - return createEmpty(PaletteType.BIOME); |
| 44 | + public static DataPalette createEmpty(PaletteType paletteType, int initial, int registrySize) { |
| 45 | + return create(new SingletonPalette(initial), null, paletteType, registrySize); |
67 | 46 | } |
68 | 47 |
|
69 | | - public static DataPalette createEmpty(PaletteType paletteType) { |
70 | | - return new DataPalette(new ListPalette(paletteType.getMinBitsPerEntry()), |
71 | | - new BitStorage(paletteType.getMinBitsPerEntry(), paletteType.getStorageSize()), paletteType); |
| 48 | + public static DataPalette create(@NonNull Palette palette, BitStorage storage, PaletteType paletteType, int registrySize) { |
| 49 | + return new DataPalette(palette, storage, paletteType, calculateBitsPerEntry(registrySize)); |
72 | 50 | } |
73 | 51 |
|
74 | | - /* |
75 | | - * @deprecated globalPaletteBits is no longer in use, use {@link #createEmpty(PaletteType)} instead. |
76 | | - */ |
77 | | - @Deprecated(forRemoval = true) |
78 | | - public static DataPalette createEmpty(PaletteType paletteType, int globalPaletteBits) { |
79 | | - return createEmpty(paletteType); |
80 | | - } |
81 | | - |
82 | | - |
83 | 52 | public int get(int x, int y, int z) { |
84 | 53 | if (storage != null) { |
85 | 54 | int id = this.storage.get(index(x, y, z)); |
@@ -115,7 +84,7 @@ private int sanitizeBitsPerEntry(int bitsPerEntry) { |
115 | 84 | if (bitsPerEntry <= this.paletteType.getMaxBitsPerEntry()) { |
116 | 85 | return Math.max(this.paletteType.getMinBitsPerEntry(), bitsPerEntry); |
117 | 86 | } else { |
118 | | - return GLOBAL_PALETTE_BITS_PER_ENTRY; |
| 87 | + return globalPaletteBitsPerEntry; |
119 | 88 | } |
120 | 89 | } |
121 | 90 |
|
@@ -149,4 +118,9 @@ private static Palette createPalette(int bitsPerEntry, PaletteType paletteType) |
149 | 118 | private int index(int x, int y, int z) { |
150 | 119 | return y << paletteType.getMaxBitsPerEntry() | z << paletteType.getMinBitsPerEntry() | x; |
151 | 120 | } |
| 121 | + |
| 122 | + private static int calculateBitsPerEntry(int registrySize) { |
| 123 | + // Mojmap uses Mth.ceillog2 |
| 124 | + return (int) Math.ceil(Math.log(registrySize) / LOG_2); |
| 125 | + } |
152 | 126 | } |
0 commit comments