refactor: replace DynamicRegistry.Key with RegistryKey across Minestom components

Updated all references from `DynamicRegistry.Key` to `RegistryKey` to align with the updated Minestom API. Adjusted relevant classes, methods, and object interactions to ensure compatibility and maintain consistency. Updated `Versions.kt` to the latest Minestom version.
This commit is contained in:
Christian Bergschneider 2025-06-17 00:10:08 +02:00
parent 7f324bd72b
commit 3fe79338db
No known key found for this signature in database
GPG Key ID: 3991F97F5FA28D3E
7 changed files with 16 additions and 14 deletions

View File

@ -87,6 +87,6 @@ object Versions {
} }
object Minestom { object Minestom {
const val minestom = "1_21_5-4d91778331" const val minestom = "1_21_5-1e8b8693ac"
} }
} }

View File

@ -2,17 +2,17 @@ package com.dfsek.terra.minestom.biome;
import com.dfsek.terra.api.world.biome.PlatformBiome; import com.dfsek.terra.api.world.biome.PlatformBiome;
import net.minestom.server.registry.DynamicRegistry; import net.minestom.server.registry.RegistryKey;
import net.minestom.server.world.biome.Biome; import net.minestom.server.world.biome.Biome;
public class MinestomBiome implements PlatformBiome { public class MinestomBiome implements PlatformBiome {
private final DynamicRegistry.Key<Biome> biome; private final RegistryKey<Biome> biome;
public MinestomBiome(DynamicRegistry.Key<Biome> biome) { this.biome = biome; } public MinestomBiome(RegistryKey<Biome> biome) { this.biome = biome; }
@Override @Override
public DynamicRegistry.Key<Biome> getHandle() { public RegistryKey<Biome> getHandle() {
return biome; return biome;
} }
} }

View File

@ -8,7 +8,7 @@ import com.dfsek.tectonic.api.loader.type.TypeLoader;
import com.dfsek.terra.api.world.biome.PlatformBiome; import com.dfsek.terra.api.world.biome.PlatformBiome;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.minestom.server.registry.DynamicRegistry; import net.minestom.server.registry.RegistryKey;
import org.intellij.lang.annotations.Subst; import org.intellij.lang.annotations.Subst;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -21,6 +21,6 @@ public class MinestomBiomeLoader implements TypeLoader<PlatformBiome> {
@Subst("name:value") @Subst("name:value")
String id = (String) o; String id = (String) o;
Key key = Key.key(id); Key key = Key.key(id);
return new MinestomBiome(DynamicRegistry.Key.of(key)); return new MinestomBiome(RegistryKey.unsafeOf(key));
} }
} }

View File

@ -8,6 +8,7 @@ import net.kyori.adventure.key.Key;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.color.Color; import net.minestom.server.color.Color;
import net.minestom.server.registry.DynamicRegistry; import net.minestom.server.registry.DynamicRegistry;
import net.minestom.server.registry.RegistryKey;
import net.minestom.server.world.biome.Biome; import net.minestom.server.world.biome.Biome;
import net.minestom.server.world.biome.BiomeEffects; import net.minestom.server.world.biome.BiomeEffects;
import org.intellij.lang.annotations.Subst; import org.intellij.lang.annotations.Subst;
@ -24,7 +25,7 @@ public class MinestomUserDefinedBiomeFactory implements BiomeFactory {
@Override @Override
public UserDefinedBiome create(ConfigPack pack, com.dfsek.terra.api.world.biome.Biome source) { public UserDefinedBiome create(ConfigPack pack, com.dfsek.terra.api.world.biome.Biome source) {
VanillaBiomeProperties properties = source.getContext().get(VanillaBiomeProperties.class); VanillaBiomeProperties properties = source.getContext().get(VanillaBiomeProperties.class);
DynamicRegistry.Key<Biome> parentKey = ((MinestomBiome) source.getPlatformBiome()).getHandle(); RegistryKey<Biome> parentKey = ((MinestomBiome) source.getPlatformBiome()).getHandle();
Biome parent = mergeNullable(biomeRegistry.get(parentKey), plainsBiome); Biome parent = mergeNullable(biomeRegistry.get(parentKey), plainsBiome);
BiomeEffects parentEffects = parent.effects(); BiomeEffects parentEffects = parent.effects();
Key key = Key.key("terra", createBiomeID(pack, source.getID())); Key key = Key.key("terra", createBiomeID(pack, source.getID()));
@ -57,7 +58,7 @@ public class MinestomUserDefinedBiomeFactory implements BiomeFactory {
.effects(effectsBuilder.build()) .effects(effectsBuilder.build())
.build(); .build();
DynamicRegistry.Key<Biome> registryKey = MinecraftServer.getBiomeRegistry().register(key, target); RegistryKey<Biome> registryKey = MinecraftServer.getBiomeRegistry().register(key, target);
return new UserDefinedBiome(key, registryKey, source.getID(), target); return new UserDefinedBiome(key, registryKey, source.getID(), target);
} }

View File

@ -1,9 +1,9 @@
package com.dfsek.terra.minestom.biome; package com.dfsek.terra.minestom.biome;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.minestom.server.registry.DynamicRegistry; import net.minestom.server.registry.RegistryKey;
import net.minestom.server.world.biome.Biome; import net.minestom.server.world.biome.Biome;
public record UserDefinedBiome(Key key, DynamicRegistry.Key<Biome> registry, String id, Biome biome) { public record UserDefinedBiome(Key key, RegistryKey<Biome> registry, String id, Biome biome) {
} }

View File

@ -7,6 +7,7 @@ import net.kyori.adventure.key.Key;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.item.Material; import net.minestom.server.item.Material;
import net.minestom.server.registry.DynamicRegistry; import net.minestom.server.registry.DynamicRegistry;
import net.minestom.server.registry.RegistryKey;
import java.util.Objects; import java.util.Objects;
@ -40,7 +41,7 @@ public class MinestomEnchantment implements Enchantment {
// Get the registry key for the other enchantment to use in contains // Get the registry key for the other enchantment to use in contains
try { try {
DynamicRegistry<net.minestom.server.item.enchant.Enchantment> registry = MinecraftServer.getEnchantmentRegistry(); DynamicRegistry<net.minestom.server.item.enchant.Enchantment> registry = MinecraftServer.getEnchantmentRegistry();
DynamicRegistry.Key<net.minestom.server.item.enchant.Enchantment> otherKey = registry.getKey(otherDelegate); RegistryKey<net.minestom.server.item.enchant.Enchantment> otherKey = registry.getKey(otherDelegate);
return delegate.exclusiveSet().contains(otherKey); return delegate.exclusiveSet().contains(otherKey);
} catch (Exception e) { } catch (Exception e) {
// If the key approach fails, fall back to a more basic implementation // If the key approach fails, fall back to a more basic implementation

View File

@ -10,7 +10,7 @@ import net.minestom.server.component.DataComponents;
import net.minestom.server.item.ItemStack; import net.minestom.server.item.ItemStack;
import net.minestom.server.item.component.EnchantmentList; import net.minestom.server.item.component.EnchantmentList;
import net.minestom.server.registry.DynamicRegistry; import net.minestom.server.registry.DynamicRegistry;
import net.minestom.server.registry.DynamicRegistry.Key; import net.minestom.server.registry.RegistryKey;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.HashMap; import java.util.HashMap;
@ -59,7 +59,7 @@ public class MinestomItemStack implements com.dfsek.terra.api.inventory.ItemStac
@Override @Override
public void setItemMeta(ItemMeta meta) { public void setItemMeta(ItemMeta meta) {
HashMap<Key<net.minestom.server.item.enchant.Enchantment>, Integer> enchantments = new HashMap<>(); HashMap<RegistryKey<net.minestom.server.item.enchant.Enchantment>, Integer> enchantments = new HashMap<>();
DynamicRegistry<net.minestom.server.item.enchant.Enchantment> registry = MinecraftServer.getEnchantmentRegistry(); DynamicRegistry<net.minestom.server.item.enchant.Enchantment> registry = MinecraftServer.getEnchantmentRegistry();
meta.getEnchantments().forEach((key, value) -> { meta.getEnchantments().forEach((key, value) -> {
MinestomEnchantment enchantment = (MinestomEnchantment) key; MinestomEnchantment enchantment = (MinestomEnchantment) key;