From df17edfe96716beac88621f2b2ec06dca9d4b67a Mon Sep 17 00:00:00 2001 From: Caltinor <62700786+Caltinor@users.noreply.github.com> Date: Wed, 4 Dec 2024 07:53:12 -0500 Subject: [PATCH] 1.19 scripting backport pre-test --- .../java/harmonised/pmmo/api/APIUtils.java | 63 +++++++------------ .../pmmo/config/codecs/LocationData.java | 2 +- .../pmmo/config/codecs/ObjectData.java | 11 +++- .../pmmo/config/readers/CoreLoader.java | 16 +++-- .../config/readers/ExecutableListener.java | 9 ++- .../readers/MergeableCodecDataManager.java | 3 +- .../pmmo/config/scripting/Expression.java | 13 ++-- .../pmmo/config/scripting/Functions.java | 43 +++---------- .../harmonised/pmmo/setup/CommonSetup.java | 7 ++- 9 files changed, 69 insertions(+), 98 deletions(-) diff --git a/src/main/java/harmonised/pmmo/api/APIUtils.java b/src/main/java/harmonised/pmmo/api/APIUtils.java index 1ba3939a..5f9ff1d5 100644 --- a/src/main/java/harmonised/pmmo/api/APIUtils.java +++ b/src/main/java/harmonised/pmmo/api/APIUtils.java @@ -16,6 +16,8 @@ import harmonised.pmmo.config.codecs.*; import harmonised.pmmo.core.CoreUtils; import harmonised.pmmo.core.IDataStorage; +import net.minecraftforge.common.util.TriPredicate; +import org.apache.commons.lang3.function.TriFunction; import org.checkerframework.checker.nullness.qual.NonNull; import com.google.common.base.Preconditions; @@ -25,7 +27,6 @@ import harmonised.pmmo.api.enums.ObjectType; import harmonised.pmmo.api.enums.PerkSide; import harmonised.pmmo.api.enums.ReqType; -import harmonised.pmmo.api.perks.Perk; import harmonised.pmmo.config.codecs.CodecTypes.SalvageData; import harmonised.pmmo.core.Core; import harmonised.pmmo.util.MsLoggy; @@ -60,7 +61,7 @@ public class APIUtils { public static int getLevel(String skill, Player player) { Preconditions.checkNotNull(skill); Preconditions.checkNotNull(player); - return Core.get(player.level()).getData().getPlayerSkillLevel(skill, player.getUUID()); + return Core.get(player.getLevel()).getData().getPlayerSkillLevel(skill, player.getUUID()); } /**Sets the player's current level in the skill provided @@ -72,7 +73,7 @@ public static int getLevel(String skill, Player player) { public static void setLevel(String skill, Player player, int level) { Preconditions.checkNotNull(skill); Preconditions.checkNotNull(player); - Core.get(player.level()).getData().setPlayerSkillLevel(skill, player.getUUID(), level); + Core.get(player.getLevel()).getData().setPlayerSkillLevel(skill, player.getUUID(), level); } /**changes the player's level in the specified skill by a specific amount. @@ -87,7 +88,7 @@ public static void setLevel(String skill, Player player, int level) { public static boolean addLevel(String skill, Player player, int levelChange) { Preconditions.checkNotNull(skill); Preconditions.checkNotNull(player); - return Core.get(player.level()).getData().changePlayerSkillLevel(skill, player.getUUID(), levelChange); + return Core.get(player.getLevel()).getData().changePlayerSkillLevel(skill, player.getUUID(), levelChange); } /**Gets the raw xp value associated with the specified skill and player. @@ -99,7 +100,7 @@ public static boolean addLevel(String skill, Player player, int levelChange) { public static long getXp(String skill, Player player) { Preconditions.checkNotNull(skill); Preconditions.checkNotNull(player); - return Core.get(player.level()).getData().getXpRaw(player.getUUID(), skill); + return Core.get(player.getLevel()).getData().getXpRaw(player.getUUID(), skill); } /**Sets the raw XP value for the player in the skill specified. @@ -111,7 +112,7 @@ public static long getXp(String skill, Player player) { public static void setXp(String skill, Player player, long xpRaw) { Preconditions.checkNotNull(skill); Preconditions.checkNotNull(player); - Core.get(player.level()).getData().setXpRaw(player.getUUID(), skill, xpRaw); + Core.get(player.getLevel()).getData().setXpRaw(player.getUUID(), skill, xpRaw); } /**Changes the player's current experience in the specified skill by the amount. @@ -127,7 +128,7 @@ public static void setXp(String skill, Player player, long xpRaw) { public static boolean addXp(String skill, Player player, long change) { Preconditions.checkNotNull(skill); Preconditions.checkNotNull(player); - IDataStorage data = Core.get(player.level()).getData(); + IDataStorage data = Core.get(player.getLevel()).getData(); return CoreUtils.processSkillGroupXP(Map.of(skill, change)).entrySet().stream() .allMatch(entry -> data.setXpDiff(player.getUUID(), entry.getKey(), entry.getValue())); } @@ -139,7 +140,7 @@ public static boolean addXp(String skill, Player player, long change) { * @return a map of skills and raw xp */ public static Map getRawXpMap(Player player) { - return Core.get(player.level()).getData().getXpMap(player.getUUID()); + return Core.get(player.getLevel()).getData().getXpMap(player.getUUID()); } /**Returns the player's entire skill map. @@ -148,7 +149,7 @@ public static Map getRawXpMap(Player player) { * @return a map of skills and levels */ public static Map getAllLevels(Player player) { - IDataStorage data = Core.get(player.level()).getData(); + IDataStorage data = Core.get(player.getLevel()).getData(); return getRawXpMap(player).entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> data.getLevelFromXP(e.getValue()))); } @@ -257,7 +258,7 @@ public static Map getRequirementMap(ItemStack item, ReqType typ Preconditions.checkNotNull(item); Preconditions.checkNotNull(type); Preconditions.checkNotNull(side); - return Core.get(side).getReqMap(type, item, true); + return Core.get(side).getReqMap(type, item); } /**Returns a skill-level map for the requirements of the block and the requirement type passed. @@ -349,25 +350,6 @@ public static void registerXpAward(ObjectType oType, ResourceLocation objectID, raw.setXpValues(type, award); registerConfiguration(asOverride, oType, objectID, raw); } - - /**Registers a configuration for an entity or item for damage dealt - * and received xp events. Note: passing other object types into - * this method will be ignored, and have no effect. - * - * @param oType use only ITEM or ENTITY - * @param objectID the key for the object being configured - * @param isDealt is Dealt Damage config else if false will be received damage - * @param damageType the id or tag string for damage type - * @param award a map of skills and experience values to be awarded - * @param asOverride should this apply after datapacks as an override - */ - public static void registerDamageXpAward(ObjectType oType, ResourceLocation objectID, boolean isDealt, String damageType, Map award, boolean asOverride) { - if (oType == ObjectType.ENTITY || oType == ObjectType.ITEM) { - ObjectData raw = new ObjectData(asOverride); - raw.damageXpValues().put(isDealt ? EventType.DEAL_DAMAGE : EventType.RECEIVE_DAMAGE, Map.of(damageType, award)); - registerConfiguration(asOverride, oType, objectID, raw); - } - } /**registers a configuration setting for bonuses to xp gains. * * @param objectID the object linked to the bonus @@ -449,8 +431,7 @@ public static void registerVeinData(ObjectType oType, ResourceLocation objectID, return; VeinData data = new VeinData(chargeCap, chargeRate, consumeAmount); ObjectData raw = new ObjectData(asOverride, Set.of(), new HashMap<>(), new HashMap<>(), new HashMap<>(), - new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), - new HashMap<>(), data); + new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), data); registerConfiguration(asOverride, oType, objectID, raw); } @@ -463,7 +444,7 @@ public static void registerVeinData(ObjectType oType, ResourceLocation objectID, * @param mob_modifiers a map of mob keys with a value map of attribute types and values * @param asOverride should this apply after datapacks as an override */ - public static void registerMobModifier(ObjectType oType, ResourceLocation locationID, Map> mob_modifiers, boolean asOverride) { + public static void registerMobModifier(ObjectType oType, ResourceLocation locationID, Map> mob_modifiers, boolean asOverride) { if (oType != ObjectType.BIOME && oType != ObjectType.DIMENSION) return; LocationData raw = new LocationData(asOverride); @@ -800,17 +781,17 @@ public static void registerListener( */ public static void registerPerk( @NonNull ResourceLocation perkID, - @NonNull Perk perk, + @NonNull CompoundTag propertyDefaults, + @NonNull TriPredicate customConditions, + @NonNull TriFunction onExecute, + @NonNull TriFunction onConclude, @NonNull PerkSide side) { - switch (side) { - case SERVER -> { - Core.get(LogicalSide.SERVER).getPerkRegistry().registerPerk(perkID, perk); - Core.get(LogicalSide.CLIENT).getPerkRegistry().registerClientClone(perkID, perk);} - case CLIENT -> Core.get(LogicalSide.CLIENT).getPerkRegistry().registerPerk(perkID, perk); - case BOTH -> { - Core.get(LogicalSide.SERVER).getPerkRegistry().registerPerk(perkID, perk); - Core.get(LogicalSide.CLIENT).getPerkRegistry().registerPerk(perkID, perk);} + if (side.equals(PerkSide.SERVER) || side.equals(PerkSide.BOTH)) { + Core.get(LogicalSide.SERVER).getPerkRegistry().registerPerk(perkID, propertyDefaults, customConditions, onExecute, onConclude); + Core.get(LogicalSide.CLIENT).getPerkRegistry().registerProperties(perkID, propertyDefaults); } + if (side.equals(PerkSide.CLIENT) || side.equals(PerkSide.BOTH)) + Core.get(LogicalSide.CLIENT).getPerkRegistry().registerPerk(perkID, propertyDefaults, customConditions, onExecute, onConclude); } //===============UTILITY METHODS================================= diff --git a/src/main/java/harmonised/pmmo/config/codecs/LocationData.java b/src/main/java/harmonised/pmmo/config/codecs/LocationData.java index d07ab637..2e3a9fc4 100644 --- a/src/main/java/harmonised/pmmo/config/codecs/LocationData.java +++ b/src/main/java/harmonised/pmmo/config/codecs/LocationData.java @@ -31,7 +31,7 @@ public record LocationData( public LocationData(boolean override) { this(override, new HashSet<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), - new ArrayList<>(), new HashMap<>(), new ArrayList<>(), new HashMap<>()); + new ArrayList<>(), new HashMap<>(), new HashMap<>()); } public LocationData() {this( false, new HashSet<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), diff --git a/src/main/java/harmonised/pmmo/config/codecs/ObjectData.java b/src/main/java/harmonised/pmmo/config/codecs/ObjectData.java index d7e121a8..b661469c 100644 --- a/src/main/java/harmonised/pmmo/config/codecs/ObjectData.java +++ b/src/main/java/harmonised/pmmo/config/codecs/ObjectData.java @@ -39,7 +39,11 @@ public record ObjectData( Map> nbtBonuses, Map salvage, VeinData veinData) implements DataSource{ - + + public ObjectData(boolean override) {this( + override, new HashSet<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), + new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), VeinData.EMPTY + );} public ObjectData() { this(false, new HashSet<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), VeinData.EMPTY); @@ -91,6 +95,11 @@ public void setNegativeEffects(Map neg) { } @Override public Set getTagValues() {return tagValues();} + + public void salvagePutAll(Map collect) { + salvage().putAll(collect); + } + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Codec.BOOL.optionalFieldOf("override").forGetter(od -> Optional.of(od.override())), Codec.STRING.listOf().optionalFieldOf("isTagFor").forGetter(od -> Optional.of(new ArrayList<>(od.tagValues))), diff --git a/src/main/java/harmonised/pmmo/config/readers/CoreLoader.java b/src/main/java/harmonised/pmmo/config/readers/CoreLoader.java index 1a55d01e..d1869771 100644 --- a/src/main/java/harmonised/pmmo/config/readers/CoreLoader.java +++ b/src/main/java/harmonised/pmmo/config/readers/CoreLoader.java @@ -6,8 +6,6 @@ import harmonised.pmmo.config.scripting.Scripting; import net.minecraft.core.RegistryAccess; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.core.registries.Registries; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import harmonised.pmmo.api.enums.ModifierDataType; @@ -106,21 +104,21 @@ public void resetData() { } public final MergeableCodecDataManager ITEM_LOADER = new MergeableCodecDataManager<>( - "pmmo/items", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, Registries.ITEM); + "pmmo/items", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, ForgeRegistries.ITEMS); public final MergeableCodecDataManager BLOCK_LOADER = new MergeableCodecDataManager<>( - "pmmo/blocks", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, Registries.BLOCK); + "pmmo/blocks", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, ForgeRegistries.BLOCKS); public final MergeableCodecDataManager> ENTITY_LOADER = new MergeableCodecDataManager<>( - "pmmo/entities", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, Registries.ENTITY_TYPE); + "pmmo/entities", DATA_LOGGER, ObjectData.CODEC, this::mergeLoaderData, this::printData, ObjectData::new, ForgeRegistries.ENTITY_TYPES); public final MergeableCodecDataManager BIOME_LOADER = new MergeableCodecDataManager<>( - "pmmo/biomes", DATA_LOGGER, LocationData.CODEC, this::mergeLoaderData, this::printData, LocationData::new, Registries.BIOME); + "pmmo/biomes", DATA_LOGGER, LocationData.CODEC, this::mergeLoaderData, this::printData, LocationData::new, ForgeRegistries.BIOMES); public final MergeableCodecDataManager DIMENSION_LOADER = new MergeableCodecDataManager<>( - "pmmo/dimensions", DATA_LOGGER, LocationData.CODEC, this::mergeLoaderData, this::printData, LocationData::new, Registries.DIMENSION); + "pmmo/dimensions", DATA_LOGGER, LocationData.CODEC, this::mergeLoaderData, this::printData, LocationData::new, null); public final MergeableCodecDataManager PLAYER_LOADER = new MergeableCodecDataManager<>( "pmmo/players", DATA_LOGGER, PlayerData.CODEC, this::mergeLoaderData, this::printData, PlayerData::new, null); public final MergeableCodecDataManager ENCHANTMENT_LOADER = new MergeableCodecDataManager<>( - "pmmo/enchantments", DATA_LOGGER, EnhancementsData.CODEC, this::mergeLoaderData, this::printData, EnhancementsData::new, Registries.ENCHANTMENT); + "pmmo/enchantments", DATA_LOGGER, EnhancementsData.CODEC, this::mergeLoaderData, this::printData, EnhancementsData::new, ForgeRegistries.ENCHANTMENTS); public final MergeableCodecDataManager EFFECT_LOADER = new MergeableCodecDataManager<>( - "pmmo/effects", DATA_LOGGER, EnhancementsData.CODEC, this::mergeLoaderData, this::printData, EnhancementsData::new, Registries.MOB_EFFECT); + "pmmo/effects", DATA_LOGGER, EnhancementsData.CODEC, this::mergeLoaderData, this::printData, EnhancementsData::new, ForgeRegistries.MOB_EFFECTS); private > T mergeLoaderData(final List raws) { diff --git a/src/main/java/harmonised/pmmo/config/readers/ExecutableListener.java b/src/main/java/harmonised/pmmo/config/readers/ExecutableListener.java index adaaf053..f120a1cc 100644 --- a/src/main/java/harmonised/pmmo/config/readers/ExecutableListener.java +++ b/src/main/java/harmonised/pmmo/config/readers/ExecutableListener.java @@ -4,6 +4,7 @@ import java.util.function.Supplier; import net.minecraft.core.RegistryAccess; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.SimplePreparableReloadListener; @@ -16,9 +17,9 @@ public class ExecutableListener extends SimplePreparableReloadListener { private final Consumer executor; - private final RegistryAccess access; + private final Supplier access; - public ExecutableListener(RegistryAccess access, Consumer executor) { + public ExecutableListener(Supplier access, Consumer executor) { this.access = access; this.executor = executor; } @@ -28,7 +29,9 @@ public ExecutableListener(RegistryAccess access, Consumer execut @Override protected void apply(Boolean pObject, ResourceManager pResourceManager, ProfilerFiller pProfiler) { - executor.accept(access); + var regAccess = access.get(); + if (regAccess != null) + executor.accept(regAccess); } /** diff --git a/src/main/java/harmonised/pmmo/config/readers/MergeableCodecDataManager.java b/src/main/java/harmonised/pmmo/config/readers/MergeableCodecDataManager.java index 15ebc38d..3e56ac19 100644 --- a/src/main/java/harmonised/pmmo/config/readers/MergeableCodecDataManager.java +++ b/src/main/java/harmonised/pmmo/config/readers/MergeableCodecDataManager.java @@ -38,6 +38,7 @@ of this software and associated documentation files (the "Software"), to deal import javax.annotation.Nonnull; +import net.minecraft.core.RegistryAccess; import org.apache.logging.log4j.Logger; import com.google.gson.Gson; @@ -273,7 +274,7 @@ protected void apply(final Map processedData, final Resourc } @SuppressWarnings("unchecked") - public void postProcess() { + public void postProcess(RegistryAccess access) { MsLoggy.DEBUG.log(LOG_CODE.DATA, "Begin PostProcessing for {}", folderName); for (Map.Entry dataRaw : new HashMap<>(this.data).entrySet()) { DataSource dataValue = dataRaw.getValue(); diff --git a/src/main/java/harmonised/pmmo/config/scripting/Expression.java b/src/main/java/harmonised/pmmo/config/scripting/Expression.java index 7aeb6660..b0688b03 100644 --- a/src/main/java/harmonised/pmmo/config/scripting/Expression.java +++ b/src/main/java/harmonised/pmmo/config/scripting/Expression.java @@ -2,13 +2,12 @@ import harmonised.pmmo.api.enums.ObjectType; import harmonised.pmmo.util.MsLoggy; -import harmonised.pmmo.util.Reference; import net.minecraft.core.Registry; import net.minecraft.core.RegistryAccess; -import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; +import net.minecraftforge.registries.ForgeRegistries; import java.util.ArrayList; import java.util.HashMap; @@ -79,11 +78,11 @@ else if (str.endsWith(":*")) { private static List getMembers(boolean isTag, ResourceLocation tagID, RegistryAccess access, ObjectType type) { return switch (type) { - case ITEM -> readRegistry(isTag, access, Registries.ITEM, tagID); - case BLOCK -> readRegistry(isTag, access, Registries.BLOCK, tagID); - case ENTITY -> readRegistry(isTag, access, Registries.ENTITY_TYPE, tagID); - case BIOME -> readRegistry(isTag, access, Registries.BIOME, tagID); - case ENCHANTMENT -> readRegistry(isTag, access, Registries.ENCHANTMENT, tagID); + case ITEM -> readRegistry(isTag, access, ForgeRegistries.ITEMS.getRegistryKey(), tagID); + case BLOCK -> readRegistry(isTag, access, ForgeRegistries.BLOCKS.getRegistryKey(), tagID); + case ENTITY -> readRegistry(isTag, access, ForgeRegistries.ENTITY_TYPES.getRegistryKey(), tagID); + case BIOME -> readRegistry(isTag, access, ForgeRegistries.BIOMES.getRegistryKey(), tagID); + case ENCHANTMENT -> readRegistry(isTag, access, ForgeRegistries.ENCHANTMENTS.getRegistryKey(), tagID); default -> List.of(); }; } diff --git a/src/main/java/harmonised/pmmo/config/scripting/Functions.java b/src/main/java/harmonised/pmmo/config/scripting/Functions.java index bae251b7..961e6919 100644 --- a/src/main/java/harmonised/pmmo/config/scripting/Functions.java +++ b/src/main/java/harmonised/pmmo/config/scripting/Functions.java @@ -7,12 +7,9 @@ import harmonised.pmmo.api.enums.ObjectType; import harmonised.pmmo.api.enums.ReqType; import harmonised.pmmo.config.codecs.DataSource; -import harmonised.pmmo.config.codecs.MobModifier; import harmonised.pmmo.config.codecs.ObjectData; import harmonised.pmmo.config.codecs.VeinData; import harmonised.pmmo.core.Core; -import harmonised.pmmo.util.Reference; -import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.TagKey; import net.minecraft.world.entity.EquipmentSlot; @@ -24,6 +21,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TieredItem; import net.minecraftforge.fml.LogicalSide; +import net.minecraftforge.registries.ForgeRegistries; import java.util.ArrayList; import java.util.HashMap; @@ -47,16 +45,6 @@ public class Functions { if (award.isEmpty()) return; APIUtils.registerXpAward(type, id, event, award, true); }); - KEYWORDS.put("deal_damage", (param, id, type, value) -> { - Map award = mapValue(value.getOrDefault("award", "")); - if (award.isEmpty()) return; - APIUtils.registerXpAward(type, id, EventType.DEAL_DAMAGE, award, true); - }); - KEYWORDS.put("receive_damage", (param, id, type, value) -> { - Map award = mapValue(value.getOrDefault("award", "")); - if (award.isEmpty()) return; - APIUtils.registerXpAward(type, id, EventType.RECEIVE_DAMAGE, award, true); - }); KEYWORDS.put("req", (param, id, type, value) -> { ReqType reqType = ReqType.byName(param.toUpperCase()); if (reqType == null) return; @@ -94,7 +82,7 @@ public class Functions { }); KEYWORDS.put("mob_scale", (param, id, type, value) -> { ResourceLocation entityID = new ResourceLocation(param); - List modifiers = modifiers(value.getOrDefault("attribute", "")); + Map modifiers = doubleMap(value.getOrDefault("attribute", "")); APIUtils.registerMobModifier(type, id, Map.of(entityID, modifiers), true); }); KEYWORDS.put("positive_effect", (param, id, type, value) -> { @@ -156,7 +144,7 @@ else if (str.startsWith("saturation")) { } final Pair values = Pair.of(nutVal, satVal); final Pair ops = Pair.of(nutOp, satOp); - List food = access.registryOrThrow(Registries.ITEM).entrySet().stream() + List food = access.registryOrThrow(ForgeRegistries.ITEMS.getRegistryKey()).entrySet().stream() .filter(entry -> { FoodProperties props = entry.getValue().getFoodProperties(entry.getValue().getDefaultInstance(), null); return props != null @@ -169,13 +157,13 @@ else if (str.startsWith("saturation")) { TARGETORS.put("tool", (param, access) -> { List tools = new ArrayList<>(); if (param.isEmpty()) - tools.addAll(access.registryOrThrow(Registries.ITEM).entrySet().stream() + tools.addAll(access.registryOrThrow(ForgeRegistries.ITEMS.getRegistryKey()).entrySet().stream() .filter(entry -> entry.getValue() instanceof TieredItem) .map(entry -> entry.getKey().location()) .toList()); else { ResourceLocation tag = new ResourceLocation(param); - tools.addAll(access.registryOrThrow(Registries.ITEM).getTag(TagKey.create(Registries.ITEM, tag)) + tools.addAll(access.registryOrThrow(ForgeRegistries.ITEMS.getRegistryKey()).getTag(TagKey.create(ForgeRegistries.ITEMS.getRegistryKey(), tag)) .map(named -> named.stream() .filter(holder -> holder.value() instanceof TieredItem) .map(holder -> holder.unwrapKey().get().location()).toList()) @@ -186,13 +174,13 @@ else if (str.startsWith("saturation")) { TARGETORS.put("armor", (param, access) -> { List tools = new ArrayList<>(); if (param.isEmpty()) - tools.addAll(access.registryOrThrow(Registries.ITEM).entrySet().stream() + tools.addAll(access.registryOrThrow(ForgeRegistries.ITEMS.getRegistryKey()).entrySet().stream() .filter(entry -> entry.getValue() instanceof ArmorItem) .map(entry -> entry.getKey().location()) .toList()); else { ResourceLocation tag = new ResourceLocation(param); - tools.addAll(access.registryOrThrow(Registries.ITEM).getTag(TagKey.create(Registries.ITEM, tag)) + tools.addAll(access.registryOrThrow(ForgeRegistries.ITEMS.getRegistryKey()).getTag(TagKey.create(ForgeRegistries.ITEMS.getRegistryKey(), tag)) .map(named -> named.stream() .filter(holder -> holder.value() instanceof ArmorItem) .map(holder -> holder.unwrapKey().get().location()).toList()) @@ -203,13 +191,13 @@ else if (str.startsWith("saturation")) { TARGETORS.put("weapon", (param, access) -> { List tools = new ArrayList<>(); if (param.isEmpty()) - tools.addAll(access.registryOrThrow(Registries.ITEM).entrySet().stream() + tools.addAll(access.registryOrThrow(ForgeRegistries.ITEMS.getRegistryKey()).entrySet().stream() .filter(entry -> entry.getValue().getAttributeModifiers(EquipmentSlot.MAINHAND, entry.getValue().getDefaultInstance()).containsKey(Attributes.ATTACK_DAMAGE)) .map(entry -> entry.getKey().location()) .toList()); else { ResourceLocation tag = new ResourceLocation(param); - tools.addAll(access.registryOrThrow(Registries.ITEM).getTag(TagKey.create(Registries.ITEM, tag)) + tools.addAll(access.registryOrThrow(ForgeRegistries.ITEMS.getRegistryKey()).getTag(TagKey.create(ForgeRegistries.ITEMS.getRegistryKey(), tag)) .map(named -> named.stream() .filter(holder -> holder.value().getAttributeModifiers(EquipmentSlot.MAINHAND, holder.value().getDefaultInstance()).containsKey(Attributes.ATTACK_DAMAGE)) .map(holder -> holder.unwrapKey().get().location()).toList()) @@ -268,17 +256,4 @@ private static Map doubleMap(String value) { } return outMap; } - - private static List modifiers(String value) { - List output = new ArrayList<>(); - String[] elements = value.replaceAll("\\)", "").split(","); - if (elements.length % 3 != 0) return output; - for (int i = 0; i <= elements.length-3; i += 3) { - output.add(new MobModifier( - new ResourceLocation(elements[i]), - Double.valueOf(elements[i+1]), - AttributeModifier.Operation.valueOf(elements[i+2]))); - } - return output; - } } diff --git a/src/main/java/harmonised/pmmo/setup/CommonSetup.java b/src/main/java/harmonised/pmmo/setup/CommonSetup.java index 8c1f0d1b..e40a6022 100644 --- a/src/main/java/harmonised/pmmo/setup/CommonSetup.java +++ b/src/main/java/harmonised/pmmo/setup/CommonSetup.java @@ -38,6 +38,7 @@ import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.config.ModConfigEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.server.ServerLifecycleHooks; @Mod.EventBusSubscriber(modid=Reference.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE) public class CommonSetup { @@ -78,7 +79,11 @@ public static void onCommandRegister(RegisterCommandsEvent event) { @SubscribeEvent public static void onAddReloadListeners(AddReloadListenerEvent event) { - Core.get(LogicalSide.SERVER).getLoader().RELOADER = new ExecutableListener(event.getRegistryAccess(), CoreLoader.RELOADER_FUNCTION); + Core.get(LogicalSide.SERVER).getLoader().RELOADER = new ExecutableListener(() -> + ServerLifecycleHooks.getCurrentServer() != null + ? ServerLifecycleHooks.getCurrentServer().registryAccess() + : null + , CoreLoader.RELOADER_FUNCTION); event.addListener(Core.get(LogicalSide.SERVER).getLoader().RELOADER); event.addListener(Core.get(LogicalSide.SERVER).getLoader().ITEM_LOADER); event.addListener(Core.get(LogicalSide.SERVER).getLoader().BLOCK_LOADER);