mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-30 03:25:41 -05:00
parent
54529f60b1
commit
d8b4afd57f
4 changed files with 26 additions and 6 deletions
|
@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
- added logging for cases where items are assigned to multiple unification tags
|
- added logging for cases where items are assigned to multiple unification tags
|
||||||
- added logging for cases where the recipe type can't be found
|
- added logging for cases where the recipe type can't be found
|
||||||
|
- added skipping logic for recipes with invalid recipe types
|
||||||
- added Turkish translation ([#102](https://github.com/AlmostReliable/almostunified/pull/102))
|
- added Turkish translation ([#102](https://github.com/AlmostReliable/almostunified/pull/102))
|
||||||
- fixed crash when runtime isn't loaded ([#101](https://github.com/AlmostReliable/almostunified/issues/101))
|
- fixed crash when runtime isn't loaded ([#101](https://github.com/AlmostReliable/almostunified/issues/101))
|
||||||
- fixed newly created custom tags not being considered for unification
|
- fixed newly created custom tags not being considered for unification
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.almostreliable.unified.unification.recipe;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
import com.almostreliable.unified.AlmostUnifiedCommon;
|
||||||
import com.almostreliable.unified.api.unification.recipe.RecipeData;
|
import com.almostreliable.unified.api.unification.recipe.RecipeData;
|
||||||
import com.almostreliable.unified.utils.JsonCompare;
|
import com.almostreliable.unified.utils.JsonCompare;
|
||||||
|
|
||||||
|
@ -15,19 +16,35 @@ import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class RecipeLink implements RecipeData {
|
public final class RecipeLink implements RecipeData {
|
||||||
|
|
||||||
private final ResourceLocation id;
|
private final ResourceLocation id;
|
||||||
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 unifiedRecipe;
|
@Nullable private JsonObject unifiedRecipe;
|
||||||
|
|
||||||
public RecipeLink(ResourceLocation id, JsonObject originalRecipe) {
|
private RecipeLink(ResourceLocation id, JsonObject originalRecipe, ResourceLocation type) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.originalRecipe = originalRecipe;
|
this.originalRecipe = originalRecipe;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static RecipeLink of(ResourceLocation id, JsonObject originalRecipe) {
|
||||||
|
ResourceLocation type = ResourceLocation.tryParse(originalRecipe.get("type").getAsString());
|
||||||
|
if (type == null) {
|
||||||
|
AlmostUnifiedCommon.LOGGER.warn("Could not detect recipe type for recipe '{}', skipping.", id);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RecipeLink(id, originalRecipe, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RecipeLink ofOrThrow(ResourceLocation id, JsonObject originalRecipe) {
|
||||||
try {
|
try {
|
||||||
this.type = ResourceLocation.parse(originalRecipe.get("type").getAsString());
|
ResourceLocation type = ResourceLocation.parse(originalRecipe.get("type").getAsString());
|
||||||
|
return new RecipeLink(id, originalRecipe, type);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("could not detect recipe type for recipe " + id);
|
throw new IllegalArgumentException("could not detect recipe type for recipe " + id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -111,7 +112,8 @@ public class RecipeTransformer {
|
||||||
return recipes
|
return recipes
|
||||||
.entrySet()
|
.entrySet()
|
||||||
.stream()
|
.stream()
|
||||||
.map(entry -> new RecipeLink(entry.getKey(), entry.getValue().getAsJsonObject()))
|
.map(entry -> RecipeLink.of(entry.getKey(), entry.getValue().getAsJsonObject()))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
.sorted(Comparator.comparing(entry -> entry.getId().toString()))
|
.sorted(Comparator.comparing(entry -> entry.getId().toString()))
|
||||||
.collect(Collectors.groupingByConcurrent(RecipeLink::getType));
|
.collect(Collectors.groupingByConcurrent(RecipeLink::getType));
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,11 +83,11 @@ public class TestUtils {
|
||||||
|
|
||||||
public static RecipeLink recipe(String jsonStr) {
|
public static RecipeLink recipe(String jsonStr) {
|
||||||
var json = json(jsonStr);
|
var json = json(jsonStr);
|
||||||
return new RecipeLink(ResourceLocation.parse("test"), json);
|
return RecipeLink.ofOrThrow(ResourceLocation.parse("test"), json);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RecipeLink recipe(JsonObject json) {
|
public static RecipeLink recipe(JsonObject json) {
|
||||||
return new RecipeLink(ResourceLocation.parse("test"), json);
|
return RecipeLink.ofOrThrow(ResourceLocation.parse("test"), json);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject json(String json) {
|
public static JsonObject json(String json) {
|
||||||
|
|
Loading…
Reference in a new issue