aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/objects/ReverseShapedRecipe.java
blob: cb9e7d4d833f6952e43cfd9ea618a95863faf903 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package gregtech.api.objects;

import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import gregtech.common.tileentities.machines.basic.GT_MetaTileEntity_Disassembler;
import net.minecraft.item.ItemStack;

import java.util.Collections;
import java.util.LinkedList;
import java.util.Optional;
import java.util.Queue;

import static gregtech.api.util.GT_Recipe.GT_Recipe_Map.sDisassemblerRecipes;

public class ReverseShapedRecipe {
    private static Queue<ReverseShapedRecipe> reverseRecipes = new LinkedList<>();
    private ItemStack aResult;
    private Object[] aRecipe;

    public static Queue<ReverseShapedRecipe> getReverseRecipes() {
        return reverseRecipes;
    }

    public ReverseShapedRecipe(ItemStack output, Object[] aRecipe) {
        this.aResult = output;
        this.aRecipe = aRecipe;
        reverseRecipes.add(this);
    }

    public static void runReverseRecipes() {
        for (ReverseShapedRecipe x : reverseRecipes) {
            Optional<GT_Recipe> recipeOptional = GT_Utility.reverseShapedRecipe(x.aResult, x.aRecipe);
            if (!recipeOptional.isPresent())
                continue;
            GT_Recipe recipe = recipeOptional.get();
            ItemStack[] replacement = new ItemStack[recipe.mOutputs.length];
            GT_MetaTileEntity_Disassembler.handleRecipeTransformation(recipe.mOutputs, replacement, Collections.singleton(recipe.mOutputs));

            recipe.mOutputs = replacement;
            sDisassemblerRecipes.add(recipe);
        }
    }
}