aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/net/glease/ggfab/api/GGFabRecipeMaps.java
blob: 039b9d2b5852ef93d20685c5d1d416a12bb354cf (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package net.glease.ggfab.api;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import net.glease.ggfab.GGItemList;
import net.minecraft.item.ItemStack;

import com.gtnewhorizons.modularui.common.widget.ProgressBar;

import gregtech.api.enums.ToolDictNames;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.recipe.RecipeMap;
import gregtech.api.recipe.RecipeMapBackend;
import gregtech.api.recipe.RecipeMapBuilder;
import gregtech.api.recipe.RecipeMetadataKey;
import gregtech.api.recipe.metadata.SimpleRecipeMetadataKey;
import gregtech.api.util.GT_Recipe;

public class GGFabRecipeMaps {

    public static final RecipeMetadataKey<ToolDictNames> OUTPUT_TYPE = SimpleRecipeMetadataKey
        .create(ToolDictNames.class, "output_type");
    public static final RecipeMetadataKey<Integer> OUTPUT_COUNT = SimpleRecipeMetadataKey
        .create(Integer.class, "output_count");
    public static final RecipeMap<RecipeMapBackend> toolCastRecipes = RecipeMapBuilder.of("ggfab.recipe.toolcast")
        .maxIO(1, 4, 1, 0)
        .minInputs(1, 1)
        .progressBar(GT_UITextures.PROGRESSBAR_ARROW, ProgressBar.Direction.RIGHT)
        .recipeEmitter(b -> {
            Optional<GT_Recipe> rr = b.noOptimize()
                .validateNoInput()
                .validateInputFluidCount(0, 1)
                .validateNoOutput()
                .validateNoOutputFluid()
                .build();
            if (!rr.isPresent()) return Collections.emptyList();
            ToolDictNames outputType = b.getMetadata(OUTPUT_TYPE);
            GT_Recipe r = rr.get();
            int outputSize = b.getMetadataOrDefault(OUTPUT_COUNT, 0);
            if (outputSize > 64 * 4 || outputSize <= 0) return Collections.emptyList();
            ItemStack shape, output;
            try {
                shape = GGItemList.valueOf("Shape_One_Use_" + outputType)
                    .get(0L);
                output = GGItemList.valueOf("One_Use_" + outputType)
                    .get(outputSize);
            } catch (IllegalArgumentException ex) {
                // this looks like python not java, but I don't have better way around this
                return Collections.emptyList();
            }
            output.stackSize = outputSize;
            List<ItemStack> outputs = new ArrayList<>();
            int maxStackSize = output.getMaxStackSize();
            while (output.stackSize > maxStackSize) outputs.add(output.splitStack(maxStackSize));
            outputs.add(output);
            r.mInputs = new ItemStack[] { shape };
            r.mOutputs = outputs.toArray(new ItemStack[0]);
            return Collections.singletonList(r);
        })
        .build();
}