|
2 | 2 |
|
3 | 3 | import static gregtech.api.unification.ore.OrePrefix.*; |
4 | 4 |
|
5 | | -import gregtech.api.unification.material.Materials; |
| 5 | +import java.util.function.Consumer; |
6 | 6 |
|
7 | 7 | import net.minecraft.item.ItemStack; |
8 | 8 |
|
9 | 9 | import gregtech.api.recipes.RecipeMaps; |
| 10 | +import gregtech.api.recipes.builders.ImplosionRecipeBuilder; |
10 | 11 | import gregtech.api.unification.material.Material; |
| 12 | +import gregtech.api.unification.material.Materials; |
11 | 13 | import gregtech.api.util.GTUtility; |
12 | 14 | import gregtech.common.blocks.MetaBlocks; |
13 | 15 | import gregtech.common.items.MetaItems; |
|
16 | 18 |
|
17 | 19 | public class GTEImplosionRecipeHandler { |
18 | 20 |
|
| 21 | + private static final Consumer<ImplosionRecipeBuilder>[] EXPLOSIVES = new Consumer[] { |
| 22 | + b -> ((ImplosionRecipeBuilder) b).explosivesType(new ItemStack(MetaBlocks.POWDERBARREL, 8)), |
| 23 | + b -> ((ImplosionRecipeBuilder) b).explosivesAmount(4), |
| 24 | + b -> ((ImplosionRecipeBuilder) b).explosivesType(MetaItems.DYNAMITE.getStackForm(2)), |
| 25 | + b -> ((ImplosionRecipeBuilder) b).explosivesType(new ItemStack(MetaBlocks.ITNT)) |
| 26 | + }; |
| 27 | + |
19 | 28 | public static void add(Material inputMaterial, Material outputMaterial) { |
20 | | - if (Mods.ImplosionNoBomb.isModLoaded()) { |
21 | | - GTEImplosionNoBombRecipeHandler.add(inputMaterial, outputMaterial); |
22 | | - } else { |
23 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
24 | | - .input(dust, inputMaterial, 4) |
25 | | - .output(gem, outputMaterial, 3) |
26 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
27 | | - .explosivesType(new ItemStack(MetaBlocks.POWDERBARREL, 8)) |
28 | | - .buildAndRegister(); |
29 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
30 | | - .input(dust, inputMaterial, 4) |
31 | | - .output(gem, outputMaterial, 3) |
32 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
33 | | - .explosivesAmount(4) |
34 | | - .buildAndRegister(); |
35 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
36 | | - .input(dust, inputMaterial, 4) |
37 | | - .output(gem, outputMaterial, 3) |
38 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
39 | | - .explosivesType(MetaItems.DYNAMITE.getStackForm(2)) |
40 | | - .buildAndRegister(); |
41 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
42 | | - .input(dust, inputMaterial, 4) |
43 | | - .output(gem, outputMaterial, 3) |
44 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
45 | | - .explosivesType(new ItemStack(MetaBlocks.ITNT)) |
46 | | - .buildAndRegister(); |
47 | | - } |
| 29 | + register( |
| 30 | + builder -> builder.input(dust, inputMaterial, 4).output(gem, outputMaterial, 3), |
| 31 | + () -> GTEImplosionNoBombRecipeHandler.add(inputMaterial, outputMaterial)); |
48 | 32 | } |
49 | 33 |
|
50 | 34 | public static void add(Material inputMaterial, ItemStack outputStack) { |
51 | | - if (Mods.ImplosionNoBomb.isModLoaded()) { |
52 | | - GTEImplosionNoBombRecipeHandler.add(inputMaterial, outputStack); |
53 | | - } else { |
54 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
55 | | - .input(dust, inputMaterial, 4) |
56 | | - .outputs(GTUtility.copy(3, outputStack)) |
57 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
58 | | - .explosivesType(new ItemStack(MetaBlocks.POWDERBARREL, 8)) |
59 | | - .buildAndRegister(); |
60 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
61 | | - .input(dust, inputMaterial, 4) |
62 | | - .outputs(GTUtility.copy(3, outputStack)) |
63 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
64 | | - .explosivesAmount(4) |
65 | | - .buildAndRegister(); |
66 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
67 | | - .input(dust, inputMaterial, 4) |
68 | | - .outputs(GTUtility.copy(3, outputStack)) |
69 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
70 | | - .explosivesType(MetaItems.DYNAMITE.getStackForm(2)) |
71 | | - .buildAndRegister(); |
72 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
73 | | - .input(dust, inputMaterial, 4) |
74 | | - .outputs(GTUtility.copy(3, outputStack)) |
75 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
76 | | - .explosivesType(new ItemStack(MetaBlocks.ITNT)) |
77 | | - .buildAndRegister(); |
78 | | - } |
| 35 | + register( |
| 36 | + builder -> builder.input(dust, inputMaterial, 4).outputs(GTUtility.copy(3, outputStack)), |
| 37 | + () -> GTEImplosionNoBombRecipeHandler.add(inputMaterial, outputStack)); |
79 | 38 | } |
80 | 39 |
|
81 | 40 | public static void add(String inputOreDict, ItemStack outputStack) { |
| 41 | + register( |
| 42 | + builder -> builder.input(inputOreDict, 4).outputs(GTUtility.copy(3, outputStack)), |
| 43 | + () -> GTEImplosionNoBombRecipeHandler.add(inputOreDict, outputStack)); |
| 44 | + } |
| 45 | + |
| 46 | + private static void register(Consumer<ImplosionRecipeBuilder> recipeConfig, Runnable noBombHandler) { |
82 | 47 | if (Mods.ImplosionNoBomb.isModLoaded()) { |
83 | | - GTEImplosionNoBombRecipeHandler.add(inputOreDict, outputStack); |
| 48 | + noBombHandler.run(); |
84 | 49 | } else { |
85 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
86 | | - .input(inputOreDict, 4) |
87 | | - .outputs(GTUtility.copy(3, outputStack)) |
88 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
89 | | - .explosivesType(new ItemStack(MetaBlocks.POWDERBARREL, 8)) |
90 | | - .buildAndRegister(); |
91 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
92 | | - .input(inputOreDict, 4) |
93 | | - .outputs(GTUtility.copy(3, outputStack)) |
94 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
95 | | - .explosivesAmount(4) |
96 | | - .buildAndRegister(); |
97 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
98 | | - .input(inputOreDict, 4) |
99 | | - .outputs(GTUtility.copy(3, outputStack)) |
100 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
101 | | - .explosivesType(MetaItems.DYNAMITE.getStackForm(2)) |
102 | | - .buildAndRegister(); |
103 | | - RecipeMaps.IMPLOSION_RECIPES.recipeBuilder() |
104 | | - .input(inputOreDict, 4) |
105 | | - .outputs(GTUtility.copy(3, outputStack)) |
106 | | - .chancedOutput(dust, Materials.DarkAsh, 2500, 0) |
107 | | - .explosivesType(new ItemStack(MetaBlocks.ITNT)) |
108 | | - .buildAndRegister(); |
| 50 | + for (Consumer<ImplosionRecipeBuilder> explosive : EXPLOSIVES) { |
| 51 | + ImplosionRecipeBuilder builder = RecipeMaps.IMPLOSION_RECIPES.recipeBuilder(); |
| 52 | + recipeConfig.accept(builder); |
| 53 | + builder.chancedOutput(dust, Materials.DarkAsh, 2500, 0); |
| 54 | + explosive.accept(builder); |
| 55 | + builder.buildAndRegister(); |
| 56 | + } |
109 | 57 | } |
110 | 58 | } |
111 | 59 | } |
0 commit comments