diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b1c599e..cdcd753 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,7 +1,7 @@ metadata.format.version = "1.1" [versions] -minestom = "1_20_5-d51c6c75e2" +minestom = "1_20_5-05a4bb77c3" zstd = "1.5.5-3" fastutil = "8.5.12" diff --git a/src/main/java/net/hollowcube/polar/PolarLoader.java b/src/main/java/net/hollowcube/polar/PolarLoader.java index 2b86e4f..6ccd199 100644 --- a/src/main/java/net/hollowcube/polar/PolarLoader.java +++ b/src/main/java/net/hollowcube/polar/PolarLoader.java @@ -13,8 +13,8 @@ import net.minestom.server.instance.block.Block; import net.minestom.server.instance.block.BlockManager; import net.minestom.server.network.NetworkBuffer; -import net.minestom.server.world.biomes.BiomeManager; -import net.minestom.server.world.biomes.VanillaBiome; +import net.minestom.server.registry.DynamicRegistry; +import net.minestom.server.world.biome.Biome; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,11 +39,11 @@ @SuppressWarnings("UnstableApiUsage") public class PolarLoader implements IChunkLoader { private static final BlockManager BLOCK_MANAGER = MinecraftServer.getBlockManager(); - private static final BiomeManager BIOME_MANAGER = MinecraftServer.getBiomeManager(); + private static final DynamicRegistry BIOME_REGISTRY = MinecraftServer.getBiomeRegistry(); private static final ExceptionManager EXCEPTION_HANDLER = MinecraftServer.getExceptionManager(); static final Logger logger = LoggerFactory.getLogger(PolarLoader.class); - private static final int PLAINS_BIOME_ID = BIOME_MANAGER.getId(VanillaBiome.PLAINS); + private static final int PLAINS_BIOME_ID = BIOME_REGISTRY.getId(Biome.PLAINS); private final Map biomeReadCache = new ConcurrentHashMap<>(); private final Map biomeWriteCache = new ConcurrentHashMap<>(); @@ -200,7 +200,7 @@ private void loadSection(@NotNull PolarSection sectionData, @NotNull Section sec var biomePalette = new int[rawBiomePalette.length]; for (int i = 0; i < rawBiomePalette.length; i++) { biomePalette[i] = biomeReadCache.computeIfAbsent(rawBiomePalette[i], name -> { - var biomeId = BIOME_MANAGER.getId(worldAccess.getBiome(name)); + var biomeId = BIOME_REGISTRY.getId(worldAccess.getBiome(name)); if (biomeId == -1) { logger.error("Failed to find biome: {}", name); biomeId = PLAINS_BIOME_ID; @@ -288,10 +288,10 @@ public void unloadChunk(Chunk chunk) { } private void updateChunkData(@NotNull Short2ObjectMap blockCache, @NotNull Chunk chunk) { - var dimension = chunk.getInstance().getDimensionType(); + var dimension = chunk.getInstance().getCachedDimensionType(); var blockEntities = new ArrayList(); - var sections = new PolarSection[dimension.getHeight() / Chunk.CHUNK_SECTION_SIZE]; + var sections = new PolarSection[dimension.height() / Chunk.CHUNK_SECTION_SIZE]; assert sections.length == chunk.getSections().size() : "World height mismatch"; var heightmaps = new int[PolarChunk.MAX_HEIGHTMAPS][]; diff --git a/src/main/java/net/hollowcube/polar/PolarWorldAccess.java b/src/main/java/net/hollowcube/polar/PolarWorldAccess.java index 23e20f5..3f8199e 100644 --- a/src/main/java/net/hollowcube/polar/PolarWorldAccess.java +++ b/src/main/java/net/hollowcube/polar/PolarWorldAccess.java @@ -4,13 +4,14 @@ import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Instance; import net.minestom.server.network.NetworkBuffer; -import net.minestom.server.utils.NamespaceID; -import net.minestom.server.world.biomes.Biome; -import net.minestom.server.world.biomes.VanillaBiome; +import net.minestom.server.registry.DynamicRegistry; +import net.minestom.server.world.biome.Biome; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Objects; + /** * Provides access to user world data for a {@link PolarLoader} to get and set user * specific world data such as objects, as well as provides some relevant callbacks. @@ -20,7 +21,8 @@ */ @SuppressWarnings("UnstableApiUsage") public interface PolarWorldAccess { - PolarWorldAccess DEFAULT = new PolarWorldAccess() {}; + PolarWorldAccess DEFAULT = new PolarWorldAccess() { + }; /** * Called when an instance is created from this chunk loader. @@ -30,7 +32,8 @@ public interface PolarWorldAccess { * @param instance The Minestom instance being created * @param userData The saved user data, or null if none is present. */ - default void loadWorldData(@NotNull Instance instance, @Nullable NetworkBuffer userData) {} + default void loadWorldData(@NotNull Instance instance, @Nullable NetworkBuffer userData) { + } /** * Called when an instance is being saved. @@ -40,33 +43,38 @@ default void loadWorldData(@NotNull Instance instance, @Nullable NetworkBuffer u * @param instance The Minestom instance being saved * @param userData A buffer to write user data to save */ - default void saveWorldData(@NotNull Instance instance, @NotNull NetworkBuffer userData) {} + default void saveWorldData(@NotNull Instance instance, @NotNull NetworkBuffer userData) { + } /** * Called when a chunk is created, just before it is added to the world. *

* Can be used to initialize the chunk based on saved user data in the world. * - * @param chunk The Minestom chunk being created + * @param chunk The Minestom chunk being created * @param userData The saved user data, or null if none is present */ - default void loadChunkData(@NotNull Chunk chunk, @Nullable NetworkBuffer userData) {} + default void loadChunkData(@NotNull Chunk chunk, @Nullable NetworkBuffer userData) { + } /** * Called when a chunk is being saved. *

* Can be used to save user data in the chunk by writing it to the buffer. * - * @param chunk The Minestom chunk being saved + * @param chunk The Minestom chunk being saved * @param userData A buffer to write user data to save */ - default void saveChunkData(@NotNull Chunk chunk, @NotNull NetworkBuffer userData) {} + default void saveChunkData(@NotNull Chunk chunk, @NotNull NetworkBuffer userData) { + } @ApiStatus.Experimental - default void loadHeightmaps(@NotNull Chunk chunk, int[][] heightmaps) {} + default void loadHeightmaps(@NotNull Chunk chunk, int[][] heightmaps) { + } @ApiStatus.Experimental - default void saveHeightmaps(@NotNull Chunk chunk, int[][] heightmaps) {} + default void saveHeightmaps(@NotNull Chunk chunk, int[][] heightmaps) { + } /** * Called when a chunk is being loaded by a {@link PolarLoader} to convert biome ids back to instances. @@ -78,20 +86,23 @@ default void saveHeightmaps(@NotNull Chunk chunk, int[][] heightmaps) {} * @param name The namespace ID of the biome, eg minecraft:plains * @return The biome instance */ - default @NotNull Biome getBiome(@NotNull String name) { - var biome = MinecraftServer.getBiomeManager().getByName(NamespaceID.from(name)); + default @NotNull DynamicRegistry.Key getBiome(@NotNull String name) { + var biomeRegistry = MinecraftServer.getBiomeRegistry(); + var key = DynamicRegistry.Key.of(name); + var biome = biomeRegistry.get(key); if (biome == null) { PolarLoader.logger.error("Failed to find biome: {}", name); - biome = VanillaBiome.PLAINS; + return Biome.PLAINS; } - return biome; + return key; } default @NotNull String getBiomeName(int id) { - var biome = MinecraftServer.getBiomeManager().getById(id); + var biomeRegistry = MinecraftServer.getBiomeRegistry(); + var biome = biomeRegistry.getKey(id); if (biome == null) { PolarLoader.logger.error("Failed to find biome: {}", id); - biome = VanillaBiome.PLAINS; + return Objects.requireNonNull(biomeRegistry.get(Biome.PLAINS)).name(); } return biome.name(); }