Skip to content

Commit

Permalink
register blocks/biomes even if max index is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
granny committed Dec 12, 2024
1 parent 35ee8ce commit 7d04354
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 21 deletions.
5 changes: 0 additions & 5 deletions bukkit/src/main/java/net/pl3x/map/bukkit/BukkitWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ public BukkitWorld(@NotNull ServerLevel level, @NotNull String name) {
// register biomes
Set<Map.Entry<ResourceKey<Biome>, Biome>> entries = level.registryAccess().lookupOrThrow(Registries.BIOME).entrySet();
for (Map.Entry<ResourceKey<Biome>, Biome> entry : entries) {
if (getBiomeRegistry().size() > BiomeRegistry.MAX_INDEX) {
Logger.debug(String.format("Cannot register any more biomes. Registered: %d Unregistered: %d", getBiomeRegistry().size(), entries.size() - getBiomeRegistry().size()));
break;
}

String id = entry.getKey().location().toString();
Biome biome = entry.getValue();
float temperature = Mathf.clamp(0.0F, 1.0F, biome.getBaseTemperature());
Expand Down
5 changes: 0 additions & 5 deletions bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,6 @@ public int getColorForPower(byte power) {
protected void loadBlocks() {
Set<Map.Entry<ResourceKey<Block>, Block>> entries = MinecraftServer.getServer().registryAccess().lookupOrThrow(Registries.BLOCK).entrySet();
for (Map.Entry<ResourceKey<Block>, Block> entry : entries) {
if (getBlockRegistry().size() > BlockRegistry.MAX_INDEX) {
Logger.debug(String.format("Cannot register any more biomes. Registered: %d Unregistered: %d", getBlockRegistry().size(), entries.size() - getBlockRegistry().size()));
break;
}

String id = entry.getKey().location().toString();
int color = entry.getValue().defaultMapColor().col;
getBlockRegistry().register(id, color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public void init(@NotNull World world) {
}

private int getNextIndex(String id) {
if (size() > MAX_INDEX) {
return -1;
}

int index = this.indexMap.getOrDefault(id, -1);
if (index > -1) {
return index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public Map<String, Integer> getIndexMap() {
}

private int getNextIndex(String id) {
if (size() > MAX_INDEX) {
return -1;
}

int index = this.indexMap.getOrDefault(id, -1);
if (index > -1) {
return index;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.pl3x.map.core.util.Mathf;
import net.pl3x.map.core.world.Biome;
import net.pl3x.map.core.world.Block;
import net.pl3x.map.core.world.Blocks;
import net.pl3x.map.core.world.Chunk;
import net.pl3x.map.core.world.Region;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -162,11 +163,14 @@ public void scanBlock(@NotNull Region region, @NotNull Chunk chunk, Chunk.@NotNu
Block block = (fluid ? data.getFluidState() : data.getBlockState()).getBlock();
Biome biome = data.getBiome(region, blockX, blockZ);

int blockIndex = block.getIndex() == -1 ? Blocks.AIR.getIndex() : block.getIndex();
int biomeIndex = biome.index() == -1 ? Biome.DEFAULT.index() : biome.index();

// 11111111111111111111111111111111 - 32 bits - (4294967295)
// 1111111111 - 10 bits - block (1023)
// 1111111111 - 10 bits - biome (1023)
// 111111111111 - 12 bits - yPos (4095)
int packed = ((block.getIndex() & 1023) << 22) | ((biome.index() & 1023) << 12) | (y & 4095);
int packed = ((blockIndex & 1023) << 22) | ((biomeIndex & 1023) << 12) | (y & 4095);
int index = (blockZ & 511) * 512 + (blockX & 511);
this.byteBuffer.put(12 + index * 4, ByteUtil.toBytes(packed));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ public FabricWorld(@NotNull ServerLevel level, @NotNull String name) {
// register biomes
Set<Map.Entry<ResourceKey<Biome>, Biome>> entries = level.registryAccess().lookupOrThrow(Registries.BIOME).entrySet();
for (Map.Entry<ResourceKey<Biome>, Biome> entry : entries) {
if (getBiomeRegistry().size() > BiomeRegistry.MAX_INDEX) {
Logger.debug(String.format("Cannot register any more biomes. Registered: %d Unregistered: %d", getBiomeRegistry().size(), entries.size() - getBiomeRegistry().size()));
break;
}

String id = entry.getKey().location().toString();
Biome biome = entry.getValue();
float temperature = Mathf.clamp(0.0F, 1.0F, biome.getBaseTemperature());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,6 @@ public int getColorForPower(byte power) {
protected void loadBlocks() {
Set<Map.Entry<ResourceKey<Block>, Block>> entries = this.server.registryAccess().lookupOrThrow(Registries.BLOCK).entrySet();
for (Map.Entry<ResourceKey<Block>, Block> entry : entries) {
if (getBlockRegistry().size() > BlockRegistry.MAX_INDEX) {
Logger.debug(String.format("Cannot register any more blocks. Registered: %d Unregistered: %d", getBlockRegistry().size(), entries.size() - getBlockRegistry().size()));
break;
}

String id = entry.getKey().location().toString();
int color = entry.getValue().defaultMapColor().col;
getBlockRegistry().register(id, color);
Expand Down

0 comments on commit 7d04354

Please sign in to comment.