From d276f378731c7358c39b1416a62cae82e4f47d28 Mon Sep 17 00:00:00 2001 From: LLytho <29131229+LLytho@users.noreply.github.com> Date: Fri, 22 Jul 2022 19:33:37 +0200 Subject: [PATCH] Clear code --- .../unified/api/recipe/RecipeHandler.java | 5 --- .../unified/api/recipe/RecipeUnifier.java | 5 +++ ...Builder.java => RecipeUnifierBuilder.java} | 2 +- .../recipe/ReplacementFallbackStrategy.java | 1 - .../unified/recipe/RecipeDumper.java | 2 +- .../unified/recipe/RecipeLink.java | 26 ++++++------ .../unified/recipe/RecipeTransformer.java | 26 ++++++------ ...mpl.java => RecipeUnifierBuilderImpl.java} | 6 +-- .../StoneStrataFallbackStrategy.java | 1 - ...Handler.java => GenericRecipeUnifier.java} | 10 ++--- .../recipe/handler/RecipeHandlerFactory.java | 30 +++++++------- ...ndler.java => ShapedRecipeKeyUnifier.java} | 10 ++--- .../unified/utils/JsonQuery.java | 18 ++++----- .../almostreliable/unified/utils/Utils.java | 2 - .../unified/FakeResourceKeyRegistry.java | 3 +- .../unified/utils/ReplacementMapTests.java | 6 ++- .../unified/AlmostUnifiedPlatformForge.java | 4 +- ...ecipeHandler.java => IERecipeUnifier.java} | 8 ++-- ...dlerTest.java => IERecipeUnifierTest.java} | 40 +++++++++---------- 19 files changed, 102 insertions(+), 103 deletions(-) delete mode 100644 Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeHandler.java create mode 100644 Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeUnifier.java rename Common/src/main/java/com/almostreliable/unified/api/recipe/{RecipeTransformationBuilder.java => RecipeUnifierBuilder.java} (90%) rename Common/src/main/java/com/almostreliable/unified/recipe/{RecipeTransformationBuilderImpl.java => RecipeUnifierBuilderImpl.java} (92%) rename Common/src/main/java/com/almostreliable/unified/recipe/handler/{GenericRecipeHandler.java => GenericRecipeUnifier.java} (67%) rename Common/src/main/java/com/almostreliable/unified/recipe/handler/{ShapedRecipeKeyHandler.java => ShapedRecipeKeyUnifier.java} (63%) rename Forge/src/main/java/com/almostreliable/unified/compat/ie/{IERecipeHandler.java => IERecipeUnifier.java} (92%) rename Forge/src/test/java/com/almostreliable/unified/compat/ie/{IERecipeHandlerTest.java => IERecipeUnifierTest.java} (71%) diff --git a/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeHandler.java b/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeHandler.java deleted file mode 100644 index 5605416..0000000 --- a/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeHandler.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.almostreliable.unified.api.recipe; - -public interface RecipeHandler { - void collectTransformations(RecipeTransformationBuilder builder); -} diff --git a/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeUnifier.java b/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeUnifier.java new file mode 100644 index 0000000..0b672b6 --- /dev/null +++ b/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeUnifier.java @@ -0,0 +1,5 @@ +package com.almostreliable.unified.api.recipe; + +public interface RecipeUnifier { + void collectUnifier(RecipeUnifierBuilder builder); +} diff --git a/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeTransformationBuilder.java b/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeUnifierBuilder.java similarity index 90% rename from Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeTransformationBuilder.java rename to Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeUnifierBuilder.java index 1708a56..6827de0 100644 --- a/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeTransformationBuilder.java +++ b/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeUnifierBuilder.java @@ -5,7 +5,7 @@ import com.google.gson.JsonObject; import java.util.function.BiFunction; -public interface RecipeTransformationBuilder { +public interface RecipeUnifierBuilder { void forEachObject(String property, BiFunction consumer); diff --git a/Common/src/main/java/com/almostreliable/unified/api/recipe/ReplacementFallbackStrategy.java b/Common/src/main/java/com/almostreliable/unified/api/recipe/ReplacementFallbackStrategy.java index ca67bf7..3a5a094 100644 --- a/Common/src/main/java/com/almostreliable/unified/api/recipe/ReplacementFallbackStrategy.java +++ b/Common/src/main/java/com/almostreliable/unified/api/recipe/ReplacementFallbackStrategy.java @@ -3,7 +3,6 @@ package com.almostreliable.unified.api.recipe; import com.almostreliable.unified.utils.TagMap; import com.almostreliable.unified.utils.UnifyTag; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import javax.annotation.Nullable; diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java index 0eac909..5897e3e 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeDumper.java @@ -83,7 +83,7 @@ public class RecipeDumper { .append("\n"); stringBuilder .append("\t\t Transformed: ") - .append(recipe.getTransformed().toString()) + .append(recipe.getUnified().toString()) .append("\n\n"); } }); diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java index 4c4617f..12a96c8 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeLink.java @@ -13,7 +13,7 @@ public class RecipeLink { private final ResourceLocation type; private final JsonObject originalRecipe; @Nullable private DuplicateLink duplicateLink; - @Nullable private JsonObject transformedRecipe; + @Nullable private JsonObject unifiedRecipe; public RecipeLink(ResourceLocation id, JsonObject originalRecipe) { this.id = id; @@ -95,21 +95,21 @@ public class RecipeLink { } @Nullable - public JsonObject getTransformed() { - return transformedRecipe; + public JsonObject getUnified() { + return unifiedRecipe; } - public boolean isTransformed() { - return transformedRecipe != null; + public boolean isUnified() { + return unifiedRecipe != null; } - public void setTransformed(JsonObject transformedRecipe) { - Objects.requireNonNull(transformedRecipe); - if (isTransformed()) { - throw new IllegalStateException("Recipe already transformed"); + void setUnified(JsonObject json) { + Objects.requireNonNull(json); + if (isUnified()) { + throw new IllegalStateException("Recipe already unified"); } - this.transformedRecipe = transformedRecipe; + this.unifiedRecipe = json; } private List getIgnoredFields() { @@ -127,8 +127,8 @@ public class RecipeLink { @Override public String toString() { String duplicate = duplicateLink != null ? " (duplicate)" : ""; - String transformed = transformedRecipe != null ? " (transformed)" : ""; - return String.format("['%s'] %s%s%s", type, id, duplicate, transformed); + String unified = unifiedRecipe != null ? " (unified)" : ""; + return String.format("['%s'] %s%s%s", type, id, duplicate, unified); } /** @@ -165,7 +165,7 @@ public class RecipeLink { } public JsonObject getActual() { - return getTransformed() != null ? getTransformed() : getOriginal(); + return getUnified() != null ? getUnified() : getOriginal(); } public static class DuplicateLink { diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformer.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformer.java index e4d5ec4..2c85767 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformer.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformer.java @@ -45,9 +45,9 @@ public class RecipeTransformer { byType.forEach((type, recipeLinks) -> { Set duplicates = new HashSet<>(recipeLinks.size()); for (RecipeLink curRecipe : recipeLinks) { - transformRecipe(curRecipe); - if (curRecipe.isTransformed()) { - recipes.put(curRecipe.getId(), curRecipe.getTransformed()); + unifyRecipe(curRecipe); + if (curRecipe.isUnified()) { + recipes.put(curRecipe.getId(), curRecipe.getUnified()); if (handleDuplicate(curRecipe, recipeLinks)) { duplicates.add(curRecipe.getDuplicateLink()); } @@ -94,22 +94,22 @@ public class RecipeTransformer { } /** - * Transforms a single recipe link. This method will modify the recipe link in-place. - * {@link RecipeHandlerFactory} will apply multiple transformations onto the recipe. + * Unifies a single recipe link. This method will modify the recipe link in-place. + * {@link RecipeHandlerFactory} will apply multiple unification's onto the recipe. * - * @param recipe The recipe link to transform. + * @param recipe The recipe link to unify. */ - public void transformRecipe(RecipeLink recipe) { + public void unifyRecipe(RecipeLink recipe) { try { RecipeContextImpl ctx = new RecipeContextImpl(recipe.getOriginal(), replacementMap); - RecipeTransformationBuilderImpl builder = new RecipeTransformationBuilderImpl(); - factory.fillTransformations(builder, ctx); - JsonObject result = builder.transform(recipe.getOriginal(), ctx); + RecipeUnifierBuilderImpl builder = new RecipeUnifierBuilderImpl(); + factory.fillUnifier(builder, ctx); + JsonObject result = builder.unify(recipe.getOriginal(), ctx); if (result != null) { - recipe.setTransformed(result); + recipe.setUnified(result); } } catch (Exception e) { - AlmostUnified.LOG.warn("Error transforming recipe '{}': {}", + AlmostUnified.LOG.warn("Error unifying recipe '{}': {}", recipe.getId(), e.getMessage()); e.printStackTrace(); @@ -126,7 +126,7 @@ public class RecipeTransformer { } allRecipesByType.put(link.getType(), link); - if (link.isTransformed()) { + if (link.isUnified()) { unifiedRecipesByType.put(link.getType(), link); } } diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformationBuilderImpl.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeUnifierBuilderImpl.java similarity index 92% rename from Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformationBuilderImpl.java rename to Common/src/main/java/com/almostreliable/unified/recipe/RecipeUnifierBuilderImpl.java index aa33519..089e24f 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeTransformationBuilderImpl.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeUnifierBuilderImpl.java @@ -1,7 +1,7 @@ package com.almostreliable.unified.recipe; import com.almostreliable.unified.api.recipe.RecipeContext; -import com.almostreliable.unified.api.recipe.RecipeTransformationBuilder; +import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -11,7 +11,7 @@ import java.util.HashMap; import java.util.Map; import java.util.function.BiFunction; -public class RecipeTransformationBuilderImpl implements RecipeTransformationBuilder { +public class RecipeUnifierBuilderImpl implements RecipeUnifierBuilder { private final Map> consumers = new HashMap<>(); @Override @@ -42,7 +42,7 @@ public class RecipeTransformationBuilderImpl implements RecipeTransformationBuil consumers.put(property, new Entry<>(type, consumer)); } - public JsonObject transform(JsonObject json, RecipeContext context) { + public JsonObject unify(JsonObject json, RecipeContext context) { JsonObject changedValues = new JsonObject(); for (var e : json.entrySet()) { diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/fallbacks/StoneStrataFallbackStrategy.java b/Common/src/main/java/com/almostreliable/unified/recipe/fallbacks/StoneStrataFallbackStrategy.java index e1a458e..4cde879 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/fallbacks/StoneStrataFallbackStrategy.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/fallbacks/StoneStrataFallbackStrategy.java @@ -4,7 +4,6 @@ import com.almostreliable.unified.api.recipe.ReplacementFallbackStrategy; import com.almostreliable.unified.utils.TagMap; import com.almostreliable.unified.utils.UnifyTag; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import java.util.Collection; diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/handler/GenericRecipeHandler.java b/Common/src/main/java/com/almostreliable/unified/recipe/handler/GenericRecipeUnifier.java similarity index 67% rename from Common/src/main/java/com/almostreliable/unified/recipe/handler/GenericRecipeHandler.java rename to Common/src/main/java/com/almostreliable/unified/recipe/handler/GenericRecipeUnifier.java index dc6f336..809f866 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/handler/GenericRecipeHandler.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/handler/GenericRecipeUnifier.java @@ -1,13 +1,13 @@ package com.almostreliable.unified.recipe.handler; import com.almostreliable.unified.api.recipe.RecipeConstants; -import com.almostreliable.unified.api.recipe.RecipeHandler; -import com.almostreliable.unified.api.recipe.RecipeTransformationBuilder; +import com.almostreliable.unified.api.recipe.RecipeUnifier; +import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder; import java.util.Set; -public class GenericRecipeHandler implements RecipeHandler { - public static final GenericRecipeHandler INSTANCE = new GenericRecipeHandler(); +public class GenericRecipeUnifier implements RecipeUnifier { + public static final GenericRecipeUnifier INSTANCE = new GenericRecipeUnifier(); private final Set inputKeys = Set.of(RecipeConstants.INPUT, RecipeConstants.INGREDIENT, RecipeConstants.INGREDIENTS); @@ -16,7 +16,7 @@ public class GenericRecipeHandler implements RecipeHandler { RecipeConstants.RESULTS); @Override - public void collectTransformations(RecipeTransformationBuilder builder) { + public void collectUnifier(RecipeUnifierBuilder builder) { for (String inputKey : inputKeys) { builder.put(inputKey, (json, ctx) -> ctx.createIngredientReplacement(json)); } diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/handler/RecipeHandlerFactory.java b/Common/src/main/java/com/almostreliable/unified/recipe/handler/RecipeHandlerFactory.java index 596383a..471d9d7 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/handler/RecipeHandlerFactory.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/handler/RecipeHandlerFactory.java @@ -1,42 +1,42 @@ package com.almostreliable.unified.recipe.handler; import com.almostreliable.unified.api.recipe.RecipeContext; -import com.almostreliable.unified.api.recipe.RecipeHandler; -import com.almostreliable.unified.api.recipe.RecipeTransformationBuilder; +import com.almostreliable.unified.api.recipe.RecipeUnifier; +import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder; import net.minecraft.resources.ResourceLocation; import java.util.HashMap; import java.util.Map; public class RecipeHandlerFactory { - private final Map transformersByType = new HashMap<>(); - private final Map transformersByModId = new HashMap<>(); + private final Map transformersByType = new HashMap<>(); + private final Map transformersByModId = new HashMap<>(); - public void fillTransformations(RecipeTransformationBuilder builder, RecipeContext context) { - GenericRecipeHandler.INSTANCE.collectTransformations(builder); + public void fillUnifier(RecipeUnifierBuilder builder, RecipeContext context) { + GenericRecipeUnifier.INSTANCE.collectUnifier(builder); - if (context.hasProperty(ShapedRecipeKeyHandler.PATTERN_PROPERTY) && - context.hasProperty(ShapedRecipeKeyHandler.KEY_PROPERTY)) { - ShapedRecipeKeyHandler.INSTANCE.collectTransformations(builder); + if (context.hasProperty(ShapedRecipeKeyUnifier.PATTERN_PROPERTY) && + context.hasProperty(ShapedRecipeKeyUnifier.KEY_PROPERTY)) { + ShapedRecipeKeyUnifier.INSTANCE.collectUnifier(builder); } ResourceLocation type = context.getType(); - RecipeHandler byMod = transformersByModId.get(type.getNamespace()); + RecipeUnifier byMod = transformersByModId.get(type.getNamespace()); if (byMod != null) { - byMod.collectTransformations(builder); + byMod.collectUnifier(builder); } - RecipeHandler byType = transformersByType.get(type); + RecipeUnifier byType = transformersByType.get(type); if (byType != null) { - byType.collectTransformations(builder); + byType.collectUnifier(builder); } } - public void registerForType(ResourceLocation type, RecipeHandler transformer) { + public void registerForType(ResourceLocation type, RecipeUnifier transformer) { transformersByType.put(type, transformer); } - public void registerForMod(String mod, RecipeHandler transformer) { + public void registerForMod(String mod, RecipeUnifier transformer) { transformersByModId.put(mod, transformer); } } diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/handler/ShapedRecipeKeyHandler.java b/Common/src/main/java/com/almostreliable/unified/recipe/handler/ShapedRecipeKeyUnifier.java similarity index 63% rename from Common/src/main/java/com/almostreliable/unified/recipe/handler/ShapedRecipeKeyHandler.java rename to Common/src/main/java/com/almostreliable/unified/recipe/handler/ShapedRecipeKeyUnifier.java index 05263e4..e165092 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/handler/ShapedRecipeKeyHandler.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/handler/ShapedRecipeKeyUnifier.java @@ -1,17 +1,17 @@ package com.almostreliable.unified.recipe.handler; -import com.almostreliable.unified.api.recipe.RecipeHandler; -import com.almostreliable.unified.api.recipe.RecipeTransformationBuilder; +import com.almostreliable.unified.api.recipe.RecipeUnifier; +import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -public class ShapedRecipeKeyHandler implements RecipeHandler { - public static final RecipeHandler INSTANCE = new ShapedRecipeKeyHandler(); +public class ShapedRecipeKeyUnifier implements RecipeUnifier { + public static final RecipeUnifier INSTANCE = new ShapedRecipeKeyUnifier(); public static final String PATTERN_PROPERTY = "pattern"; public static final String KEY_PROPERTY = "key"; @Override - public void collectTransformations(RecipeTransformationBuilder builder) { + public void collectUnifier(RecipeUnifierBuilder builder) { builder.put(KEY_PROPERTY, JsonObject.class, (json, context) -> { for (var entry : json.entrySet()) { JsonElement result = context.createIngredientReplacement(entry.getValue()); diff --git a/Common/src/main/java/com/almostreliable/unified/utils/JsonQuery.java b/Common/src/main/java/com/almostreliable/unified/utils/JsonQuery.java index 1275f8f..fef1243 100644 --- a/Common/src/main/java/com/almostreliable/unified/utils/JsonQuery.java +++ b/Common/src/main/java/com/almostreliable/unified/utils/JsonQuery.java @@ -9,6 +9,10 @@ public class JsonQuery { private final JsonElement element; + JsonQuery(JsonElement element) { + this.element = element; + } + public static JsonQuery of(JsonElement element) { return new JsonQuery(element); } @@ -17,7 +21,7 @@ public class JsonQuery { String[] parts = path.split("/"); JsonQuery current = of(element); for (String part : parts) { - if(StringUtils.isNumeric(part)) { + if (StringUtils.isNumeric(part)) { current = current.get(Integer.parseInt(part)); } else { current = current.get(part); @@ -26,17 +30,13 @@ public class JsonQuery { return current; } - JsonQuery(JsonElement element) { - this.element = element; - } - public JsonQuery get(String identifier) { - if(!element.isJsonObject()) { + if (!element.isJsonObject()) { throw new IllegalArgumentException("Expected JsonObject, got " + element.getClass()); } JsonElement child = element.getAsJsonObject().get(identifier); - if(child == null) { + if (child == null) { return null; } @@ -44,12 +44,12 @@ public class JsonQuery { } public JsonQuery get(int index) { - if(!element.isJsonArray()) { + if (!element.isJsonArray()) { throw new IllegalArgumentException("Expected JsonArray, got " + element.getClass()); } JsonElement child = element.getAsJsonArray().get(index); - if(child == null) { + if (child == null) { return null; } diff --git a/Common/src/main/java/com/almostreliable/unified/utils/Utils.java b/Common/src/main/java/com/almostreliable/unified/utils/Utils.java index eb2fcf5..4822bf7 100644 --- a/Common/src/main/java/com/almostreliable/unified/utils/Utils.java +++ b/Common/src/main/java/com/almostreliable/unified/utils/Utils.java @@ -1,9 +1,7 @@ package com.almostreliable.unified.utils; import com.almostreliable.unified.BuildConfig; -import net.minecraft.core.Registry; import net.minecraft.resources.ResourceLocation; -import net.minecraft.tags.TagKey; import net.minecraft.world.item.Item; import javax.annotation.Nullable; diff --git a/Common/src/test/java/com/almostreliable/unified/FakeResourceKeyRegistry.java b/Common/src/test/java/com/almostreliable/unified/FakeResourceKeyRegistry.java index d02997d..e19735b 100644 --- a/Common/src/test/java/com/almostreliable/unified/FakeResourceKeyRegistry.java +++ b/Common/src/test/java/com/almostreliable/unified/FakeResourceKeyRegistry.java @@ -15,7 +15,8 @@ public class FakeResourceKeyRegistry { c.setAccessible(true); return (ResourceKey>) c.newInstance(new ResourceLocation("test_registry"), new ResourceLocation(name)); - } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { + } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | + IllegalAccessException e) { e.printStackTrace(); return null; } diff --git a/Common/src/test/java/com/almostreliable/unified/utils/ReplacementMapTests.java b/Common/src/test/java/com/almostreliable/unified/utils/ReplacementMapTests.java index 615c7b0..50e7646 100644 --- a/Common/src/test/java/com/almostreliable/unified/utils/ReplacementMapTests.java +++ b/Common/src/test/java/com/almostreliable/unified/utils/ReplacementMapTests.java @@ -8,7 +8,8 @@ import org.junit.jupiter.api.Test; import java.util.List; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class ReplacementMapTests { @@ -45,6 +46,7 @@ public class ReplacementMapTests { TestUtils.TEST_MOD_PRIORITIES, ModConfig.DEFAULT_STONE_STRATA); assertEquals(map.getPreferredTagForItem(TestUtils.mod1RL("bronze_ore")), TestUtils.BRONZE_ORES_TAG); - assertNull(map.getPreferredTagForItem(new ResourceLocation("minecraft:diamond")), "We don't have a tag for diamond"); + assertNull(map.getPreferredTagForItem(new ResourceLocation("minecraft:diamond")), + "We don't have a tag for diamond"); } } diff --git a/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java b/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java index 41569b1..8026726 100644 --- a/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java +++ b/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java @@ -1,7 +1,7 @@ package com.almostreliable.unified; import com.almostreliable.unified.api.ModConstants; -import com.almostreliable.unified.compat.ie.IERecipeHandler; +import com.almostreliable.unified.compat.ie.IERecipeUnifier; import com.almostreliable.unified.recipe.handler.RecipeHandlerFactory; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.loading.FMLLoader; @@ -38,7 +38,7 @@ public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform { @Override public void bindRecipeHandlers(RecipeHandlerFactory factory) { - factory.registerForMod(ModConstants.IE, new IERecipeHandler()); + factory.registerForMod(ModConstants.IE, new IERecipeUnifier()); } @Override diff --git a/Forge/src/main/java/com/almostreliable/unified/compat/ie/IERecipeHandler.java b/Forge/src/main/java/com/almostreliable/unified/compat/ie/IERecipeUnifier.java similarity index 92% rename from Forge/src/main/java/com/almostreliable/unified/compat/ie/IERecipeHandler.java rename to Forge/src/main/java/com/almostreliable/unified/compat/ie/IERecipeUnifier.java index 23eaa3a..9d3ae64 100644 --- a/Forge/src/main/java/com/almostreliable/unified/compat/ie/IERecipeHandler.java +++ b/Forge/src/main/java/com/almostreliable/unified/compat/ie/IERecipeUnifier.java @@ -2,8 +2,8 @@ package com.almostreliable.unified.compat.ie; import com.almostreliable.unified.api.recipe.RecipeConstants; import com.almostreliable.unified.api.recipe.RecipeContext; -import com.almostreliable.unified.api.recipe.RecipeHandler; -import com.almostreliable.unified.api.recipe.RecipeTransformationBuilder; +import com.almostreliable.unified.api.recipe.RecipeUnifier; +import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder; import com.almostreliable.unified.utils.JsonUtils; import com.almostreliable.unified.utils.Utils; import com.google.gson.JsonArray; @@ -13,14 +13,14 @@ import net.minecraft.resources.ResourceLocation; import javax.annotation.Nullable; -public class IERecipeHandler implements RecipeHandler { +public class IERecipeUnifier implements RecipeUnifier { // From IE protected static final String BASE_KEY = "base_ingredient"; // TODO make it cleaner @Override - public void collectTransformations(RecipeTransformationBuilder builder) { + public void collectUnifier(RecipeUnifierBuilder builder) { builder.put("input0", this::replaceIEIngredient); // alloy recipes, refinery builder.put("input1", this::replaceIEIngredient); // alloy recipes, refinery builder.put(RecipeConstants.INPUT, diff --git a/Forge/src/test/java/com/almostreliable/unified/compat/ie/IERecipeHandlerTest.java b/Forge/src/test/java/com/almostreliable/unified/compat/ie/IERecipeUnifierTest.java similarity index 71% rename from Forge/src/test/java/com/almostreliable/unified/compat/ie/IERecipeHandlerTest.java rename to Forge/src/test/java/com/almostreliable/unified/compat/ie/IERecipeUnifierTest.java index 91b17ff..a216574 100644 --- a/Forge/src/test/java/com/almostreliable/unified/compat/ie/IERecipeHandlerTest.java +++ b/Forge/src/test/java/com/almostreliable/unified/compat/ie/IERecipeUnifierTest.java @@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; -public class IERecipeHandlerTest { +public class IERecipeUnifierTest { public final Gson gson = new Gson(); private final ResourceLocation defaultRecipeId = new ResourceLocation("default_test_recipe"); @@ -29,29 +29,29 @@ public class IERecipeHandlerTest { @Test public void notMatching() { RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE, - new IERecipeHandler())); + new IERecipeUnifier())); JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class); RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy); - transformer.transformRecipe(recipe); - assertFalse(recipe.isTransformed(), "Nothing to transform, so it should be false"); + transformer.unifyRecipe(recipe); + assertFalse(recipe.isUnified(), "Nothing to transform, so it should be false"); } @Test public void resultTagMatches() { RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE, - new IERecipeHandler())); + new IERecipeUnifier())); JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class); alloy .getAsJsonObject("result") .getAsJsonObject("base_ingredient") .addProperty("tag", TestUtils.BRONZE_ORES_TAG.location().toString()); RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy); - transformer.transformRecipe(recipe); + transformer.unifyRecipe(recipe); - assertNotEquals(recipe.getTransformed(), alloy, "Result should be different"); - assertNotNull(recipe.getTransformed(), "Result should not be null"); - assertNull(JsonQuery.of(recipe.getTransformed(), "result/base_ingredient/tag"), "Tag key should be removed"); - assertEquals(JsonQuery.of(recipe.getTransformed(), "result/base_ingredient/item").asString(), + assertNotEquals(recipe.getUnified(), alloy, "Result should be different"); + assertNotNull(recipe.getUnified(), "Result should not be null"); + assertNull(JsonQuery.of(recipe.getUnified(), "result/base_ingredient/tag"), "Tag key should be removed"); + assertEquals(JsonQuery.of(recipe.getUnified(), "result/base_ingredient/item").asString(), TestUtils.mod1RL("bronze_ore").toString(), "Result should be bronze_ore"); } @@ -59,7 +59,7 @@ public class IERecipeHandlerTest { @Test public void resultItemMatches() { RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE, - new IERecipeHandler())); + new IERecipeUnifier())); JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class); alloy.getAsJsonObject("result").getAsJsonObject("base_ingredient").remove("tag"); alloy @@ -67,11 +67,11 @@ public class IERecipeHandlerTest { .getAsJsonObject("base_ingredient") .addProperty("item", TestUtils.mod3RL("bronze_ore").toString()); RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy); - transformer.transformRecipe(recipe); + transformer.unifyRecipe(recipe); - assertNotEquals(recipe.getTransformed(), alloy, "Result should be different"); - assertNotNull(recipe.getTransformed(), "Result should not be null"); - assertEquals(JsonQuery.of(recipe.getTransformed(), ("result/base_ingredient/item")).asString(), + assertNotEquals(recipe.getUnified(), alloy, "Result should be different"); + assertNotNull(recipe.getUnified(), "Result should not be null"); + assertEquals(JsonQuery.of(recipe.getUnified(), ("result/base_ingredient/item")).asString(), TestUtils.mod1RL("bronze_ore").toString(), "Transformer should replace bronze_ore from mod3 with bronze_ore from mod1"); } @@ -79,7 +79,7 @@ public class IERecipeHandlerTest { @Test public void inputAlloyItemMatches() { RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE, - new IERecipeHandler())); + new IERecipeUnifier())); JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class); alloy.getAsJsonObject("result").getAsJsonObject("base_ingredient").remove("tag"); alloy @@ -87,11 +87,11 @@ public class IERecipeHandlerTest { .getAsJsonObject("base_ingredient") .addProperty("item", TestUtils.mod3RL("bronze_ore").toString()); RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy); - transformer.transformRecipe(recipe); + transformer.unifyRecipe(recipe); - assertNotEquals(recipe.getTransformed(), alloy, "Result should be different"); - assertNotNull(recipe.getTransformed(), "Result should not be null"); - assertEquals(JsonQuery.of(recipe.getTransformed(), ("result/base_ingredient/item")).asString(), + assertNotEquals(recipe.getUnified(), alloy, "Result should be different"); + assertNotNull(recipe.getUnified(), "Result should not be null"); + assertEquals(JsonQuery.of(recipe.getUnified(), ("result/base_ingredient/item")).asString(), TestUtils.mod1RL("bronze_ore").toString(), "Transformer should replace bronze_ore from mod3 with bronze_ore from mod1"); }