Guard potion and enchantment registry

This commit is contained in:
IzzelAliz 2021-03-07 13:28:21 +08:00
parent 79637420b8
commit e2f496eb7c
2 changed files with 19 additions and 10 deletions

View File

@ -208,10 +208,14 @@ public class BukkitRegistry {
int size = ForgeRegistries.ENCHANTMENTS.getEntries().size(); int size = ForgeRegistries.ENCHANTMENTS.getEntries().size();
putBool(Enchantment.class, "acceptingNew", true); putBool(Enchantment.class, "acceptingNew", true);
for (net.minecraft.enchantment.Enchantment enc : ForgeRegistries.ENCHANTMENTS) { for (net.minecraft.enchantment.Enchantment enc : ForgeRegistries.ENCHANTMENTS) {
try {
String name = ResourceLocationUtil.standardize(enc.getRegistryName()); String name = ResourceLocationUtil.standardize(enc.getRegistryName());
ArclightEnchantment enchantment = new ArclightEnchantment(enc, name); ArclightEnchantment enchantment = new ArclightEnchantment(enc, name);
Enchantment.registerEnchantment(enchantment); Enchantment.registerEnchantment(enchantment);
ArclightMod.LOGGER.debug("Registered {} as enchantment {}", enc.getRegistryName(), 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(); Enchantment.stopAcceptingRegistrations();
ArclightMod.LOGGER.info("registry.enchantment", size - origin); ArclightMod.LOGGER.info("registry.enchantment", size - origin);
@ -220,14 +224,19 @@ public class BukkitRegistry {
private static void loadPotions() { private static void loadPotions() {
int origin = PotionEffectType.values().length; int origin = PotionEffectType.values().length;
int size = ForgeRegistries.POTIONS.getEntries().size(); 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); putStatic(PotionEffectType.class, "byId", types);
putBool(PotionEffectType.class, "acceptingNew", true); putBool(PotionEffectType.class, "acceptingNew", true);
for (Effect eff : ForgeRegistries.POTIONS) { for (Effect eff : ForgeRegistries.POTIONS) {
try {
String name = ResourceLocationUtil.standardize(eff.getRegistryName()); String name = ResourceLocationUtil.standardize(eff.getRegistryName());
ArclightPotionEffect effect = new ArclightPotionEffect(eff, name); ArclightPotionEffect effect = new ArclightPotionEffect(eff, name);
PotionEffectType.registerPotionEffectType(effect); PotionEffectType.registerPotionEffectType(effect);
ArclightMod.LOGGER.debug("Registered {} as potion {}", eff.getRegistryName(), 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(); PotionEffectType.stopAcceptingRegistrations();
ArclightMod.LOGGER.info("registry.potion", size - origin); ArclightMod.LOGGER.info("registry.potion", size - origin);

View File

@ -1,6 +1,6 @@
allprojects { allprojects {
group 'io.izzel.arclight' group 'io.izzel.arclight'
version '1.0.15' version '1.0.16-SNAPSHOT'
ext { ext {
agpVersion = '1.14' agpVersion = '1.14'