From b59c535c3d5869d0c4c2d8939ef4af3159e050e8 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Mon, 17 Jan 2022 22:34:47 +0000 Subject: [PATCH] Use fabric resource conditions api. Remove reborncore's. --- .../common/crafting/ConditionManager.java | 140 ------------------ .../common/crafting/RebornRecipeType.java | 5 - .../mixin/common/MixinRecipeManager.java | 60 -------- .../resources/reborncore.common.mixins.json | 1 - build.gradle | 2 +- gradle.properties | 4 +- .../recipes/byg_compat/ametrine_gem.json | 11 +- .../recipes/byg_compat/anthracite.json | 11 +- .../byg_compat/coal_dust_from_anthracite.json | 11 +- .../byg_compat/coal_dust_from_lignite.json | 11 +- .../recipes/byg_compat/lignite.json | 11 +- .../recipes/byg_compat/pendorite_scraps.json | 11 +- .../recipes/grinder/certus_quartz_dust.json | 11 +- .../grinder/certus_quartz_dust_from_ore.json | 11 +- .../recipes/grinder/fluix_dust.json | 11 +- .../grinder/marble_dust_from_limestone.json | 12 +- .../grinder/marble_dust_from_marble.json | 12 +- .../recipes/grinder/sulfur_dust.json | 11 +- .../recipes/grinder/sulfur_dust_from_ore.json | 11 +- .../industrial_grinder/certus_quartz_ore.json | 11 +- src/main/resources/fabric.mod.json | 2 +- 21 files changed, 116 insertions(+), 254 deletions(-) delete mode 100644 RebornCore/src/main/java/reborncore/common/crafting/ConditionManager.java delete mode 100644 RebornCore/src/main/java/reborncore/mixin/common/MixinRecipeManager.java diff --git a/RebornCore/src/main/java/reborncore/common/crafting/ConditionManager.java b/RebornCore/src/main/java/reborncore/common/crafting/ConditionManager.java deleted file mode 100644 index 8e39966d0..000000000 --- a/RebornCore/src/main/java/reborncore/common/crafting/ConditionManager.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * This file is part of RebornCore, licensed under the MIT License (MIT). - * - * Copyright (c) 2021 TeamReborn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package reborncore.common.crafting; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.tag.ItemTags; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; -import net.minecraft.util.registry.SimpleRegistry; -import org.apache.commons.lang3.Validate; - -import java.util.HashMap; -import java.util.function.Function; - -public final class ConditionManager { - - private static final HashMap> RECIPE_CONDITIONS = new HashMap<>(); - private static final HashMap> RECIPE_CONDITION_TYPES = new HashMap<>(); - - static { - //Only loads the recipe in a development env - register("development", Boolean.class, (bool) -> bool == FabricLoader.getInstance().isDevelopmentEnvironment()); - - //Only loads the recipe when the item is registered - register("item", Identifier.class, (id) -> registryContains(Registry.ITEM, id)); - - //Only loads the recipe when the fluid is registered - register("fluid", Identifier.class, (id) -> registryContains(Registry.FLUID, id)); - - //Only loads the recipe when the tag is loaded - register("tag", Identifier.class, s -> ItemTags.getTagGroup().getTags().containsKey(s)); - - //Only load the recipe if the provided mod is loaded - register("mod", String.class, s -> FabricLoader.getInstance().isModLoaded(s)); - - //Never load, just pass whatever in as the string - register("never", String.class, s -> false); - } - - private static boolean registryContains(SimpleRegistry registry, Identifier ident) { - return registry.containsId(ident); - } - - public static void register(String name, Class type, RecipeCondition recipeCondition){ - register(new Identifier("reborncore", name), type, recipeCondition); - } - - public static void register(Identifier identifier, Class type, RecipeCondition recipeCondition){ - Validate.isTrue(!RECIPE_CONDITIONS.containsKey(identifier), "Recipe condition already registered"); - RECIPE_CONDITIONS.put(identifier, recipeCondition); - RECIPE_CONDITION_TYPES.put(identifier, type); - } - - public static RecipeCondition getRecipeCondition(Identifier identifier){ - RecipeCondition condition = RECIPE_CONDITIONS.get(identifier); - if(condition == null){ - throw new UnsupportedOperationException("Could not find recipe condition for " + identifier.toString()); - } - return condition; - } - - public static boolean shouldLoadRecipe(JsonObject jsonObject){ - if(!jsonObject.has("conditions")) return true; - return jsonObject.get("conditions").getAsJsonObject().entrySet().stream() - .allMatch(entry -> shouldLoad(entry.getKey(), entry.getValue())); - } - - public static boolean shouldLoad(String ident, JsonElement jsonElement){ - Identifier identifier = parseIdent(ident); - RecipeCondition recipeCondition = getRecipeCondition(identifier); - Class type = RECIPE_CONDITION_TYPES.get(identifier); - return shouldLoad(type, jsonElement, recipeCondition); - } - - @SuppressWarnings("unchecked") - private static boolean shouldLoad(Class type, JsonElement jsonElement, RecipeCondition recipeCondition){ - Object val = TypeHelper.getValue(type, jsonElement); - return recipeCondition.shouldLoad(val); - } - - private static Identifier parseIdent(String string) { - if(string.contains(":")){ - return new Identifier(string); - } - return new Identifier("reborncore", string); - } - - @FunctionalInterface - public interface RecipeCondition { - boolean shouldLoad(T t); - } - - private static class TypeHelper { - - private static final HashMap, Function> FUNCTIONS = new HashMap<>(); - - static { - register(String.class, JsonElement::getAsString); - register(Boolean.class, JsonElement::getAsBoolean); - - register(Identifier.class, element -> new Identifier(element.getAsString())); - } - - private static void register(Class type, Function function){ - Validate.isTrue(!FUNCTIONS.containsKey(type), "Function for this class is already registered"); - FUNCTIONS.put(type, function); - } - - public static T getValue(Class type, JsonElement jsonElement){ - Validate.isTrue(FUNCTIONS.containsKey(type), "Function for this class could not be found"); - //noinspection unchecked - return (T) FUNCTIONS.get(type).apply(jsonElement); - } - - } -} diff --git a/RebornCore/src/main/java/reborncore/common/crafting/RebornRecipeType.java b/RebornCore/src/main/java/reborncore/common/crafting/RebornRecipeType.java index 20624d715..a0249a97a 100644 --- a/RebornCore/src/main/java/reborncore/common/crafting/RebornRecipeType.java +++ b/RebornCore/src/main/java/reborncore/common/crafting/RebornRecipeType.java @@ -52,11 +52,6 @@ public record RebornRecipeType( try { R recipe = newRecipe(recipeId); - if (!ConditionManager.shouldLoadRecipe(json)) { - recipe.makeDummy(); - return recipe; - } - recipe.deserialize(json); return recipe; } catch (Throwable t) { diff --git a/RebornCore/src/main/java/reborncore/mixin/common/MixinRecipeManager.java b/RebornCore/src/main/java/reborncore/mixin/common/MixinRecipeManager.java deleted file mode 100644 index 463ca0eec..000000000 --- a/RebornCore/src/main/java/reborncore/mixin/common/MixinRecipeManager.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of RebornCore, licensed under the MIT License (MIT). - * - * Copyright (c) 2021 TeamReborn - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package reborncore.mixin.common; - -import com.google.gson.JsonObject; -import net.minecraft.recipe.RecipeManager; -import net.minecraft.resource.ResourceManager; -import net.minecraft.util.Identifier; -import net.minecraft.util.profiler.Profiler; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import reborncore.common.crafting.ConditionManager; - -import java.util.Iterator; -import java.util.Map; - -@Mixin(RecipeManager.class) -public class MixinRecipeManager { - - @Inject(method = "apply", at = @At("HEAD")) - private void deserialize(Map map, ResourceManager resourceManager, Profiler profiler, CallbackInfo info) { - Iterator> iterator = map.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry entry = iterator.next(); - Identifier id = entry.getKey(); - JsonObject json = entry.getValue(); - - // TODO dont hard code this as its awful - if (id.getNamespace().equals("reborncore") || id.getNamespace().equals("techreborn")) { - if (!ConditionManager.shouldLoadRecipe(json)) { - iterator.remove(); - } - } - } - } -} diff --git a/RebornCore/src/main/resources/reborncore.common.mixins.json b/RebornCore/src/main/resources/reborncore.common.mixins.json index 2186fd3f9..e32577fc9 100644 --- a/RebornCore/src/main/resources/reborncore.common.mixins.json +++ b/RebornCore/src/main/resources/reborncore.common.mixins.json @@ -14,7 +14,6 @@ "MixinItemStack", "MixinLivingEntity", "MixinPlayerEntity", - "MixinRecipeManager", "MixinServerPlayerEntity" ], "injectors": { diff --git a/build.gradle b/build.gradle index 8fba67833..770260c2a 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ plugins { id 'eclipse' id 'maven-publish' id "org.cadixdev.licenser" version "0.6.1" - id "fabric-loom" version "0.10-SNAPSHOT" + id "fabric-loom" version "0.11-SNAPSHOT" id "com.matthewprenger.cursegradle" version "1.4.0" id "de.undercouch.download" version "4.1.1" } diff --git a/gradle.properties b/gradle.properties index 731425dfc..dd6184874 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,10 +9,10 @@ org.gradle.jvmargs=-Xmx2G minecraft_version=1.18.1 yarn_version=1.18.1+build.18 loader_version=0.12.12 - fapi_version=0.46.0+1.18 + fapi_version=0.46.1+1.18 # Dependencies - energy_version=2.0.0-beta1 + energy_version=2.1.0 rei_version=7.1.361 trinkets_version=3.0.2 autoswitch_version=-SNAPSHOT diff --git a/src/main/resources/data/techreborn/recipes/byg_compat/ametrine_gem.json b/src/main/resources/data/techreborn/recipes/byg_compat/ametrine_gem.json index 32f44dc34..79bef8fb4 100644 --- a/src/main/resources/data/techreborn/recipes/byg_compat/ametrine_gem.json +++ b/src/main/resources/data/techreborn/recipes/byg_compat/ametrine_gem.json @@ -12,7 +12,12 @@ "item": "byg:ametrine_gems" } ], - "conditions": { - "reborncore:mod": "byg" - } + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "byg" + ] + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/byg_compat/anthracite.json b/src/main/resources/data/techreborn/recipes/byg_compat/anthracite.json index d1aaed2fe..c310b195e 100644 --- a/src/main/resources/data/techreborn/recipes/byg_compat/anthracite.json +++ b/src/main/resources/data/techreborn/recipes/byg_compat/anthracite.json @@ -13,7 +13,12 @@ "count": 2 } ], - "conditions": { - "reborncore:mod": "byg" - } + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "byg" + ] + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/byg_compat/coal_dust_from_anthracite.json b/src/main/resources/data/techreborn/recipes/byg_compat/coal_dust_from_anthracite.json index e68314b06..7f987c583 100644 --- a/src/main/resources/data/techreborn/recipes/byg_compat/coal_dust_from_anthracite.json +++ b/src/main/resources/data/techreborn/recipes/byg_compat/coal_dust_from_anthracite.json @@ -12,7 +12,12 @@ "item": "techreborn:coal_dust" } ], - "conditions": { - "reborncore:mod": "byg" - } + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "byg" + ] + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/byg_compat/coal_dust_from_lignite.json b/src/main/resources/data/techreborn/recipes/byg_compat/coal_dust_from_lignite.json index fc27c3f25..14ff371fe 100644 --- a/src/main/resources/data/techreborn/recipes/byg_compat/coal_dust_from_lignite.json +++ b/src/main/resources/data/techreborn/recipes/byg_compat/coal_dust_from_lignite.json @@ -12,7 +12,12 @@ "item": "techreborn:coal_dust" } ], - "conditions": { - "reborncore:mod": "byg" - } + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "byg" + ] + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/byg_compat/lignite.json b/src/main/resources/data/techreborn/recipes/byg_compat/lignite.json index faae837d9..0c6356d8f 100644 --- a/src/main/resources/data/techreborn/recipes/byg_compat/lignite.json +++ b/src/main/resources/data/techreborn/recipes/byg_compat/lignite.json @@ -13,7 +13,12 @@ "count": 2 } ], - "conditions": { - "reborncore:mod": "byg" - } + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "byg" + ] + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/byg_compat/pendorite_scraps.json b/src/main/resources/data/techreborn/recipes/byg_compat/pendorite_scraps.json index f25dfff50..764e3d099 100644 --- a/src/main/resources/data/techreborn/recipes/byg_compat/pendorite_scraps.json +++ b/src/main/resources/data/techreborn/recipes/byg_compat/pendorite_scraps.json @@ -12,7 +12,12 @@ "item": "byg:pendorite_scraps" } ], - "conditions": { - "reborncore:mod": "byg" - } + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "byg" + ] + } + ] } \ No newline at end of file diff --git a/src/main/resources/data/techreborn/recipes/grinder/certus_quartz_dust.json b/src/main/resources/data/techreborn/recipes/grinder/certus_quartz_dust.json index 55b9bfe14..b955a8484 100644 --- a/src/main/resources/data/techreborn/recipes/grinder/certus_quartz_dust.json +++ b/src/main/resources/data/techreborn/recipes/grinder/certus_quartz_dust.json @@ -13,7 +13,12 @@ "item": "ae2:certus_quartz_dust" } ], - "conditions": { - "reborncore:mod": "ae2" - } + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "ae2" + ] + } + ] } diff --git a/src/main/resources/data/techreborn/recipes/grinder/certus_quartz_dust_from_ore.json b/src/main/resources/data/techreborn/recipes/grinder/certus_quartz_dust_from_ore.json index 46163efcb..e31be4f4d 100644 --- a/src/main/resources/data/techreborn/recipes/grinder/certus_quartz_dust_from_ore.json +++ b/src/main/resources/data/techreborn/recipes/grinder/certus_quartz_dust_from_ore.json @@ -13,7 +13,12 @@ "count": 5 } ], - "conditions": { - "reborncore:mod": "ae2" - } + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "ae2" + ] + } + ] } diff --git a/src/main/resources/data/techreborn/recipes/grinder/fluix_dust.json b/src/main/resources/data/techreborn/recipes/grinder/fluix_dust.json index 7463e20ba..c68584d9e 100644 --- a/src/main/resources/data/techreborn/recipes/grinder/fluix_dust.json +++ b/src/main/resources/data/techreborn/recipes/grinder/fluix_dust.json @@ -13,7 +13,12 @@ "item": "ae2:fluix_dust" } ], - "conditions": { - "reborncore:mod": "ae2" - } + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "ae2" + ] + } + ] } diff --git a/src/main/resources/data/techreborn/recipes/grinder/marble_dust_from_limestone.json b/src/main/resources/data/techreborn/recipes/grinder/marble_dust_from_limestone.json index 4356344dd..0362530d9 100644 --- a/src/main/resources/data/techreborn/recipes/grinder/marble_dust_from_limestone.json +++ b/src/main/resources/data/techreborn/recipes/grinder/marble_dust_from_limestone.json @@ -14,8 +14,12 @@ "item": "techreborn:marble_dust" } ], - - "conditions": { - "reborncore:tag": "c:limestone" - } + "fabric:load_conditions": [ + { + "condition": "fabric:item_tags_populated", + "values": [ + "c:limestone" + ] + } + ] } diff --git a/src/main/resources/data/techreborn/recipes/grinder/marble_dust_from_marble.json b/src/main/resources/data/techreborn/recipes/grinder/marble_dust_from_marble.json index 9c418e2be..eea9c34dc 100644 --- a/src/main/resources/data/techreborn/recipes/grinder/marble_dust_from_marble.json +++ b/src/main/resources/data/techreborn/recipes/grinder/marble_dust_from_marble.json @@ -14,8 +14,12 @@ "item": "techreborn:marble_dust" } ], - - "conditions": { - "reborncore:tag": "c:marble" - } + "fabric:load_conditions": [ + { + "condition": "fabric:item_tags_populated", + "values": [ + "c:marble" + ] + } + ] } diff --git a/src/main/resources/data/techreborn/recipes/grinder/sulfur_dust.json b/src/main/resources/data/techreborn/recipes/grinder/sulfur_dust.json index 3d960b000..b216235f1 100644 --- a/src/main/resources/data/techreborn/recipes/grinder/sulfur_dust.json +++ b/src/main/resources/data/techreborn/recipes/grinder/sulfur_dust.json @@ -12,7 +12,12 @@ "item": "techreborn:sulfur_dust" } ], - "conditions": { - "reborncore:tag": "c:sulfurs" - } + "fabric:load_conditions": [ + { + "condition": "fabric:item_tags_populated", + "values": [ + "c:sulfurs" + ] + } + ] } diff --git a/src/main/resources/data/techreborn/recipes/grinder/sulfur_dust_from_ore.json b/src/main/resources/data/techreborn/recipes/grinder/sulfur_dust_from_ore.json index 4df4a42c6..1ea2d0ca3 100644 --- a/src/main/resources/data/techreborn/recipes/grinder/sulfur_dust_from_ore.json +++ b/src/main/resources/data/techreborn/recipes/grinder/sulfur_dust_from_ore.json @@ -13,7 +13,12 @@ "count": 2 } ], - "conditions": { - "reborncore:tag": "c:sulfur_ores" - } + "fabric:load_conditions": [ + { + "condition": "fabric:item_tags_populated", + "values": [ + "c:sulfur_ores" + ] + } + ] } diff --git a/src/main/resources/data/techreborn/recipes/industrial_grinder/certus_quartz_ore.json b/src/main/resources/data/techreborn/recipes/industrial_grinder/certus_quartz_ore.json index 87a3f5214..01dae0ded 100644 --- a/src/main/resources/data/techreborn/recipes/industrial_grinder/certus_quartz_ore.json +++ b/src/main/resources/data/techreborn/recipes/industrial_grinder/certus_quartz_ore.json @@ -21,7 +21,12 @@ "count": 5 } ], - "conditions": { - "reborncore:mod": "ae2" - } + "fabric:load_conditions": [ + { + "condition": "fabric:all_mods_loaded", + "values": [ + "ae2" + ] + } + ] } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d4647abd9..b12dabec6 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -34,7 +34,7 @@ }, "depends": { "fabricloader": ">=0.12.0", - "fabric": ">=0.40.0", + "fabric": ">=0.46.1", "reborncore": "*", "team_reborn_energy": ">=2.0.0-beta1", "fabric-biome-api-v1": ">=3.0.0"