11package modtweaker2 .mods .appeng .handlers ;
22
3- import static modtweaker2 .helpers .InputHelper .toIItemStack ;
4- import static modtweaker2 .helpers .InputHelper .toStack ;
5- import static modtweaker2 .helpers .StackHelper .matches ;
6-
7- import java .util .LinkedList ;
8-
3+ import appeng .api .AEApi ;
4+ import appeng .api .features .IGrinderEntry ;
5+ import appeng .core .features .registries .entries .AppEngGrinderRecipe ;
96import minetweaker .MineTweakerAPI ;
107import minetweaker .api .item .IIngredient ;
118import minetweaker .api .item .IItemStack ;
9+ import minetweaker .api .item .WeightedItemStack ;
1210import modtweaker2 .helpers .InputHelper ;
1311import modtweaker2 .helpers .LogHelper ;
1412import modtweaker2 .mods .appeng .AppliedEnergisticsHelper ;
1715import stanhebben .zenscript .annotations .Optional ;
1816import stanhebben .zenscript .annotations .ZenClass ;
1917import stanhebben .zenscript .annotations .ZenMethod ;
20- import appeng .api .AEApi ;
21- import appeng .api .features .IGrinderEntry ;
22- import appeng .core .features .registries .entries .AppEngGrinderRecipe ;
18+
19+ import java .util .LinkedList ;
20+
21+ import static modtweaker2 .helpers .InputHelper .toIItemStack ;
22+ import static modtweaker2 .helpers .InputHelper .toStack ;
23+ import static modtweaker2 .helpers .StackHelper .matches ;
2324
2425@ ZenClass ("mods.appeng.Grinder" )
2526public class Grind {
26-
27- protected static final String name = "Applied Energistics 2 Grinder" ;
2827
29- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
28+ protected static final String name = "Applied Energistics 2 Grindstone" ;
29+
30+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
31+
32+ /**
33+ * Adds a shaped recipe for the Grindstone
34+ * @param outputs
35+ * @param inputStack
36+ * @param turns
37+ */
38+ @ ZenMethod
39+ public static void addRecipe (WeightedItemStack [] outputs , IItemStack inputStack , int turns ) {
40+ IGrinderEntry recipe ;
41+ if (outputs .length == 1 )
42+ recipe = new AppEngGrinderRecipe (InputHelper .toStack (inputStack ), InputHelper .toStack (outputs [0 ].getStack ()), turns );
43+ else if (outputs .length == 2 )
44+ recipe = new AppEngGrinderRecipe (InputHelper .toStack (inputStack ), InputHelper .toStack (outputs [0 ].getStack ()), InputHelper .toStack (outputs [1 ].getStack ()), outputs [1 ].getChance (), turns );
45+ else if (outputs .length == 3 )
46+ recipe = new AppEngGrinderRecipe (InputHelper .toStack (inputStack ), InputHelper .toStack (outputs [0 ].getStack ()), InputHelper .toStack (outputs [1 ].getStack ()), InputHelper .toStack (outputs [2 ].getStack ()), outputs [1 ].getChance (), outputs [2 ].getChance (), turns );
47+ else {
48+ LogHelper .logWarning (String .format ("No more then 3 output stacks are allowed in %s. Command ignored!" , name , LogHelper .getStackDescription (toStack (inputStack ))));
49+ return ;
50+ }
51+
52+ // Check if the recipe is already present, we don't want to add duplicates
53+ for (IGrinderEntry r : AEApi .instance ().registries ().grinder ().getRecipes ()) {
54+ if (r != null && AppliedEnergisticsHelper .equals (r , recipe )) {
55+ LogHelper .logWarning (String .format ("Duplicate %s Recipe found for %s. Command ignored!" , name , LogHelper .getStackDescription (toStack (inputStack ))));
56+ return ;
57+ }
58+ }
3059
31- /**
32- * Adds a shaped recipe for the Carpenter
33- *
60+ MineTweakerAPI .apply (new Add (recipe ));
61+ }
62+
63+ /**
64+ * Adds a shaped recipe for the Grindstone
65+ *
3466 * @param outputStack - Product of the Recipe
35- * @param inputStack - Ingredient of the Recipe
67+ * @param inputStack - Ingredient of the Recipe
68+ * @param inputEnergy - Energy requirement of the Recipe
3669 * @optionalParam outputStack2 - Second product of the Recipe
3770 * @optionalParam outputStack2Chance - Chance for the acquirement of the second product
3871 * @optionalParam outputStack3 - Third product of the Recipe
3972 * @optionalParam outputStack3Chance - Chance for the acquirement of the third product
40- * @param inputEnergy - Energy requirement of the Recipe
4173 **/
42- @ ZenMethod
74+ @ Deprecated
75+ @ ZenMethod
4376 public static void addRecipe (IItemStack outputStack , IItemStack inputStack , @ Optional IItemStack outputStack2 , @ Optional float outputStack2Chance , @ Optional IItemStack outputStack3 , @ Optional float outputStack3Chance , int inputEnergy ) {
44- if (inputStack == null || outputStack == null ) {
45- LogHelper .logError (String .format ("Required parameters missing for %s Recipe." , name ));
46- return ;
47- }
48-
49- // Create recipe
50- IGrinderEntry recipe ;
51-
52- if (outputStack2 != null && outputStack3 != null )
53- recipe = new AppEngGrinderRecipe (InputHelper .toStack (inputStack ), InputHelper .toStack (outputStack ), InputHelper .toStack (outputStack2 ), InputHelper .toStack (outputStack3 ), outputStack2Chance , outputStack3Chance , inputEnergy );
54- else if (outputStack2 != null )
55- recipe = new AppEngGrinderRecipe (InputHelper .toStack (inputStack ), InputHelper .toStack (outputStack ), InputHelper .toStack (outputStack2 ), outputStack2Chance , inputEnergy );
56- else
57- recipe = new AppEngGrinderRecipe (InputHelper .toStack (inputStack ), InputHelper .toStack (outputStack ), inputEnergy );
58-
59- // Check if the recipe is already present, we don't want to add duplicates
60- for (IGrinderEntry r : AEApi .instance ().registries ().grinder ().getRecipes ()) {
61- if (r != null && AppliedEnergisticsHelper .equals (r , recipe )) {
62- LogHelper .logWarning (String .format ("Duplicate %s Recipe found for %s. Command ignored!" , name , LogHelper .getStackDescription (toStack (inputStack ))));
63- return ;
64- }
65- }
77+ if (inputStack == null || outputStack == null ) {
78+ LogHelper .logError (String .format ("Required parameters missing for %s Recipe." , name ));
79+ return ;
80+ }
81+
82+ // Create recipe
83+ IGrinderEntry recipe ;
84+
85+ if (outputStack2 != null && outputStack3 != null )
86+ recipe = new AppEngGrinderRecipe (InputHelper .toStack (inputStack ), InputHelper .toStack (outputStack ), InputHelper .toStack (outputStack2 ), InputHelper .toStack (outputStack3 ), outputStack2Chance , outputStack3Chance , inputEnergy );
87+ else if (outputStack2 != null )
88+ recipe = new AppEngGrinderRecipe (InputHelper .toStack (inputStack ), InputHelper .toStack (outputStack ), InputHelper .toStack (outputStack2 ), outputStack2Chance , inputEnergy );
89+ else
90+ recipe = new AppEngGrinderRecipe (InputHelper .toStack (inputStack ), InputHelper .toStack (outputStack ), inputEnergy );
91+
92+ // Check if the recipe is already present, we don't want to add duplicates
93+ for (IGrinderEntry r : AEApi .instance ().registries ().grinder ().getRecipes ()) {
94+ if (r != null && AppliedEnergisticsHelper .equals (r , recipe )) {
95+ LogHelper .logWarning (String .format ("Duplicate %s Recipe found for %s. Command ignored!" , name , LogHelper .getStackDescription (toStack (inputStack ))));
96+ return ;
97+ }
98+ }
6699
67100 MineTweakerAPI .apply (new Add (recipe ));
68101 }
69-
70- @ Deprecated
71- @ ZenMethod
102+
103+ @ Deprecated
104+ @ ZenMethod
72105 public static void addRecipe (IItemStack input , IItemStack output , int energy , @ Optional IItemStack output2 , @ Optional float chance2 , @ Optional IItemStack output3 , @ Optional float chance3 ) {
73- if (input == null || output == null ) {
74- LogHelper .logError (String .format ("Required parameters missing for %s Recipe." , name ));
75- return ;
76- }
77-
78- // Create recipe
79- IGrinderEntry recipe ;
80-
81- if (output2 != null && output3 != null )
82- recipe = new AppEngGrinderRecipe (InputHelper .toStack (input ), InputHelper .toStack (output ), InputHelper .toStack (output2 ), InputHelper .toStack (output3 ), chance2 , chance3 , energy );
83- else if (output2 != null )
84- recipe = new AppEngGrinderRecipe (InputHelper .toStack (input ), InputHelper .toStack (output ), InputHelper .toStack (output2 ), chance2 , energy );
85- else
86- recipe = new AppEngGrinderRecipe (InputHelper .toStack (input ), InputHelper .toStack (output ), energy );
87-
88- // Check if the recipe is already present, we don't want to add duplicates
89- for (IGrinderEntry r : AEApi .instance ().registries ().grinder ().getRecipes ()) {
90- if (r != null && AppliedEnergisticsHelper .equals (r , recipe )) {
91- LogHelper .logWarning (String .format ("Duplicate %s Recipe found for %s. Command ignored!" , name , LogHelper .getStackDescription (toStack (input ))));
92- return ;
93- }
94- }
106+ if (input == null || output == null ) {
107+ LogHelper .logError (String .format ("Required parameters missing for %s Recipe." , name ));
108+ return ;
109+ }
110+
111+ // Create recipe
112+ IGrinderEntry recipe ;
113+
114+ if (output2 != null && output3 != null )
115+ recipe = new AppEngGrinderRecipe (InputHelper .toStack (input ), InputHelper .toStack (output ), InputHelper .toStack (output2 ), InputHelper .toStack (output3 ), chance2 , chance3 , energy );
116+ else if (output2 != null )
117+ recipe = new AppEngGrinderRecipe (InputHelper .toStack (input ), InputHelper .toStack (output ), InputHelper .toStack (output2 ), chance2 , energy );
118+ else
119+ recipe = new AppEngGrinderRecipe (InputHelper .toStack (input ), InputHelper .toStack (output ), energy );
120+
121+ // Check if the recipe is already present, we don't want to add duplicates
122+ for (IGrinderEntry r : AEApi .instance ().registries ().grinder ().getRecipes ()) {
123+ if (r != null && AppliedEnergisticsHelper .equals (r , recipe )) {
124+ LogHelper .logWarning (String .format ("Duplicate %s Recipe found for %s. Command ignored!" , name , LogHelper .getStackDescription (toStack (input ))));
125+ return ;
126+ }
127+ }
95128
96129 MineTweakerAPI .apply (new Add (recipe ));
97130 }
@@ -103,46 +136,46 @@ public Add(IGrinderEntry recipe) {
103136 recipes .add (recipe );
104137 }
105138
106- @ Override
107- public String getRecipeInfo (IGrinderEntry recipe ) {
108- return LogHelper .getStackDescription (recipe .getInput ());
109- }
110-
111- @ Override
112- protected boolean equals (IGrinderEntry recipe , IGrinderEntry otherRecipe ) {
113- return AppliedEnergisticsHelper .equals (recipe , otherRecipe );
114- }
139+ @ Override
140+ public String getRecipeInfo (IGrinderEntry recipe ) {
141+ return LogHelper .getStackDescription (recipe .getInput ());
142+ }
143+
144+ @ Override
145+ protected boolean equals (IGrinderEntry recipe , IGrinderEntry otherRecipe ) {
146+ return AppliedEnergisticsHelper .equals (recipe , otherRecipe );
147+ }
115148 }
116149
117- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
150+ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
118151
119- /**
120- * Adds a shaped recipe for the Carpenter
121- *
122- * @param outputStack - Product of the Recipe
152+ /**
153+ * Removes a recipe for the Grindstone
154+ *
155+ * @param input - Product of the Recipe
123156 **/
124157 @ ZenMethod
125- public static void removeRecipe (IIngredient outputStack ) {
126- if ( outputStack == null ) {
127- LogHelper .logError (String .format ("Required parameters missing for %s Recipe." , name ));
128- return ;
129- }
130-
131- // Get list of existing recipes, matching with parameter
132- LinkedList <IGrinderEntry > result = new LinkedList <IGrinderEntry >();
133-
134- for (IGrinderEntry entry : AEApi .instance ().registries ().grinder ().getRecipes ()) {
135- if (entry != null && entry .getOutput () != null && matches (outputStack , toIItemStack (entry .getOutput ()))) {
136- result .add (entry );
137- }
138- }
139-
140- // Check if we found the recipes and apply the action
141- if (!result .isEmpty ()) {
142- MineTweakerAPI .apply (new Remove (result ));
143- } else {
144- LogHelper .logWarning (String .format ("No %s Recipe found for %s. Command ignored!" , name , outputStack .toString ()));
145- }
158+ public static void removeRecipe (IIngredient input ) {
159+ if ( input == null ) {
160+ LogHelper .logError (String .format ("Required parameters missing for %s Recipe." , name ));
161+ return ;
162+ }
163+
164+ // Get list of existing recipes, matching with parameter
165+ LinkedList <IGrinderEntry > result = new LinkedList <IGrinderEntry >();
166+
167+ for (IGrinderEntry entry : AEApi .instance ().registries ().grinder ().getRecipes ()) {
168+ if (entry != null && entry .getOutput () != null && matches (input , toIItemStack (entry .getOutput ()))) {
169+ result .add (entry );
170+ }
171+ }
172+
173+ // Check if we found the recipes and apply the action
174+ if (!result .isEmpty ()) {
175+ MineTweakerAPI .apply (new Remove (result ));
176+ } else {
177+ LogHelper .logWarning (String .format ("No %s Recipe found for %s. Command ignored!" , name , input .toString ()));
178+ }
146179 }
147180
148181 private static class Remove extends BaseListRemoval <IGrinderEntry > {
@@ -152,7 +185,7 @@ public Remove(LinkedList<IGrinderEntry> recipes) {
152185
153186 @ Override
154187 public String getRecipeInfo (IGrinderEntry recipe ) {
155- return LogHelper .getStackDescription (recipe .getInput ());
188+ return LogHelper .getStackDescription (recipe .getInput ());
156189 }
157190 }
158191
0 commit comments