|
9 | 9 | import gregtech.api.items.toolitem.ToolHelper; |
10 | 10 | import gregtech.api.recipes.recipes.DummyRecipe; |
11 | 11 | import gregtech.api.unification.OreDictUnifier; |
12 | | -import gregtech.api.unification.material.MarkerMaterial; |
13 | 12 | import gregtech.api.unification.material.Material; |
14 | 13 | import gregtech.api.unification.material.Materials; |
15 | 14 | import gregtech.api.unification.material.properties.PropertyKey; |
|
26 | 25 | import gregtech.common.crafting.GTShapedOreRecipe; |
27 | 26 | import gregtech.common.crafting.GTShapelessOreRecipe; |
28 | 27 | import gregtech.common.crafting.ShapedOreEnergyTransferRecipe; |
29 | | -import it.unimi.dsi.fastutil.chars.Char2IntFunction; |
30 | | -import it.unimi.dsi.fastutil.chars.Char2IntOpenHashMap; |
31 | | -import it.unimi.dsi.fastutil.objects.Object2LongMap; |
32 | | -import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; |
33 | 28 | import net.minecraft.block.Block; |
34 | 29 | import net.minecraft.inventory.InventoryCrafting; |
35 | 30 | import net.minecraft.item.Item; |
|
48 | 43 | import net.minecraftforge.registries.IForgeRegistry; |
49 | 44 | import org.apache.commons.lang3.tuple.ImmutablePair; |
50 | 45 | import org.apache.commons.lang3.tuple.Pair; |
| 46 | +import org.jetbrains.annotations.ApiStatus; |
51 | 47 |
|
52 | 48 | import javax.annotation.Nonnull; |
53 | 49 | import javax.annotation.Nullable; |
@@ -290,7 +286,7 @@ public static void addShapedRecipe(boolean withUnificationData, @Nonnull String |
290 | 286 | addRecipe(regName, result, isNBTClearing, isMirrored, recipe); |
291 | 287 |
|
292 | 288 | if (withUnificationData) { |
293 | | - OreDictUnifier.registerOre(result, getRecyclingIngredients(result.getCount(), recipe)); |
| 289 | + OreDictUnifier.registerOre(result, RecyclingHandler.getRecyclingIngredients(result.getCount(), recipe)); |
294 | 290 | } |
295 | 291 | } |
296 | 292 |
|
@@ -437,97 +433,13 @@ public static Object finalizeIngredient(@Nonnull Object ingredient) { |
437 | 433 | * @param outputCount the amount of outputs the recipe has |
438 | 434 | * @param recipe the recipe to retrieve from |
439 | 435 | * @return the recycling ingredients for a recipe |
| 436 | + * @deprecated Use {@link RecyclingHandler#getRecyclingIngredients(int, Object...)}. Will be removed in 2.9 |
440 | 437 | */ |
| 438 | + @Deprecated |
| 439 | + @ApiStatus.ScheduledForRemoval(inVersion = "2.9") |
441 | 440 | @Nullable |
442 | 441 | public static ItemMaterialInfo getRecyclingIngredients(int outputCount, @Nonnull Object... recipe) { |
443 | | - Char2IntOpenHashMap inputCountMap = new Char2IntOpenHashMap(); |
444 | | - Object2LongMap<Material> materialStacksExploded = new Object2LongOpenHashMap<>(); |
445 | | - |
446 | | - int itr = 0; |
447 | | - while (recipe[itr] instanceof String s) { |
448 | | - for (char c : s.toCharArray()) { |
449 | | - if (ToolHelper.getToolFromSymbol(c) != null) continue; // skip tools |
450 | | - int count = inputCountMap.getOrDefault(c, 0); |
451 | | - inputCountMap.put(c, count + 1); |
452 | | - } |
453 | | - itr++; |
454 | | - } |
455 | | - |
456 | | - char lastChar = ' '; |
457 | | - for (int i = itr; i < recipe.length; i++) { |
458 | | - Object ingredient = recipe[i]; |
459 | | - |
460 | | - // Track the current working ingredient symbol |
461 | | - if (ingredient instanceof Character) { |
462 | | - lastChar = (char) ingredient; |
463 | | - continue; |
464 | | - } |
465 | | - |
466 | | - // Should never happen if recipe is formatted correctly |
467 | | - // In the case that it isn't, this error should be handled |
468 | | - // by an earlier method call parsing the recipe. |
469 | | - if (lastChar == ' ') return null; |
470 | | - |
471 | | - ItemStack stack; |
472 | | - if (ingredient instanceof MetaItem.MetaValueItem) { |
473 | | - stack = ((MetaItem<?>.MetaValueItem) ingredient).getStackForm(); |
474 | | - } else if (ingredient instanceof UnificationEntry) { |
475 | | - stack = OreDictUnifier.get((UnificationEntry) ingredient); |
476 | | - } else if (ingredient instanceof ItemStack) { |
477 | | - stack = (ItemStack) ingredient; |
478 | | - } else if (ingredient instanceof Item) { |
479 | | - stack = new ItemStack((Item) ingredient, 1); |
480 | | - } else if (ingredient instanceof Block) { |
481 | | - stack = new ItemStack((Block) ingredient, 1); |
482 | | - } else if (ingredient instanceof String) { |
483 | | - stack = OreDictUnifier.get((String) ingredient); |
484 | | - } else continue; // throw out bad entries |
485 | | - |
486 | | - // First try to get ItemMaterialInfo |
487 | | - ItemMaterialInfo info = OreDictUnifier.getMaterialInfo(stack); |
488 | | - if (info != null) { |
489 | | - for (MaterialStack ms : info.getMaterials()) { |
490 | | - if (!(ms.material instanceof MarkerMaterial)) { |
491 | | - addMaterialStack(materialStacksExploded, inputCountMap, ms, lastChar); |
492 | | - } |
493 | | - } |
494 | | - continue; |
495 | | - } |
496 | | - |
497 | | - // Then try to get a single Material (UnificationEntry needs this, for example) |
498 | | - MaterialStack materialStack = OreDictUnifier.getMaterial(stack); |
499 | | - if (materialStack != null && !(materialStack.material instanceof MarkerMaterial)) { |
500 | | - addMaterialStack(materialStacksExploded, inputCountMap, materialStack, lastChar); |
501 | | - } |
502 | | - |
503 | | - // Gather any secondary materials if this item has an OrePrefix |
504 | | - OrePrefix prefix = OreDictUnifier.getPrefix(stack); |
505 | | - if (prefix != null && !prefix.secondaryMaterials.isEmpty()) { |
506 | | - for (MaterialStack ms : prefix.secondaryMaterials) { |
507 | | - addMaterialStack(materialStacksExploded, inputCountMap, ms, lastChar); |
508 | | - } |
509 | | - } |
510 | | - } |
511 | | - |
512 | | - return new ItemMaterialInfo(materialStacksExploded.entrySet().stream() |
513 | | - .map(e -> new MaterialStack(e.getKey(), e.getValue() / outputCount)) |
514 | | - .sorted(Comparator.comparingLong(m -> -m.amount)) |
515 | | - .collect(Collectors.toList()) |
516 | | - ); |
517 | | - } |
518 | | - |
519 | | - /** |
520 | | - * Adds a MaterialStack to a map of {@code <Material, Quantity>} |
521 | | - * |
522 | | - * @param materialStacksExploded the map to add to |
523 | | - * @param inputCountMap the map supplying quantities by char |
524 | | - * @param ms the stack to add |
525 | | - * @param c the char for quantities |
526 | | - */ |
527 | | - private static void addMaterialStack(@Nonnull Object2LongMap<Material> materialStacksExploded, |
528 | | - @Nonnull Char2IntFunction inputCountMap, @Nonnull MaterialStack ms, char c) { |
529 | | - long amount = materialStacksExploded.getOrDefault(ms.material, 0L); |
530 | | - materialStacksExploded.put(ms.material, (ms.amount * inputCountMap.get(c)) + amount); |
| 442 | + return RecyclingHandler.getRecyclingIngredients(outputCount, recipe); |
531 | 443 | } |
532 | 444 |
|
533 | 445 | /** |
|
0 commit comments