From e2f496eb7c483f2fcfbe787f364277c388395df5 Mon Sep 17 00:00:00 2001 From: IzzelAliz Date: Sun, 7 Mar 2021 13:28:21 +0800 Subject: [PATCH] Guard potion and enchantment registry --- .../common/mod/server/BukkitRegistry.java | 27 ++++++++++++------- build.gradle | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java index 0cf8fe34..478488a8 100644 --- a/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java +++ b/arclight-common/src/main/java/io/izzel/arclight/common/mod/server/BukkitRegistry.java @@ -208,10 +208,14 @@ public class BukkitRegistry { int size = ForgeRegistries.ENCHANTMENTS.getEntries().size(); putBool(Enchantment.class, "acceptingNew", true); for (net.minecraft.enchantment.Enchantment enc : ForgeRegistries.ENCHANTMENTS) { - String name = ResourceLocationUtil.standardize(enc.getRegistryName()); - ArclightEnchantment enchantment = new ArclightEnchantment(enc, name); - Enchantment.registerEnchantment(enchantment); - ArclightMod.LOGGER.debug("Registered {} as enchantment {}", enc.getRegistryName(), enchantment); + try { + String name = ResourceLocationUtil.standardize(enc.getRegistryName()); + ArclightEnchantment enchantment = new ArclightEnchantment(enc, name); + Enchantment.registerEnchantment(enchantment); + ArclightMod.LOGGER.debug("Registered {} as enchantment {}", enc.getRegistryName(), enchantment); + } catch (Exception e) { + ArclightMod.LOGGER.error("Failed to register enchantment {}: {}", enc.getRegistryName(), e); + } } Enchantment.stopAcceptingRegistrations(); ArclightMod.LOGGER.info("registry.enchantment", size - origin); @@ -220,14 +224,19 @@ public class BukkitRegistry { private static void loadPotions() { int origin = PotionEffectType.values().length; int size = ForgeRegistries.POTIONS.getEntries().size(); - PotionEffectType[] types = new PotionEffectType[size + 1]; + int maxId = ForgeRegistries.POTIONS.getValues().stream().mapToInt(Effect::getId).max().orElse(0); + PotionEffectType[] types = new PotionEffectType[maxId + 1]; putStatic(PotionEffectType.class, "byId", types); putBool(PotionEffectType.class, "acceptingNew", true); for (Effect eff : ForgeRegistries.POTIONS) { - String name = ResourceLocationUtil.standardize(eff.getRegistryName()); - ArclightPotionEffect effect = new ArclightPotionEffect(eff, name); - PotionEffectType.registerPotionEffectType(effect); - ArclightMod.LOGGER.debug("Registered {} as potion {}", eff.getRegistryName(), effect); + try { + String name = ResourceLocationUtil.standardize(eff.getRegistryName()); + ArclightPotionEffect effect = new ArclightPotionEffect(eff, name); + PotionEffectType.registerPotionEffectType(effect); + ArclightMod.LOGGER.debug("Registered {} as potion {}", eff.getRegistryName(), effect); + } catch (Exception e) { + ArclightMod.LOGGER.error("Failed to register potion type {}: {}", eff.getRegistryName(), e); + } } PotionEffectType.stopAcceptingRegistrations(); ArclightMod.LOGGER.info("registry.potion", size - origin); diff --git a/build.gradle b/build.gradle index 5a6d91ee..ffeca3d7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ allprojects { group 'io.izzel.arclight' - version '1.0.15' + version '1.0.16-SNAPSHOT' ext { agpVersion = '1.14'