diff options
| author | 2024-11-03 19:29:57 +0200 | |
|---|---|---|
| committer | 2024-11-03 19:29:57 +0200 | |
| commit | 23537e09f398caf1e816454857d4e602a76318ec (patch) | |
| tree | 915dfc8e0b9830f53803d44ec4cce2c9fe53199c /src/main/java/lv/enes/mc/eris_alchemy/Emc.java | |
| parent | Increase dependency versions. (diff) | |
| download | mc-eris-alchemy-23537e09f398caf1e816454857d4e602a76318ec.tar.gz mc-eris-alchemy-23537e09f398caf1e816454857d4e602a76318ec.tar.xz mc-eris-alchemy-23537e09f398caf1e816454857d4e602a76318ec.zip | |
Support Chipped fully.
Diffstat (limited to 'src/main/java/lv/enes/mc/eris_alchemy/Emc.java')
| -rw-r--r-- | src/main/java/lv/enes/mc/eris_alchemy/Emc.java | 50 |
1 files changed, 46 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 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, |