Skip to content

Commit

Permalink
Resolve fallout from globalPaletteBits removal (#777)
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Castle <[email protected]>
  • Loading branch information
Kas-tle authored Dec 20, 2023
1 parent 809a0c5 commit d3cc9d4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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();
Expand Down

0 comments on commit d3cc9d4

Please sign in to comment.