11package gregtech .api .recipes .builders ;
22
3- import gregtech .api .GTValues ;
4- import gregtech .api .items .metaitem .MetaItem ;
53import gregtech .api .items .metaitem .stats .IDataItem ;
6- import gregtech .api .items .metaitem .stats .IItemBehaviour ;
74import gregtech .api .recipes .Recipe ;
85import gregtech .api .recipes .RecipeBuilder ;
96import gregtech .api .recipes .RecipeMap ;
129import gregtech .api .util .AssemblyLineManager ;
1310import gregtech .api .util .EnumValidationResult ;
1411import gregtech .api .util .GTLog ;
15- import gregtech .api .util .GTStringUtils ;
1612import gregtech .common .ConfigHolder ;
1713import net .minecraft .item .ItemStack ;
1814
2420
2521public class AssemblyLineRecipeBuilder extends RecipeBuilder <AssemblyLineRecipeBuilder > {
2622
27- public static final int DEFAULT_SCANNER_DURATION = 1200 ; // 60 secs
28- public static final int DEFAULT_SCANNER_EUT = GTValues .VA [GTValues .HV ];
29- public static final int DEFAULT_STATION_DURATION = 4000 ; // 200 secs
30- public static final int DEFAULT_STATION_EUT = GTValues .VA [GTValues .LuV ];
31-
3223 private final Collection <ResearchRecipeEntry > recipeEntries = new ArrayList <>();
3324
3425 private boolean generatingRecipes = true ;
@@ -55,7 +46,7 @@ public AssemblyLineRecipeBuilder copy() {
5546 public boolean applyProperty (@ Nonnull String key , @ Nullable Object value ) {
5647 if (key .equals (ResearchProperty .KEY )) {
5748 if (value instanceof ItemStack itemStack ) {
58- research (itemStack );
49+ scannerResearch (itemStack );
5950 return true ;
6051 }
6152 }
@@ -115,22 +106,36 @@ public AssemblyLineRecipeBuilder researchWithoutRecipe(@Nonnull String researchI
115106 return this ;
116107 }
117108
118- public AssemblyLineRecipeBuilder research (UnaryOperator <ResearchBuilder > research ) {
119- ResearchRecipeEntry entry = research .apply (new ResearchBuilder ()).build ();
109+ /**
110+ * Generates a research recipe for the Scanner.
111+ */
112+ public AssemblyLineRecipeBuilder scannerResearch (UnaryOperator <ResearchRecipeBuilder .ScannerRecipeBuilder > research ) {
113+ ResearchRecipeEntry entry = research .apply (new ResearchRecipeBuilder .ScannerRecipeBuilder ()).build ();
120114 if (applyResearchProperty (new ResearchPropertyData .ResearchEntry (entry .researchId , entry .dataStack ))) {
121115 this .recipeEntries .add (entry );
122116 }
123117 return this ;
124118 }
125119
126120 /**
127- * Generates a research recipe.
121+ * Generates a research recipe for the Scanner. All values are defaults other than the research stack .
128122 *
129123 * @param researchStack the stack to use for research
130124 * @return this
131125 */
132- public AssemblyLineRecipeBuilder research (@ Nonnull ItemStack researchStack ) {
133- return research (b -> new ResearchBuilder ().researchStack (researchStack ));
126+ public AssemblyLineRecipeBuilder scannerResearch (@ Nonnull ItemStack researchStack ) {
127+ return scannerResearch (b -> new ResearchRecipeBuilder .ScannerRecipeBuilder ().researchStack (researchStack ));
128+ }
129+
130+ /**
131+ * Generates a research recipe for the Research Station.
132+ */
133+ public AssemblyLineRecipeBuilder stationResearch (UnaryOperator <ResearchRecipeBuilder .StationRecipeBuilder > research ) {
134+ ResearchRecipeEntry entry = research .apply (new ResearchRecipeBuilder .StationRecipeBuilder ()).build ();
135+ if (applyResearchProperty (new ResearchPropertyData .ResearchEntry (entry .researchId , entry .dataStack ))) {
136+ this .recipeEntries .add (entry );
137+ }
138+ return this ;
134139 }
135140
136141 @ Nonnull
@@ -194,95 +199,4 @@ public int getCWUt() {
194199 return CWUt ;
195200 }
196201 }
197-
198- public static class ResearchBuilder {
199-
200- private ItemStack researchStack ;
201- private ItemStack dataStack ;
202- private String researchId ;
203- private int duration ;
204- private int eut ;
205- private int cwut ;
206-
207- private ResearchBuilder () {/**/ }
208-
209- public ResearchBuilder researchStack (@ Nonnull ItemStack researchStack ) {
210- if (!researchStack .isEmpty ()) {
211- this .researchStack = researchStack ;
212- }
213- return this ;
214- }
215-
216- public ResearchBuilder dataStack (@ Nonnull ItemStack dataStack ) {
217- if (!dataStack .isEmpty ()) {
218- this .dataStack = dataStack ;
219- }
220- return this ;
221- }
222-
223- public ResearchBuilder researchId (String researchId ) {
224- this .researchId = researchId ;
225- return this ;
226- }
227-
228- public ResearchBuilder duration (int duration ) {
229- this .duration = duration ;
230- return this ;
231- }
232-
233- public ResearchBuilder EUt (int eut ) {
234- this .eut = eut ;
235- return this ;
236- }
237-
238- /** If this value is greater than zero, then this recipe will be done in the Research Station instead of the Scanner */
239- public ResearchBuilder CWUt (int cwut ) {
240- this .cwut = cwut ;
241- return this ;
242- }
243-
244- private ResearchRecipeEntry build () {
245- if (researchStack == null ) {
246- throw new IllegalArgumentException ("Research stack cannot be null or empty!" );
247- }
248-
249- if (researchId == null ) {
250- researchId = GTStringUtils .itemStackToString (researchStack );
251- }
252-
253- if (dataStack == null ) {
254- dataStack = cwut > 0
255- ? AssemblyLineManager .getDefaultResearchStationItem (cwut )
256- : AssemblyLineManager .getDefaultScannerItem ();
257- }
258-
259- boolean foundBehavior = false ;
260- if (dataStack .getItem () instanceof MetaItem <?> metaItem ) {
261- for (IItemBehaviour behaviour : metaItem .getBehaviours (dataStack )) {
262- if (behaviour instanceof IDataItem ) {
263- foundBehavior = true ;
264- dataStack = dataStack .copy ();
265- dataStack .setCount (1 );
266- break ;
267- }
268- }
269- }
270- if (!foundBehavior ) {
271- throw new IllegalArgumentException ("Data ItemStack must have the IDataItem behavior" );
272- }
273-
274- if (duration <= 0 ) {
275- duration = cwut > 0
276- ? DEFAULT_STATION_DURATION
277- : DEFAULT_SCANNER_DURATION ;
278- }
279-
280- if (eut <= 0 ) {
281- eut = cwut > 0
282- ? DEFAULT_STATION_EUT
283- : DEFAULT_SCANNER_EUT ;
284- }
285- return new ResearchRecipeEntry (researchId , researchStack , dataStack , duration , eut , cwut );
286- }
287- }
288202}
0 commit comments