9
0
mirror of https://github.com/HibiscusMC/HibiscusCommons.git synced 2025-12-19 15:09:26 +00:00

chore: use new paper registry on recent versions for enchantments

This commit is contained in:
LoJoSho
2025-03-24 15:45:39 -05:00
parent 75c3d4b19a
commit c9ed39b525

View File

@@ -1,5 +1,7 @@
package me.lojosho.hibiscuscommons.config.serializer; package me.lojosho.hibiscuscommons.config.serializer;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin; import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
import me.lojosho.hibiscuscommons.hooks.Hooks; import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.MinecraftVersion; import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
@@ -129,7 +131,13 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
for (ConfigurationNode enchantNode : enchantsNode.childrenMap().values()) { for (ConfigurationNode enchantNode : enchantsNode.childrenMap().values()) {
String enchantName = enchantNode.key().toString().toLowerCase(); String enchantName = enchantNode.key().toString().toLowerCase();
NamespacedKey key = NamespacedKey.minecraft(enchantName); NamespacedKey key = NamespacedKey.minecraft(enchantName);
Enchantment enchant = Registry.ENCHANTMENT.get(key); Enchantment enchant = null;
if (HibiscusCommonsPlugin.isOnPaper() && NMSHandlers.getVersion().isHigherOrEqual(MinecraftVersion.v1_21_4)) {
enchant = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).get(key);
} else {
enchant = Registry.ENCHANTMENT.get(key);
}
if (enchant == null) continue; if (enchant == null) continue;
itemMeta.addEnchant(enchant, enchantNode.getInt(1), true); itemMeta.addEnchant(enchant, enchantNode.getInt(1), true);
} }