Added biome-key-format configuration option to config.yml

This commit is contained in:
OakLoaf
2025-07-03 21:37:45 +01:00
parent 6b60246694
commit 8d8034d4e2
6 changed files with 36 additions and 12 deletions

View File

@@ -1,5 +1,6 @@
package com.dfsek.terra.bukkit.nms.v1_21_7;
import com.dfsek.terra.bukkit.PlatformImpl;
import com.dfsek.terra.bukkit.nms.v1_21_7.config.VanillaBiomeProperties;
import com.dfsek.terra.bukkit.world.BukkitBiomeInfo;
@@ -28,7 +29,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import com.dfsek.terra.bukkit.world.BukkitPlatformBiome;
import com.dfsek.terra.registry.master.ConfigRegistry;
public class AwfulBukkitHacks {
@@ -36,7 +36,7 @@ public class AwfulBukkitHacks {
private static final Map<ResourceLocation, List<ResourceLocation>> terraBiomeMap = new HashMap<>();
public static void registerBiomes(ConfigRegistry configRegistry) {
public static void registerBiomes(PlatformImpl platform) {
try {
LOGGER.info("Hacking biome registry...");
MappedRegistry<Biome> biomeRegistry = (MappedRegistry<Biome>) RegistryFetcher.biomeRegistry();
@@ -45,7 +45,7 @@ public class AwfulBukkitHacks {
Reflection.MAPPED_REGISTRY.setFrozen(biomeRegistry, false);
// Register the terra biomes to the registry
configRegistry.forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
platform.getRawConfigRegistry().forEach(pack -> pack.getRegistry(com.dfsek.terra.api.world.biome.Biome.class).forEach((key, biome) -> {
try {
BukkitPlatformBiome platformBiome = (BukkitPlatformBiome) biome.getPlatformBiome();
NamespacedKey vanillaBukkitKey = platformBiome.getHandle().getKey();
@@ -54,14 +54,13 @@ public class AwfulBukkitHacks {
VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class);
Biome platform = NMSBiomeInjector.createBiome(biomeRegistry.get(vanillaMinecraftKey).orElseThrow().value(), vanillaBiomeProperties);
ResourceLocation delegateMinecraftKey = ResourceLocation.fromNamespaceAndPath("terra", NMSBiomeInjector.createBiomeID(pack, key));
Biome nmsBiome = NMSBiomeInjector.createBiome(biomeRegistry.get(vanillaMinecraftKey).orElseThrow().value(), vanillaBiomeProperties);
ResourceLocation delegateMinecraftKey = ResourceLocation.tryParse(platform.getTerraConfig().getBiomeKey(pack, key).toString());
NamespacedKey delegateBukkitKey = NamespacedKey.fromString(delegateMinecraftKey.toString());
ResourceKey<Biome> delegateKey = ResourceKey.create(Registries.BIOME, delegateMinecraftKey);
Reference<Biome> holder = biomeRegistry.register(delegateKey, platform, RegistrationInfo.BUILT_IN);
Reflection.REFERENCE.invokeBindValue(holder, platform); // IMPORTANT: bind holder.
Reference<Biome> holder = biomeRegistry.register(delegateKey, nmsBiome, RegistrationInfo.BUILT_IN);
Reflection.REFERENCE.invokeBindValue(holder, nmsBiome); // IMPORTANT: bind holder.
platformBiome.getContext().put(new BukkitBiomeInfo(delegateBukkitKey));
platformBiome.getContext().put(new NMSBiomeInfo(delegateKey));

View File

@@ -11,7 +11,7 @@ import com.dfsek.terra.bukkit.nms.Initializer;
public class NMSInitializer implements Initializer {
@Override
public void initialize(PlatformImpl platform) {
AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry());
AwfulBukkitHacks.registerBiomes(platform);
Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin());
}