From 7d043548dc6d7d642657fc9f56ca7965d7fde668 Mon Sep 17 00:00:00 2001 From: granny Date: Thu, 12 Dec 2024 01:30:14 -0800 Subject: [PATCH] register blocks/biomes even if max index is reached --- bukkit/src/main/java/net/pl3x/map/bukkit/BukkitWorld.java | 5 ----- bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapImpl.java | 5 ----- .../main/java/net/pl3x/map/core/registry/BiomeRegistry.java | 4 ++++ .../main/java/net/pl3x/map/core/registry/BlockRegistry.java | 4 ++++ .../java/net/pl3x/map/core/renderer/BlockInfoRenderer.java | 6 +++++- .../main/java/net/pl3x/map/fabric/server/FabricWorld.java | 5 ----- .../net/pl3x/map/fabric/server/Pl3xMapFabricServer.java | 5 ----- 7 files changed, 13 insertions(+), 21 deletions(-) diff --git a/bukkit/src/main/java/net/pl3x/map/bukkit/BukkitWorld.java b/bukkit/src/main/java/net/pl3x/map/bukkit/BukkitWorld.java index 93d95b12e..6e536b016 100644 --- a/bukkit/src/main/java/net/pl3x/map/bukkit/BukkitWorld.java +++ b/bukkit/src/main/java/net/pl3x/map/bukkit/BukkitWorld.java @@ -67,11 +67,6 @@ public BukkitWorld(@NotNull ServerLevel level, @NotNull String name) { // register biomes Set, Biome>> entries = level.registryAccess().lookupOrThrow(Registries.BIOME).entrySet(); for (Map.Entry, 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()); diff --git a/bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapImpl.java b/bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapImpl.java index ced8d2f5f..9fb3f7bff 100644 --- a/bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapImpl.java +++ b/bukkit/src/main/java/net/pl3x/map/bukkit/Pl3xMapImpl.java @@ -172,11 +172,6 @@ public int getColorForPower(byte power) { protected void loadBlocks() { Set, Block>> entries = MinecraftServer.getServer().registryAccess().lookupOrThrow(Registries.BLOCK).entrySet(); for (Map.Entry, 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); diff --git a/core/src/main/java/net/pl3x/map/core/registry/BiomeRegistry.java b/core/src/main/java/net/pl3x/map/core/registry/BiomeRegistry.java index 4b5c33ca1..d9fae6d09 100644 --- a/core/src/main/java/net/pl3x/map/core/registry/BiomeRegistry.java +++ b/core/src/main/java/net/pl3x/map/core/registry/BiomeRegistry.java @@ -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; diff --git a/core/src/main/java/net/pl3x/map/core/registry/BlockRegistry.java b/core/src/main/java/net/pl3x/map/core/registry/BlockRegistry.java index 603a52219..f1f0ec912 100644 --- a/core/src/main/java/net/pl3x/map/core/registry/BlockRegistry.java +++ b/core/src/main/java/net/pl3x/map/core/registry/BlockRegistry.java @@ -71,6 +71,10 @@ public Map getIndexMap() { } private int getNextIndex(String id) { + if (size() > MAX_INDEX) { + return -1; + } + int index = this.indexMap.getOrDefault(id, -1); if (index > -1) { return index; diff --git a/core/src/main/java/net/pl3x/map/core/renderer/BlockInfoRenderer.java b/core/src/main/java/net/pl3x/map/core/renderer/BlockInfoRenderer.java index f9e6e24be..6a193025a 100644 --- a/core/src/main/java/net/pl3x/map/core/renderer/BlockInfoRenderer.java +++ b/core/src/main/java/net/pl3x/map/core/renderer/BlockInfoRenderer.java @@ -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; @@ -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)); } diff --git a/fabric/src/main/java/net/pl3x/map/fabric/server/FabricWorld.java b/fabric/src/main/java/net/pl3x/map/fabric/server/FabricWorld.java index f4432e5af..2987c39d3 100644 --- a/fabric/src/main/java/net/pl3x/map/fabric/server/FabricWorld.java +++ b/fabric/src/main/java/net/pl3x/map/fabric/server/FabricWorld.java @@ -67,11 +67,6 @@ public FabricWorld(@NotNull ServerLevel level, @NotNull String name) { // register biomes Set, Biome>> entries = level.registryAccess().lookupOrThrow(Registries.BIOME).entrySet(); for (Map.Entry, 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()); diff --git a/fabric/src/main/java/net/pl3x/map/fabric/server/Pl3xMapFabricServer.java b/fabric/src/main/java/net/pl3x/map/fabric/server/Pl3xMapFabricServer.java index bfacee455..66cc32201 100644 --- a/fabric/src/main/java/net/pl3x/map/fabric/server/Pl3xMapFabricServer.java +++ b/fabric/src/main/java/net/pl3x/map/fabric/server/Pl3xMapFabricServer.java @@ -230,11 +230,6 @@ public int getColorForPower(byte power) { protected void loadBlocks() { Set, Block>> entries = this.server.registryAccess().lookupOrThrow(Registries.BLOCK).entrySet(); for (Map.Entry, 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);