diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/Emc.java | 50 | ||||
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/recipe/SimplifiedRecipe.java | 20 |
2 files changed, 59 insertions, 11 deletions
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/Emc.java b/src/main/java/lv/enes/mc/eris_alchemy/Emc.java index d278bcc..cb782e5 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/Emc.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/Emc.java | |||
| @@ -64,10 +64,9 @@ public final class Emc { | |||
| 64 | return get(itemId) | 64 | return get(itemId) |
| 65 | .stream() | 65 | .stream() |
| 66 | .map(value -> { | 66 | .map(value -> { |
| 67 | if (item instanceof BlockItem blockItem) { | 67 | if (item instanceof BlockItem blockItem |
| 68 | if (blockItem.getBlock() instanceof EmcStorageBlock block) { | 68 | && blockItem.getBlock() instanceof EmcStorageBlock block) { |
| 69 | return value + block.getStoredEmc(stack); | 69 | return value + block.getStoredEmc(stack); |
| 70 | } | ||
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | return value; | 72 | return value; |
| @@ -220,11 +219,54 @@ public final class Emc { | |||
| 220 | sortedItems.stream() | 219 | sortedItems.stream() |
| 221 | .filter(id -> !VALUES.containsKey(id)) | 220 | .filter(id -> !VALUES.containsKey(id)) |
| 222 | .forEach(id -> calcEmc(id, recipes).ifPresent(v -> VALUES.put(id, OptionalDouble.of(v)))); | 221 | .forEach(id -> calcEmc(id, recipes).ifPresent(v -> VALUES.put(id, OptionalDouble.of(v)))); |
| 222 | |||
| 223 | if (ForeignUtils.isClassAvailable("earth.terrarium.chipped.common.recipes.ChippedRecipe")) { | ||
| 224 | reinitForChipped(sortedItems, recipes); | ||
| 225 | } | ||
| 226 | |||
| 223 | ErisAlchemy.LOGGER.info("Done calculating EMC values..."); | 227 | ErisAlchemy.LOGGER.info("Done calculating EMC values..."); |
| 224 | 228 | ||
| 225 | sync(); | 229 | sync(); |
| 226 | } | 230 | } |
| 227 | 231 | ||
| 232 | private static void reinitForChipped( | ||
| 233 | Set<ResourceLocation> items, | ||
| 234 | HashMap<ResourceLocation, List<SimplifiedRecipe>> recipes | ||
| 235 | ) { | ||
| 236 | items.stream() | ||
| 237 | .filter(id -> !VALUES.containsKey(id)) | ||
| 238 | .forEach(item -> { | ||
| 239 | var myRecipes = recipes.getOrDefault(item, List.of()) | ||
| 240 | .stream() | ||
| 241 | .filter(SimplifiedRecipe::fromChipped) | ||
| 242 | .toList(); | ||
| 243 | |||
| 244 | if (myRecipes.size() != 1) { | ||
| 245 | if (!myRecipes.isEmpty()) { | ||
| 246 | ErisAlchemy.LOGGER.warn("Item {} has multiple chipped recipes, skipping...", item); | ||
| 247 | } | ||
| 248 | return; | ||
| 249 | } | ||
| 250 | |||
| 251 | var recipe = myRecipes.get(0); | ||
| 252 | if (recipe.input().size() != 1) { | ||
| 253 | ErisAlchemy.LOGGER.warn("Chipped recipe for {} has multiple inputs, skipping...", item); | ||
| 254 | return; | ||
| 255 | } | ||
| 256 | |||
| 257 | var stacks = recipe.input().get(0).get().getItems(); | ||
| 258 | if (stacks.length != 1) { | ||
| 259 | ErisAlchemy.LOGGER.warn("Chipped recipe for {} has multiple stack inputs, skipping...", item); | ||
| 260 | return; | ||
| 261 | } | ||
| 262 | |||
| 263 | var inputId = ItemUtils.getId(stacks[0]); | ||
| 264 | if (VALUES.containsKey(inputId)) { | ||
| 265 | VALUES.put(item, VALUES.get(inputId)); | ||
| 266 | } | ||
| 267 | }); | ||
| 268 | } | ||
| 269 | |||
| 228 | private static void sortDps( | 270 | private static void sortDps( |
| 229 | Set<ResourceLocation> permSorted, | 271 | Set<ResourceLocation> permSorted, |
| 230 | ConsList<ResourceLocation> tmpSorted, | 272 | ConsList<ResourceLocation> tmpSorted, |
diff --git a/src/main/java/lv/enes/mc/eris_alchemy/recipe/SimplifiedRecipe.java b/src/main/java/lv/enes/mc/eris_alchemy/recipe/SimplifiedRecipe.java index 518cf89..b63e4c5 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/recipe/SimplifiedRecipe.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/recipe/SimplifiedRecipe.java | |||
| @@ -28,7 +28,12 @@ import java.util.function.Predicate; | |||
| 28 | import java.util.function.Supplier; | 28 | import java.util.function.Supplier; |
| 29 | import java.util.stream.Stream; | 29 | import java.util.stream.Stream; |
| 30 | 30 | ||
| 31 | public record SimplifiedRecipe(ItemStack output, List<ItemStack> remainder, List<Supplier<Ingredient>> input) { | 31 | public record SimplifiedRecipe( |
| 32 | ItemStack output, | ||
| 33 | List<ItemStack> remainder, | ||
| 34 | List<Supplier<Ingredient>> input, | ||
| 35 | boolean fromChipped | ||
| 36 | ) { | ||
| 32 | public static List<SimplifiedRecipe> of(Recipe<?> recipe, RegistryAccess registryAccess) { | 37 | public static List<SimplifiedRecipe> of(Recipe<?> recipe, RegistryAccess registryAccess) { |
| 33 | if (ForeignUtils.isClassAvailable("earth.terrarium.chipped.common.recipes.ChippedRecipe") | 38 | if (ForeignUtils.isClassAvailable("earth.terrarium.chipped.common.recipes.ChippedRecipe") |
| 34 | && recipe instanceof ChippedRecipe chippedRecipe) { | 39 | && recipe instanceof ChippedRecipe chippedRecipe) { |
| @@ -46,10 +51,10 @@ public record SimplifiedRecipe(ItemStack output, List<ItemStack> remainder, List | |||
| 46 | .toList(); | 51 | .toList(); |
| 47 | var outputs = items.stream().filter(isOutput).map(Item::getDefaultInstance).toList(); | 52 | var outputs = items.stream().filter(isOutput).map(Item::getDefaultInstance).toList(); |
| 48 | return outputs.stream() | 53 | return outputs.stream() |
| 49 | .flatMap( | 54 | .flatMap(output -> |
| 50 | output -> | 55 | inputs.stream() |
| 51 | inputs.stream() | 56 | .map(input -> |
| 52 | .map(input -> new SimplifiedRecipe(output, remainder, input)) | 57 | new SimplifiedRecipe(output, remainder, input, true)) |
| 53 | ); | 58 | ); |
| 54 | }) | 59 | }) |
| 55 | .toList(); | 60 | .toList(); |
| @@ -62,7 +67,8 @@ public record SimplifiedRecipe(ItemStack output, List<ItemStack> remainder, List | |||
| 62 | .stream() | 67 | .stream() |
| 63 | .filter(ingredient -> !ingredient.isEmpty()) | 68 | .filter(ingredient -> !ingredient.isEmpty()) |
| 64 | .map(x -> (Supplier<Ingredient>)() -> x) | 69 | .map(x -> (Supplier<Ingredient>)() -> x) |
| 65 | .toList() | 70 | .toList(), |
| 71 | false | ||
| 66 | )); | 72 | )); |
| 67 | } | 73 | } |
| 68 | 74 | ||
| @@ -110,7 +116,7 @@ public record SimplifiedRecipe(ItemStack output, List<ItemStack> remainder, List | |||
| 110 | var output = parseOutputOrRemainder(obj.get("output")); | 116 | var output = parseOutputOrRemainder(obj.get("output")); |
| 111 | var remainder = parseRemainders(obj.get("remainder")); | 117 | var remainder = parseRemainders(obj.get("remainder")); |
| 112 | var input = parseInputs(obj.get("input")); | 118 | var input = parseInputs(obj.get("input")); |
| 113 | return new SimplifiedRecipe(output, remainder, input); | 119 | return new SimplifiedRecipe(output, remainder, input, false); |
| 114 | } | 120 | } |
| 115 | 121 | ||
| 116 | private List<Supplier<Ingredient>> parseInputs(JsonElement el) { | 122 | private List<Supplier<Ingredient>> parseInputs(JsonElement el) { |