diff options
| author | 2024-11-03 22:07:33 +0200 | |
|---|---|---|
| committer | 2024-11-03 22:07:33 +0200 | |
| commit | dca34b61c70567727f7237b4f7e00f5030dad3af (patch) | |
| tree | 59e1fde0dc2be85e0273647eaff04b84e8ac3cca | |
| parent | Support Ad Astra fully. (diff) | |
| download | mc-eris-alchemy-dca34b61c70567727f7237b4f7e00f5030dad3af.tar.gz mc-eris-alchemy-dca34b61c70567727f7237b4f7e00f5030dad3af.tar.xz mc-eris-alchemy-dca34b61c70567727f7237b4f7e00f5030dad3af.zip | |
BREAK: Fix a bug in recipe-derived EMC calculation.
This likely changes EMC values wildly!
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/Emc.java | 14 | ||||
| -rw-r--r-- | src/main/resources/data/eris_alchemy/eris_alchemy/fake_recipes/fake_recipes.json5 | 5 |
2 files changed, 15 insertions, 4 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 cb782e5..f0b21db 100644 --- a/src/main/java/lv/enes/mc/eris_alchemy/Emc.java +++ b/src/main/java/lv/enes/mc/eris_alchemy/Emc.java | |||
| @@ -54,6 +54,8 @@ public final class Emc { | |||
| 54 | return FORMATTER.format(value); | 54 | return FORMATTER.format(value); |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | /** Returns the EMC for one item not the entire stack. | ||
| 58 | * @see #getTotal(ItemStack) */ | ||
| 57 | public static OptionalDouble get(ItemStack stack) { | 59 | public static OptionalDouble get(ItemStack stack) { |
| 58 | if (stack.isEmpty()) { | 60 | if (stack.isEmpty()) { |
| 59 | return OptionalDouble.empty(); | 61 | return OptionalDouble.empty(); |
| @@ -74,6 +76,14 @@ public final class Emc { | |||
| 74 | .findFirst(); | 76 | .findFirst(); |
| 75 | } | 77 | } |
| 76 | 78 | ||
| 79 | /** getTotal = get * count */ | ||
| 80 | public static OptionalDouble getTotal(ItemStack stack) { | ||
| 81 | return get(stack).stream() | ||
| 82 | .map(x -> x * stack.getCount()) | ||
| 83 | .filter(x -> x > 0) | ||
| 84 | .findFirst(); | ||
| 85 | } | ||
| 86 | |||
| 77 | public static OptionalDouble get(ResourceLocation itemId) { | 87 | public static OptionalDouble get(ResourceLocation itemId) { |
| 78 | return VALUES.getOrDefault(itemId, OptionalDouble.empty()); | 88 | return VALUES.getOrDefault(itemId, OptionalDouble.empty()); |
| 79 | } | 89 | } |
| @@ -133,7 +143,7 @@ public final class Emc { | |||
| 133 | 143 | ||
| 134 | private static OptionalDouble calcEmcForIngredient(Ingredient ingredient) { | 144 | private static OptionalDouble calcEmcForIngredient(Ingredient ingredient) { |
| 135 | return Arrays.stream(ingredient.getItems()) | 145 | return Arrays.stream(ingredient.getItems()) |
| 136 | .map(Emc::get) | 146 | .map(Emc::getTotal) |
| 137 | .flatMapToDouble(OptionalDouble::stream) | 147 | .flatMapToDouble(OptionalDouble::stream) |
| 138 | .average(); | 148 | .average(); |
| 139 | } | 149 | } |
| @@ -155,7 +165,7 @@ public final class Emc { | |||
| 155 | 165 | ||
| 156 | var remainderEmcOpt = recipe.remainder() | 166 | var remainderEmcOpt = recipe.remainder() |
| 157 | .stream() | 167 | .stream() |
| 158 | .map(Emc::get) | 168 | .map(Emc::getTotal) |
| 159 | .collect(new OptionalDoubleSummer()); | 169 | .collect(new OptionalDoubleSummer()); |
| 160 | 170 | ||
| 161 | if (remainderEmcOpt.isEmpty()) { | 171 | if (remainderEmcOpt.isEmpty()) { |
diff --git a/src/main/resources/data/eris_alchemy/eris_alchemy/fake_recipes/fake_recipes.json5 b/src/main/resources/data/eris_alchemy/eris_alchemy/fake_recipes/fake_recipes.json5 index 4511005..0422360 100644 --- a/src/main/resources/data/eris_alchemy/eris_alchemy/fake_recipes/fake_recipes.json5 +++ b/src/main/resources/data/eris_alchemy/eris_alchemy/fake_recipes/fake_recipes.json5 | |||
| @@ -98,11 +98,12 @@ | |||
| 98 | "count": 16 | 98 | "count": 16 |
| 99 | } | 99 | } |
| 100 | }, { | 100 | }, { |
| 101 | // Carving a pumpkin with shears | 101 | // Carving a pumpkin with shears, |
| 102 | // but one seed gets lost bcs otherwise this makes carved pumpkins be worth 0 lol | ||
| 102 | "output": "carved_pumpkin", | 103 | "output": "carved_pumpkin", |
| 103 | "remainder": { | 104 | "remainder": { |
| 104 | "item": "pumpkin_seeds", | 105 | "item": "pumpkin_seeds", |
| 105 | "count": 4 | 106 | "count": 3 |
| 106 | }, | 107 | }, |
| 107 | "input": "pumpkin" | 108 | "input": "pumpkin" |
| 108 | }, { | 109 | }, { |