Skip to content

Commit

Permalink
fix(blockinfo): increase blocks that can be registered by reducing bi…
Browse files Browse the repository at this point in the history
…ome amount
  • Loading branch information
granny committed Dec 25, 2024
1 parent 1c45e6b commit 56cfdb3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

public class BiomeRegistry extends Registry<@NotNull Biome> {
private static final Gson GSON = new GsonBuilder().create();
public static final int MAX_INDEX = 1023;
public static final int MAX_INDEX = 511;

private final Map<String, Integer> indexMap;
private int lastIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

public class BlockRegistry extends Registry<@NotNull Block> {
private static final Gson GSON = new GsonBuilder().create();
public static final int MAX_INDEX = 1023;
public static final int MAX_INDEX = 2047;

private final Map<String, Integer> indexMap;
private int lastIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ public void scanBlock(@NotNull Region region, @NotNull Chunk chunk, Chunk.@NotNu
int biomeIndex = biome.index() == -1 ? Biome.DEFAULT.index() : biome.index();

// 11111111111111111111111111111111 - 32 bits - (4294967295)
// 1111111111 - 10 bits - block (1023)
// 1111111111 - 10 bits - biome (1023)
// 11111111111 - 11 bits - block (2047)
// 111111111 - 9 bits - biome (511)
// 111111111111 - 12 bits - yPos (4095)
int packed = ((blockIndex & 1023) << 22) | ((biomeIndex & 1023) << 12) | (y & 4095);
int packed = ((blockIndex & 2047) << 21) | ((biomeIndex & 511) << 12) | (y & 4095);
int index = (blockZ & 511) * 512 + (blockX & 511);
this.byteBuffer.put(12 + index * 4, ByteUtil.toBytes(packed));
}
Expand Down
10 changes: 7 additions & 3 deletions webmap/src/palette/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ export class Block {
private readonly _minY: number;

constructor(packed: number, minY: number) {
this._block = packed >>> 22;
this._biome = (packed & 0b0000000000_1111111111_000000000000) >>> 12;
this._yPos = packed & 0b0000000000_0000000000_111111111111;
// 11111111111111111111111111111111 - 32 bits - (4294967295)
// 11111111111 - 11 bits - block (2047)
// 111111111 - 9 bits - biome (511)
// 111111111111 - 12 bits - yPos (4095)
this._block = packed >>> 21;
this._biome = (packed & 0b00000000000_111111111_000000000000) >>> 12;
this._yPos = packed & 0b00000000000_000000000_111111111111;
this._minY = minY;
}

Expand Down

0 comments on commit 56cfdb3

Please sign in to comment.