mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-28 10:35:38 -05:00
Clear code
This commit is contained in:
parent
fbbe715447
commit
d276f37873
19 changed files with 102 additions and 103 deletions
|
@ -1,5 +0,0 @@
|
||||||
package com.almostreliable.unified.api.recipe;
|
|
||||||
|
|
||||||
public interface RecipeHandler {
|
|
||||||
void collectTransformations(RecipeTransformationBuilder builder);
|
|
||||||
}
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
package com.almostreliable.unified.api.recipe;
|
||||||
|
|
||||||
|
public interface RecipeUnifier {
|
||||||
|
void collectUnifier(RecipeUnifierBuilder builder);
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public interface RecipeTransformationBuilder {
|
public interface RecipeUnifierBuilder {
|
||||||
|
|
||||||
void forEachObject(String property, BiFunction<JsonObject, RecipeContext, JsonObject> consumer);
|
void forEachObject(String property, BiFunction<JsonObject, RecipeContext, JsonObject> consumer);
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.almostreliable.unified.api.recipe;
|
||||||
import com.almostreliable.unified.utils.TagMap;
|
import com.almostreliable.unified.utils.TagMap;
|
||||||
import com.almostreliable.unified.utils.UnifyTag;
|
import com.almostreliable.unified.utils.UnifyTag;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.TagKey;
|
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class RecipeDumper {
|
||||||
.append("\n");
|
.append("\n");
|
||||||
stringBuilder
|
stringBuilder
|
||||||
.append("\t\t Transformed: ")
|
.append("\t\t Transformed: ")
|
||||||
.append(recipe.getTransformed().toString())
|
.append(recipe.getUnified().toString())
|
||||||
.append("\n\n");
|
.append("\n\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class RecipeLink {
|
||||||
private final ResourceLocation type;
|
private final ResourceLocation type;
|
||||||
private final JsonObject originalRecipe;
|
private final JsonObject originalRecipe;
|
||||||
@Nullable private DuplicateLink duplicateLink;
|
@Nullable private DuplicateLink duplicateLink;
|
||||||
@Nullable private JsonObject transformedRecipe;
|
@Nullable private JsonObject unifiedRecipe;
|
||||||
|
|
||||||
public RecipeLink(ResourceLocation id, JsonObject originalRecipe) {
|
public RecipeLink(ResourceLocation id, JsonObject originalRecipe) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -95,21 +95,21 @@ public class RecipeLink {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JsonObject getTransformed() {
|
public JsonObject getUnified() {
|
||||||
return transformedRecipe;
|
return unifiedRecipe;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTransformed() {
|
public boolean isUnified() {
|
||||||
return transformedRecipe != null;
|
return unifiedRecipe != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransformed(JsonObject transformedRecipe) {
|
void setUnified(JsonObject json) {
|
||||||
Objects.requireNonNull(transformedRecipe);
|
Objects.requireNonNull(json);
|
||||||
if (isTransformed()) {
|
if (isUnified()) {
|
||||||
throw new IllegalStateException("Recipe already transformed");
|
throw new IllegalStateException("Recipe already unified");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.transformedRecipe = transformedRecipe;
|
this.unifiedRecipe = json;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getIgnoredFields() {
|
private List<String> getIgnoredFields() {
|
||||||
|
@ -127,8 +127,8 @@ public class RecipeLink {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String duplicate = duplicateLink != null ? " (duplicate)" : "";
|
String duplicate = duplicateLink != null ? " (duplicate)" : "";
|
||||||
String transformed = transformedRecipe != null ? " (transformed)" : "";
|
String unified = unifiedRecipe != null ? " (unified)" : "";
|
||||||
return String.format("['%s'] %s%s%s", type, id, duplicate, transformed);
|
return String.format("['%s'] %s%s%s", type, id, duplicate, unified);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,7 +165,7 @@ public class RecipeLink {
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonObject getActual() {
|
public JsonObject getActual() {
|
||||||
return getTransformed() != null ? getTransformed() : getOriginal();
|
return getUnified() != null ? getUnified() : getOriginal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DuplicateLink {
|
public static class DuplicateLink {
|
||||||
|
|
|
@ -45,9 +45,9 @@ public class RecipeTransformer {
|
||||||
byType.forEach((type, recipeLinks) -> {
|
byType.forEach((type, recipeLinks) -> {
|
||||||
Set<RecipeLink.DuplicateLink> duplicates = new HashSet<>(recipeLinks.size());
|
Set<RecipeLink.DuplicateLink> duplicates = new HashSet<>(recipeLinks.size());
|
||||||
for (RecipeLink curRecipe : recipeLinks) {
|
for (RecipeLink curRecipe : recipeLinks) {
|
||||||
transformRecipe(curRecipe);
|
unifyRecipe(curRecipe);
|
||||||
if (curRecipe.isTransformed()) {
|
if (curRecipe.isUnified()) {
|
||||||
recipes.put(curRecipe.getId(), curRecipe.getTransformed());
|
recipes.put(curRecipe.getId(), curRecipe.getUnified());
|
||||||
if (handleDuplicate(curRecipe, recipeLinks)) {
|
if (handleDuplicate(curRecipe, recipeLinks)) {
|
||||||
duplicates.add(curRecipe.getDuplicateLink());
|
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.
|
* Unifies a single recipe link. This method will modify the recipe link in-place.
|
||||||
* {@link RecipeHandlerFactory} will apply multiple transformations onto the recipe.
|
* {@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 {
|
try {
|
||||||
RecipeContextImpl ctx = new RecipeContextImpl(recipe.getOriginal(), replacementMap);
|
RecipeContextImpl ctx = new RecipeContextImpl(recipe.getOriginal(), replacementMap);
|
||||||
RecipeTransformationBuilderImpl builder = new RecipeTransformationBuilderImpl();
|
RecipeUnifierBuilderImpl builder = new RecipeUnifierBuilderImpl();
|
||||||
factory.fillTransformations(builder, ctx);
|
factory.fillUnifier(builder, ctx);
|
||||||
JsonObject result = builder.transform(recipe.getOriginal(), ctx);
|
JsonObject result = builder.unify(recipe.getOriginal(), ctx);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
recipe.setTransformed(result);
|
recipe.setUnified(result);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
AlmostUnified.LOG.warn("Error transforming recipe '{}': {}",
|
AlmostUnified.LOG.warn("Error unifying recipe '{}': {}",
|
||||||
recipe.getId(),
|
recipe.getId(),
|
||||||
e.getMessage());
|
e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -126,7 +126,7 @@ public class RecipeTransformer {
|
||||||
}
|
}
|
||||||
|
|
||||||
allRecipesByType.put(link.getType(), link);
|
allRecipesByType.put(link.getType(), link);
|
||||||
if (link.isTransformed()) {
|
if (link.isUnified()) {
|
||||||
unifiedRecipesByType.put(link.getType(), link);
|
unifiedRecipesByType.put(link.getType(), link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.almostreliable.unified.recipe;
|
package com.almostreliable.unified.recipe;
|
||||||
|
|
||||||
import com.almostreliable.unified.api.recipe.RecipeContext;
|
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.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
@ -11,7 +11,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class RecipeTransformationBuilderImpl implements RecipeTransformationBuilder {
|
public class RecipeUnifierBuilderImpl implements RecipeUnifierBuilder {
|
||||||
private final Map<String, Entry<?>> consumers = new HashMap<>();
|
private final Map<String, Entry<?>> consumers = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -42,7 +42,7 @@ public class RecipeTransformationBuilderImpl implements RecipeTransformationBuil
|
||||||
consumers.put(property, new Entry<>(type, consumer));
|
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();
|
JsonObject changedValues = new JsonObject();
|
||||||
|
|
||||||
for (var e : json.entrySet()) {
|
for (var e : json.entrySet()) {
|
|
@ -4,7 +4,6 @@ import com.almostreliable.unified.api.recipe.ReplacementFallbackStrategy;
|
||||||
import com.almostreliable.unified.utils.TagMap;
|
import com.almostreliable.unified.utils.TagMap;
|
||||||
import com.almostreliable.unified.utils.UnifyTag;
|
import com.almostreliable.unified.utils.UnifyTag;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.TagKey;
|
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package com.almostreliable.unified.recipe.handler;
|
package com.almostreliable.unified.recipe.handler;
|
||||||
|
|
||||||
import com.almostreliable.unified.api.recipe.RecipeConstants;
|
import com.almostreliable.unified.api.recipe.RecipeConstants;
|
||||||
import com.almostreliable.unified.api.recipe.RecipeHandler;
|
import com.almostreliable.unified.api.recipe.RecipeUnifier;
|
||||||
import com.almostreliable.unified.api.recipe.RecipeTransformationBuilder;
|
import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class GenericRecipeHandler implements RecipeHandler {
|
public class GenericRecipeUnifier implements RecipeUnifier {
|
||||||
public static final GenericRecipeHandler INSTANCE = new GenericRecipeHandler();
|
public static final GenericRecipeUnifier INSTANCE = new GenericRecipeUnifier();
|
||||||
private final Set<String> inputKeys = Set.of(RecipeConstants.INPUT,
|
private final Set<String> inputKeys = Set.of(RecipeConstants.INPUT,
|
||||||
RecipeConstants.INGREDIENT,
|
RecipeConstants.INGREDIENT,
|
||||||
RecipeConstants.INGREDIENTS);
|
RecipeConstants.INGREDIENTS);
|
||||||
|
@ -16,7 +16,7 @@ public class GenericRecipeHandler implements RecipeHandler {
|
||||||
RecipeConstants.RESULTS);
|
RecipeConstants.RESULTS);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collectTransformations(RecipeTransformationBuilder builder) {
|
public void collectUnifier(RecipeUnifierBuilder builder) {
|
||||||
for (String inputKey : inputKeys) {
|
for (String inputKey : inputKeys) {
|
||||||
builder.put(inputKey, (json, ctx) -> ctx.createIngredientReplacement(json));
|
builder.put(inputKey, (json, ctx) -> ctx.createIngredientReplacement(json));
|
||||||
}
|
}
|
|
@ -1,42 +1,42 @@
|
||||||
package com.almostreliable.unified.recipe.handler;
|
package com.almostreliable.unified.recipe.handler;
|
||||||
|
|
||||||
import com.almostreliable.unified.api.recipe.RecipeContext;
|
import com.almostreliable.unified.api.recipe.RecipeContext;
|
||||||
import com.almostreliable.unified.api.recipe.RecipeHandler;
|
import com.almostreliable.unified.api.recipe.RecipeUnifier;
|
||||||
import com.almostreliable.unified.api.recipe.RecipeTransformationBuilder;
|
import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class RecipeHandlerFactory {
|
public class RecipeHandlerFactory {
|
||||||
private final Map<ResourceLocation, RecipeHandler> transformersByType = new HashMap<>();
|
private final Map<ResourceLocation, RecipeUnifier> transformersByType = new HashMap<>();
|
||||||
private final Map<String, RecipeHandler> transformersByModId = new HashMap<>();
|
private final Map<String, RecipeUnifier> transformersByModId = new HashMap<>();
|
||||||
|
|
||||||
public void fillTransformations(RecipeTransformationBuilder builder, RecipeContext context) {
|
public void fillUnifier(RecipeUnifierBuilder builder, RecipeContext context) {
|
||||||
GenericRecipeHandler.INSTANCE.collectTransformations(builder);
|
GenericRecipeUnifier.INSTANCE.collectUnifier(builder);
|
||||||
|
|
||||||
if (context.hasProperty(ShapedRecipeKeyHandler.PATTERN_PROPERTY) &&
|
if (context.hasProperty(ShapedRecipeKeyUnifier.PATTERN_PROPERTY) &&
|
||||||
context.hasProperty(ShapedRecipeKeyHandler.KEY_PROPERTY)) {
|
context.hasProperty(ShapedRecipeKeyUnifier.KEY_PROPERTY)) {
|
||||||
ShapedRecipeKeyHandler.INSTANCE.collectTransformations(builder);
|
ShapedRecipeKeyUnifier.INSTANCE.collectUnifier(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceLocation type = context.getType();
|
ResourceLocation type = context.getType();
|
||||||
RecipeHandler byMod = transformersByModId.get(type.getNamespace());
|
RecipeUnifier byMod = transformersByModId.get(type.getNamespace());
|
||||||
if (byMod != null) {
|
if (byMod != null) {
|
||||||
byMod.collectTransformations(builder);
|
byMod.collectUnifier(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
RecipeHandler byType = transformersByType.get(type);
|
RecipeUnifier byType = transformersByType.get(type);
|
||||||
if (byType != null) {
|
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);
|
transformersByType.put(type, transformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerForMod(String mod, RecipeHandler transformer) {
|
public void registerForMod(String mod, RecipeUnifier transformer) {
|
||||||
transformersByModId.put(mod, transformer);
|
transformersByModId.put(mod, transformer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
package com.almostreliable.unified.recipe.handler;
|
package com.almostreliable.unified.recipe.handler;
|
||||||
|
|
||||||
import com.almostreliable.unified.api.recipe.RecipeHandler;
|
import com.almostreliable.unified.api.recipe.RecipeUnifier;
|
||||||
import com.almostreliable.unified.api.recipe.RecipeTransformationBuilder;
|
import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
public class ShapedRecipeKeyHandler implements RecipeHandler {
|
public class ShapedRecipeKeyUnifier implements RecipeUnifier {
|
||||||
public static final RecipeHandler INSTANCE = new ShapedRecipeKeyHandler();
|
public static final RecipeUnifier INSTANCE = new ShapedRecipeKeyUnifier();
|
||||||
public static final String PATTERN_PROPERTY = "pattern";
|
public static final String PATTERN_PROPERTY = "pattern";
|
||||||
public static final String KEY_PROPERTY = "key";
|
public static final String KEY_PROPERTY = "key";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collectTransformations(RecipeTransformationBuilder builder) {
|
public void collectUnifier(RecipeUnifierBuilder builder) {
|
||||||
builder.put(KEY_PROPERTY, JsonObject.class, (json, context) -> {
|
builder.put(KEY_PROPERTY, JsonObject.class, (json, context) -> {
|
||||||
for (var entry : json.entrySet()) {
|
for (var entry : json.entrySet()) {
|
||||||
JsonElement result = context.createIngredientReplacement(entry.getValue());
|
JsonElement result = context.createIngredientReplacement(entry.getValue());
|
|
@ -9,6 +9,10 @@ public class JsonQuery {
|
||||||
|
|
||||||
private final JsonElement element;
|
private final JsonElement element;
|
||||||
|
|
||||||
|
JsonQuery(JsonElement element) {
|
||||||
|
this.element = element;
|
||||||
|
}
|
||||||
|
|
||||||
public static JsonQuery of(JsonElement element) {
|
public static JsonQuery of(JsonElement element) {
|
||||||
return new JsonQuery(element);
|
return new JsonQuery(element);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +21,7 @@ public class JsonQuery {
|
||||||
String[] parts = path.split("/");
|
String[] parts = path.split("/");
|
||||||
JsonQuery current = of(element);
|
JsonQuery current = of(element);
|
||||||
for (String part : parts) {
|
for (String part : parts) {
|
||||||
if(StringUtils.isNumeric(part)) {
|
if (StringUtils.isNumeric(part)) {
|
||||||
current = current.get(Integer.parseInt(part));
|
current = current.get(Integer.parseInt(part));
|
||||||
} else {
|
} else {
|
||||||
current = current.get(part);
|
current = current.get(part);
|
||||||
|
@ -26,17 +30,13 @@ public class JsonQuery {
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonQuery(JsonElement element) {
|
|
||||||
this.element = element;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonQuery get(String identifier) {
|
public JsonQuery get(String identifier) {
|
||||||
if(!element.isJsonObject()) {
|
if (!element.isJsonObject()) {
|
||||||
throw new IllegalArgumentException("Expected JsonObject, got " + element.getClass());
|
throw new IllegalArgumentException("Expected JsonObject, got " + element.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonElement child = element.getAsJsonObject().get(identifier);
|
JsonElement child = element.getAsJsonObject().get(identifier);
|
||||||
if(child == null) {
|
if (child == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,12 +44,12 @@ public class JsonQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonQuery get(int index) {
|
public JsonQuery get(int index) {
|
||||||
if(!element.isJsonArray()) {
|
if (!element.isJsonArray()) {
|
||||||
throw new IllegalArgumentException("Expected JsonArray, got " + element.getClass());
|
throw new IllegalArgumentException("Expected JsonArray, got " + element.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonElement child = element.getAsJsonArray().get(index);
|
JsonElement child = element.getAsJsonArray().get(index);
|
||||||
if(child == null) {
|
if (child == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package com.almostreliable.unified.utils;
|
package com.almostreliable.unified.utils;
|
||||||
|
|
||||||
import com.almostreliable.unified.BuildConfig;
|
import com.almostreliable.unified.BuildConfig;
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.tags.TagKey;
|
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
|
@ -15,7 +15,8 @@ public class FakeResourceKeyRegistry {
|
||||||
c.setAccessible(true);
|
c.setAccessible(true);
|
||||||
return (ResourceKey<Registry<T>>) c.newInstance(new ResourceLocation("test_registry"),
|
return (ResourceKey<Registry<T>>) c.newInstance(new ResourceLocation("test_registry"),
|
||||||
new ResourceLocation(name));
|
new ResourceLocation(name));
|
||||||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
|
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
|
||||||
|
IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
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 {
|
public class ReplacementMapTests {
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ public class ReplacementMapTests {
|
||||||
TestUtils.TEST_MOD_PRIORITIES, ModConfig.DEFAULT_STONE_STRATA);
|
TestUtils.TEST_MOD_PRIORITIES, ModConfig.DEFAULT_STONE_STRATA);
|
||||||
|
|
||||||
assertEquals(map.getPreferredTagForItem(TestUtils.mod1RL("bronze_ore")), TestUtils.BRONZE_ORES_TAG);
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.almostreliable.unified;
|
package com.almostreliable.unified;
|
||||||
|
|
||||||
import com.almostreliable.unified.api.ModConstants;
|
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 com.almostreliable.unified.recipe.handler.RecipeHandlerFactory;
|
||||||
import net.minecraftforge.fml.ModList;
|
import net.minecraftforge.fml.ModList;
|
||||||
import net.minecraftforge.fml.loading.FMLLoader;
|
import net.minecraftforge.fml.loading.FMLLoader;
|
||||||
|
@ -38,7 +38,7 @@ public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
|
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
|
||||||
factory.registerForMod(ModConstants.IE, new IERecipeHandler());
|
factory.registerForMod(ModConstants.IE, new IERecipeUnifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,8 +2,8 @@ package com.almostreliable.unified.compat.ie;
|
||||||
|
|
||||||
import com.almostreliable.unified.api.recipe.RecipeConstants;
|
import com.almostreliable.unified.api.recipe.RecipeConstants;
|
||||||
import com.almostreliable.unified.api.recipe.RecipeContext;
|
import com.almostreliable.unified.api.recipe.RecipeContext;
|
||||||
import com.almostreliable.unified.api.recipe.RecipeHandler;
|
import com.almostreliable.unified.api.recipe.RecipeUnifier;
|
||||||
import com.almostreliable.unified.api.recipe.RecipeTransformationBuilder;
|
import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder;
|
||||||
import com.almostreliable.unified.utils.JsonUtils;
|
import com.almostreliable.unified.utils.JsonUtils;
|
||||||
import com.almostreliable.unified.utils.Utils;
|
import com.almostreliable.unified.utils.Utils;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
|
@ -13,14 +13,14 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class IERecipeHandler implements RecipeHandler {
|
public class IERecipeUnifier implements RecipeUnifier {
|
||||||
|
|
||||||
// From IE
|
// From IE
|
||||||
protected static final String BASE_KEY = "base_ingredient";
|
protected static final String BASE_KEY = "base_ingredient";
|
||||||
|
|
||||||
// TODO make it cleaner
|
// TODO make it cleaner
|
||||||
@Override
|
@Override
|
||||||
public void collectTransformations(RecipeTransformationBuilder builder) {
|
public void collectUnifier(RecipeUnifierBuilder builder) {
|
||||||
builder.put("input0", this::replaceIEIngredient); // alloy recipes, refinery
|
builder.put("input0", this::replaceIEIngredient); // alloy recipes, refinery
|
||||||
builder.put("input1", this::replaceIEIngredient); // alloy recipes, refinery
|
builder.put("input1", this::replaceIEIngredient); // alloy recipes, refinery
|
||||||
builder.put(RecipeConstants.INPUT,
|
builder.put(RecipeConstants.INPUT,
|
|
@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class IERecipeHandlerTest {
|
public class IERecipeUnifierTest {
|
||||||
public final Gson gson = new Gson();
|
public final Gson gson = new Gson();
|
||||||
|
|
||||||
private final ResourceLocation defaultRecipeId = new ResourceLocation("default_test_recipe");
|
private final ResourceLocation defaultRecipeId = new ResourceLocation("default_test_recipe");
|
||||||
|
@ -29,29 +29,29 @@ public class IERecipeHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
public void notMatching() {
|
public void notMatching() {
|
||||||
RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE,
|
RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE,
|
||||||
new IERecipeHandler()));
|
new IERecipeUnifier()));
|
||||||
JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class);
|
JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class);
|
||||||
RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy);
|
RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy);
|
||||||
transformer.transformRecipe(recipe);
|
transformer.unifyRecipe(recipe);
|
||||||
assertFalse(recipe.isTransformed(), "Nothing to transform, so it should be false");
|
assertFalse(recipe.isUnified(), "Nothing to transform, so it should be false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void resultTagMatches() {
|
public void resultTagMatches() {
|
||||||
RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE,
|
RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE,
|
||||||
new IERecipeHandler()));
|
new IERecipeUnifier()));
|
||||||
JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class);
|
JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class);
|
||||||
alloy
|
alloy
|
||||||
.getAsJsonObject("result")
|
.getAsJsonObject("result")
|
||||||
.getAsJsonObject("base_ingredient")
|
.getAsJsonObject("base_ingredient")
|
||||||
.addProperty("tag", TestUtils.BRONZE_ORES_TAG.location().toString());
|
.addProperty("tag", TestUtils.BRONZE_ORES_TAG.location().toString());
|
||||||
RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy);
|
RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy);
|
||||||
transformer.transformRecipe(recipe);
|
transformer.unifyRecipe(recipe);
|
||||||
|
|
||||||
assertNotEquals(recipe.getTransformed(), alloy, "Result should be different");
|
assertNotEquals(recipe.getUnified(), alloy, "Result should be different");
|
||||||
assertNotNull(recipe.getTransformed(), "Result should not be null");
|
assertNotNull(recipe.getUnified(), "Result should not be null");
|
||||||
assertNull(JsonQuery.of(recipe.getTransformed(), "result/base_ingredient/tag"), "Tag key should be removed");
|
assertNull(JsonQuery.of(recipe.getUnified(), "result/base_ingredient/tag"), "Tag key should be removed");
|
||||||
assertEquals(JsonQuery.of(recipe.getTransformed(), "result/base_ingredient/item").asString(),
|
assertEquals(JsonQuery.of(recipe.getUnified(), "result/base_ingredient/item").asString(),
|
||||||
TestUtils.mod1RL("bronze_ore").toString(),
|
TestUtils.mod1RL("bronze_ore").toString(),
|
||||||
"Result should be bronze_ore");
|
"Result should be bronze_ore");
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public class IERecipeHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
public void resultItemMatches() {
|
public void resultItemMatches() {
|
||||||
RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE,
|
RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE,
|
||||||
new IERecipeHandler()));
|
new IERecipeUnifier()));
|
||||||
JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class);
|
JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class);
|
||||||
alloy.getAsJsonObject("result").getAsJsonObject("base_ingredient").remove("tag");
|
alloy.getAsJsonObject("result").getAsJsonObject("base_ingredient").remove("tag");
|
||||||
alloy
|
alloy
|
||||||
|
@ -67,11 +67,11 @@ public class IERecipeHandlerTest {
|
||||||
.getAsJsonObject("base_ingredient")
|
.getAsJsonObject("base_ingredient")
|
||||||
.addProperty("item", TestUtils.mod3RL("bronze_ore").toString());
|
.addProperty("item", TestUtils.mod3RL("bronze_ore").toString());
|
||||||
RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy);
|
RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy);
|
||||||
transformer.transformRecipe(recipe);
|
transformer.unifyRecipe(recipe);
|
||||||
|
|
||||||
assertNotEquals(recipe.getTransformed(), alloy, "Result should be different");
|
assertNotEquals(recipe.getUnified(), alloy, "Result should be different");
|
||||||
assertNotNull(recipe.getTransformed(), "Result should not be null");
|
assertNotNull(recipe.getUnified(), "Result should not be null");
|
||||||
assertEquals(JsonQuery.of(recipe.getTransformed(), ("result/base_ingredient/item")).asString(),
|
assertEquals(JsonQuery.of(recipe.getUnified(), ("result/base_ingredient/item")).asString(),
|
||||||
TestUtils.mod1RL("bronze_ore").toString(),
|
TestUtils.mod1RL("bronze_ore").toString(),
|
||||||
"Transformer should replace bronze_ore from mod3 with bronze_ore from mod1");
|
"Transformer should replace bronze_ore from mod3 with bronze_ore from mod1");
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ public class IERecipeHandlerTest {
|
||||||
@Test
|
@Test
|
||||||
public void inputAlloyItemMatches() {
|
public void inputAlloyItemMatches() {
|
||||||
RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE,
|
RecipeTransformer transformer = TestUtils.basicTransformer(f -> f.registerForMod(ModConstants.IE,
|
||||||
new IERecipeHandler()));
|
new IERecipeUnifier()));
|
||||||
JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class);
|
JsonObject alloy = gson.fromJson(simpleAlloyRecipe, JsonObject.class);
|
||||||
alloy.getAsJsonObject("result").getAsJsonObject("base_ingredient").remove("tag");
|
alloy.getAsJsonObject("result").getAsJsonObject("base_ingredient").remove("tag");
|
||||||
alloy
|
alloy
|
||||||
|
@ -87,11 +87,11 @@ public class IERecipeHandlerTest {
|
||||||
.getAsJsonObject("base_ingredient")
|
.getAsJsonObject("base_ingredient")
|
||||||
.addProperty("item", TestUtils.mod3RL("bronze_ore").toString());
|
.addProperty("item", TestUtils.mod3RL("bronze_ore").toString());
|
||||||
RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy);
|
RecipeLink recipe = new RecipeLink(defaultRecipeId, alloy);
|
||||||
transformer.transformRecipe(recipe);
|
transformer.unifyRecipe(recipe);
|
||||||
|
|
||||||
assertNotEquals(recipe.getTransformed(), alloy, "Result should be different");
|
assertNotEquals(recipe.getUnified(), alloy, "Result should be different");
|
||||||
assertNotNull(recipe.getTransformed(), "Result should not be null");
|
assertNotNull(recipe.getUnified(), "Result should not be null");
|
||||||
assertEquals(JsonQuery.of(recipe.getTransformed(), ("result/base_ingredient/item")).asString(),
|
assertEquals(JsonQuery.of(recipe.getUnified(), ("result/base_ingredient/item")).asString(),
|
||||||
TestUtils.mod1RL("bronze_ore").toString(),
|
TestUtils.mod1RL("bronze_ore").toString(),
|
||||||
"Transformer should replace bronze_ore from mod3 with bronze_ore from mod1");
|
"Transformer should replace bronze_ore from mod3 with bronze_ore from mod1");
|
||||||
}
|
}
|
Loading…
Reference in a new issue