diff --git a/gradle.properties b/gradle.properties index 243eda6c9..09f4087d4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ org.gradle.parallel=true fabric_version=0.97.0+1.20.4 cca_version=5.4.0 pal_version=1.9.0 - calio_version=1.14.0-alpha.1+mc.1.20.4 + calio_version=1.14.0-alpha.2+mc.1.20.4 clothconfig_version=13.0.121 modmenu_version=9.0.0 aea_version=1.7.1+1.20.4 diff --git a/src/main/java/io/github/apace100/apoli/Apoli.java b/src/main/java/io/github/apace100/apoli/Apoli.java index df9631cea..afd968ffb 100644 --- a/src/main/java/io/github/apace100/apoli/Apoli.java +++ b/src/main/java/io/github/apace100/apoli/Apoli.java @@ -21,13 +21,14 @@ import io.github.apace100.apoli.registry.ApoliClassData; import io.github.apace100.apoli.util.*; import io.github.apace100.apoli.util.modifier.ModifierOperations; +import io.github.apace100.calio.Calio; +import io.github.apace100.calio.util.CalioResourceConditions; import io.github.ladysnake.pal.AbilitySource; import io.github.ladysnake.pal.Pal; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.resource.ResourceManagerHelper; -import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditions; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.advancement.criterion.Criteria; import net.minecraft.entity.LivingEntity; @@ -113,9 +114,7 @@ public void onInitialize() { ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new PowerTypes()); ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new GlobalPowerSetLoader()); - ResourceConditions.register(ApoliResourceConditions.ANY_NAMESPACE_LOADED, jsonObject -> ApoliResourceConditions.namespacesLoaded(jsonObject, PowerTypes.LOADED_NAMESPACES, false)); - ResourceConditions.register(ApoliResourceConditions.ALL_NAMESPACES_LOADED, jsonObject -> ApoliResourceConditions.namespacesLoaded(jsonObject, PowerTypes.LOADED_NAMESPACES, true)); - + CalioResourceConditions.ALIASES.addNamespaceAlias(MODID, Calio.MOD_NAMESPACE); Criteria.register(GainedPowerCriterion.ID.toString(), GainedPowerCriterion.INSTANCE); LOGGER.info("Apoli " + VERSION + " has initialized. Ready to power up your game!"); diff --git a/src/main/java/io/github/apace100/apoli/global/GlobalPowerSetLoader.java b/src/main/java/io/github/apace100/apoli/global/GlobalPowerSetLoader.java index 2939e6b63..c6294f709 100644 --- a/src/main/java/io/github/apace100/apoli/global/GlobalPowerSetLoader.java +++ b/src/main/java/io/github/apace100/apoli/global/GlobalPowerSetLoader.java @@ -21,8 +21,9 @@ public class GlobalPowerSetLoader extends IdentifiableMultiJsonDataLoader implements IdentifiableResourceReloadListener { public static final Identifier PHASE = Apoli.identifier("phase/global_powers"); - public static final Set DEPENDENCIES = Util.make(new HashSet<>(), set -> set.add(Apoli.identifier("powers"))); + + public static final Set DISABLED = new HashSet<>(); public static final Map ALL = new HashMap<>(); private static final Gson GSON = new GsonBuilder() @@ -51,9 +52,11 @@ public GlobalPowerSetLoader() { @Override protected void apply(MultiJsonDataContainer prepared, ResourceManager manager, Profiler profiler) { - ALL.clear(); prevId = null; + DISABLED.clear(); + ALL.clear(); + Map> loadedGlobalPowerSets = new HashMap<>(); prepared.forEach((packName, id, jsonElement) -> { @@ -97,6 +100,7 @@ protected void apply(MultiJsonDataContainer prepared, ResourceManager manager, P prevPriority = loadingPriority + 1; } + DISABLED.remove(id); globalPowerSets.add(globalPowerSet); } catch (Exception e) { @@ -134,6 +138,15 @@ protected void apply(MultiJsonDataContainer prepared, ResourceManager manager, P } + @Override + public void onReject(String packName, Identifier resourceId) { + + if (!ALL.containsKey(resourceId)) { + DISABLED.add(resourceId); + } + + } + @Override public Identifier getFabricId() { return Apoli.identifier("global_powers"); diff --git a/src/main/java/io/github/apace100/apoli/power/PowerType.java b/src/main/java/io/github/apace100/apoli/power/PowerType.java index 9ce91ce2d..2204e38c3 100644 --- a/src/main/java/io/github/apace100/apoli/power/PowerType.java +++ b/src/main/java/io/github/apace100/apoli/power/PowerType.java @@ -9,6 +9,7 @@ import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.Util; public class PowerType { @@ -55,9 +56,13 @@ public PowerType setSubPower(boolean subPower) { return this; } - public void setTranslationKeys(String name, String description) { + public PowerType setTranslationKeys(String name, String description) { + this.nameTranslationKey = name; this.descriptionTranslationKey = description; + + return this; + } public PowerType setDisplayTexts(Text name, Text description) { @@ -107,11 +112,13 @@ public T get(Entity entity) { } public String getOrCreateNameTranslationKey() { - if(nameTranslationKey == null || nameTranslationKey.isEmpty()) { - nameTranslationKey = - "power." + identifier.getNamespace() + "." + identifier.getPath() + ".name"; + + if (nameTranslationKey == null || nameTranslationKey.isEmpty()) { + this.nameTranslationKey = Util.createTranslationKey("power", identifier) + ".name"; } + return nameTranslationKey; + } public MutableText getName() { @@ -119,11 +126,13 @@ public MutableText getName() { } public String getOrCreateDescriptionTranslationKey() { - if(descriptionTranslationKey == null || descriptionTranslationKey.isEmpty()) { - descriptionTranslationKey = - "power." + identifier.getNamespace() + "." + identifier.getPath() + ".description"; + + if (descriptionTranslationKey == null || descriptionTranslationKey.isEmpty()) { + this.descriptionTranslationKey = Util.createTranslationKey("power", identifier) + ".description"; } + return descriptionTranslationKey; + } public MutableText getDescription() { @@ -157,4 +166,4 @@ public boolean equals(Object obj) { Identifier id = ((PowerType)obj).getIdentifier(); return identifier.equals(id); } -} \ No newline at end of file +} diff --git a/src/main/java/io/github/apace100/apoli/power/PowerTypes.java b/src/main/java/io/github/apace100/apoli/power/PowerTypes.java index 0869fcfa4..451b78f0c 100644 --- a/src/main/java/io/github/apace100/apoli/power/PowerTypes.java +++ b/src/main/java/io/github/apace100/apoli/power/PowerTypes.java @@ -10,11 +10,11 @@ import io.github.apace100.apoli.power.factory.PowerFactories; import io.github.apace100.apoli.power.factory.PowerFactory; import io.github.apace100.apoli.registry.ApoliRegistries; -import io.github.apace100.apoli.util.ApoliResourceConditions; import io.github.apace100.calio.data.IdentifiableMultiJsonDataLoader; import io.github.apace100.calio.data.MultiJsonDataContainer; import io.github.apace100.calio.data.SerializableData; import io.github.apace100.calio.data.SerializableDataTypes; +import io.github.apace100.calio.util.CalioResourceConditions; import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; @@ -30,6 +30,7 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.JsonHelper; +import net.minecraft.util.Util; import net.minecraft.util.profiler.Profiler; import org.jetbrains.annotations.Nullable; @@ -213,8 +214,13 @@ protected void apply(MultiJsonDataContainer prepared, ResourceManager manager, P } - private boolean isResourceConditionValid(Identifier id, JsonObject jo) { - return ApoliResourceConditions.test(id, jo); + @Override + public void onReject(String packName, Identifier resourceId) { + + if (!PowerTypeRegistry.contains(resourceId)) { + PowerTypeRegistry.disable(resourceId); + } + } private void readPower(String packName, Identifier id, JsonObject jsonObject) { @@ -264,7 +270,16 @@ else if (PowerTypeRegistry.isDisabled(id)) { @Nullable private PowerType readSubPower(String packName, Identifier id, JsonObject jsonObject) { - return readPower(packName, id, jsonObject, true, PowerType::new); + + if (CalioResourceConditions.objectMatchesConditions(id, jsonObject)) { + return readPower(packName, id, jsonObject, true, PowerType::new); + } + + else { + this.onReject(packName, id); + return null; + } + } @Nullable @@ -273,16 +288,6 @@ private PowerType readPower(String packName, Identifier id, JsonObject jsonOb Identifier powerFactoryId = SerializableDataTypes.IDENTIFIER.read(JsonHelper.getElement(jsonObject, "type")); int loadingPriority = JsonHelper.getInt(jsonObject, "loading_priority", 0); - if (!isResourceConditionValid(id, jsonObject)) { - - if (!PowerTypeRegistry.contains(id)) { - PowerTypeRegistry.disable(id); - } - - return null; - - } - boolean multiple = this.isMultiple(powerFactoryId); if (multiple) { powerFactoryId = SIMPLE; @@ -329,18 +334,15 @@ private PowerType finishReadingPower(BiFunction, Pow private PowerType loadPower(Identifier id, PowerFactory.Instance powerFactoryInstance, BiFunction.Instance, PowerType> powerTypeFactory, JsonObject jsonObject, boolean isSubPower) { - JsonElement nameJson = jsonObject.get("name"); - JsonElement descriptionJson = jsonObject.get("description"); + String nameTranslationKey = Util.createTranslationKey("power", id) + ".name"; + String descriptionTranslationKey = Util.createTranslationKey("power", id) + ".description"; - Text name = nameJson == null - ? null - : ApoliDataTypes.DEFAULT_TRANSLATABLE_TEXT.read(nameJson); - Text description = descriptionJson == null - ? null - : ApoliDataTypes.DEFAULT_TRANSLATABLE_TEXT.read(descriptionJson); + Text name = ApoliDataTypes.DEFAULT_TRANSLATABLE_TEXT.read(jsonObject.asMap().getOrDefault("name", new JsonPrimitive(nameTranslationKey))); + Text description = ApoliDataTypes.DEFAULT_TRANSLATABLE_TEXT.read(jsonObject.asMap().getOrDefault("description", new JsonPrimitive(descriptionTranslationKey))); boolean hidden = JsonHelper.getBoolean(jsonObject, "hidden", false); return powerTypeFactory.apply(id, powerFactoryInstance) + .setTranslationKeys(nameTranslationKey, descriptionTranslationKey) .setDisplayTexts(name, description) .setHidden(hidden || isSubPower) .setSubPower(isSubPower); diff --git a/src/main/java/io/github/apace100/apoli/util/ApoliResourceConditions.java b/src/main/java/io/github/apace100/apoli/util/ApoliResourceConditions.java deleted file mode 100644 index 8cff9cb56..000000000 --- a/src/main/java/io/github/apace100/apoli/util/ApoliResourceConditions.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.github.apace100.apoli.util; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParseException; -import io.github.apace100.apoli.Apoli; -import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditions; -import net.minecraft.util.Identifier; -import net.minecraft.util.JsonHelper; - -import java.util.Set; - -public class ApoliResourceConditions { - - public static final Identifier ANY_NAMESPACE_LOADED = Apoli.identifier("any_namespace_loaded"); - - public static final Identifier ALL_NAMESPACES_LOADED = Apoli.identifier("all_namespaces_loaded"); - - public static boolean namespacesLoaded(JsonObject jsonObject, Set namespaces, boolean and) { - - JsonArray jsonArray = JsonHelper.getArray(jsonObject, "namespaces"); - for (JsonElement jsonElement : jsonArray) { - if (jsonElement.isJsonPrimitive()) { - if (namespaces.contains(jsonElement.getAsString()) != and) { - return !and; - } - } else { - throw new JsonParseException("Invalid " + jsonElement + " entry: expected a JSON string!"); - } - } - - return and; - - } - - public static boolean test(Identifier id, JsonObject jsonObject) { - - try { - JsonArray conditions = JsonHelper.getArray(jsonObject, ResourceConditions.CONDITIONS_KEY, null); - if (conditions == null) { - return true; - } else { - return ResourceConditions.conditionsMatch(conditions, true); - } - } catch (RuntimeException e) { - Apoli.LOGGER.error("There was a problem parsing the resource condition(s) of power file " + id + " (skipping): " + e.getMessage()); - return false; - } - - } - -}