Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve fallout from globalPaletteBits removal #777

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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