22
33import appeng .api .networking .crafting .ICraftingGrid ;
44import appeng .api .storage .data .IAEItemStack ;
5- import appeng .crafting .CraftBranchFailure ;
65import appeng .crafting .CraftingJob ;
76import appeng .crafting .CraftingTreeNode ;
87import appeng .crafting .MECraftingInventory ;
@@ -53,30 +52,42 @@ public void record(MECraftingInventory instance, IAEItemStack what, Operation<Vo
5352 original .call (instance , what );
5453 }
5554
55+ @ Unique
56+ private boolean r$specialDeficiency ;
57+
58+ @ Intrinsic
59+ public IAEItemStack getWaitingItem () {
60+ return r$wait ;
61+ }
62+
5663 @ Inject (method = "run" , at = @ At (value = "INVOKE" , target = "Lappeng/crafting/CraftingTreeNode;request(Lappeng/crafting/MECraftingInventory;JLappeng/api/networking/security/IActionSource;)Lappeng/api/storage/data/IAEItemStack;" , shift = At .Shift .AFTER , ordinal = 0 ))
57- public void supplementaryOutput (CallbackInfo ci , @ Share ("rcOutput" ) LocalLongRef stackLocalRef ) throws CraftBranchFailure {
64+ public void supplementaryOutput (CallbackInfo ci , @ Share ("rcOutput" ) LocalLongRef stackLocalRef ) {
65+ var tree = (AccessorCraftingTreeNode ) this .tree ;
66+ if (tree .isCanEmit ()) return ;
5867 final long out = stackLocalRef .get ();
5968 if (out > 0 ) {
6069 for (var details : this .cc .getCraftingFor (this .output , null , 0 , this .world )) {
70+ IAEItemStack repeatInput = this .output .copy ().setStackSize (0 );
71+ for (var input : details .getCondensedInputs ()) {
72+ if (this .output .equals (input )) {
73+ repeatInput .incStackSize (input .getStackSize ());
74+ }
75+ }
76+ if (repeatInput .getStackSize () == 0 ) return ;
77+
6178 IAEItemStack repeatOutput = this .output .copy ().setStackSize (0 );
6279 for (var input : details .getCondensedOutputs ()) {
6380 if (this .output .equals (input )) {
64- repeatOutput .setStackSize ( repeatOutput . getStackSize () + input .getStackSize ());
81+ repeatOutput .incStackSize ( input .getStackSize ());
6582 }
6683 }
6784 if (repeatOutput .getStackSize () == 0 ) return ;
6885
6986 long outputQuantity = this .output .getStackSize () / repeatOutput .getStackSize ();
7087 if (this .output .getStackSize () % repeatOutput .getStackSize () != 0 ) ++outputQuantity ;
88+ repeatInput .setStackSize (repeatInput .getStackSize () * outputQuantity );
7189
72- IAEItemStack repeatInput = this .output .copy ().setStackSize (0 );
73- for (var input : details .getCondensedInputs ()) {
74- if (this .output .equals (input )) {
75- repeatInput .setStackSize (repeatInput .getStackSize () + (input .getStackSize () * outputQuantity ));
76- }
77- }
7890 if (repeatInput .getStackSize () > 0 ) {
79- var tree = (AccessorCraftingTreeNode ) this .tree ;
8091 var size = Math .min (out , repeatInput .getStackSize ());
8192 tree .getUsed ().add (this .output .copy ().setStackSize (size ));
8293 r$wait = this .output .copy ().setStackSize (repeatInput .getStackSize () - size );
@@ -85,17 +96,41 @@ public void supplementaryOutput(CallbackInfo ci, @Share("rcOutput") LocalLongRef
8596 }
8697 } else {
8798 for (var details : this .cc .getCraftingFor (this .output , null , 0 , this .world )) {
99+ IAEItemStack repeatInput = this .output .copy ().setStackSize (0 );
88100 for (var input : details .getCondensedInputs ()) {
89101 if (this .output .equals (input )) {
90- throw new CraftBranchFailure ( this . output , this . output .getStackSize ());
102+ repeatInput . incStackSize ( input .getStackSize ());
91103 }
92104 }
105+ final var inputSize = repeatInput .getStackSize ();
106+ if (inputSize == 0 ) return ;
107+
108+ IAEItemStack repeatOutput = this .output .copy ().setStackSize (0 );
109+ for (var input : details .getCondensedOutputs ()) {
110+ if (this .output .equals (input )) {
111+ repeatOutput .incStackSize (input .getStackSize ());
112+ }
113+ }
114+ if (repeatOutput .getStackSize () == 0 ) return ;
115+
116+ long outputQuantity = this .output .getStackSize () / repeatOutput .getStackSize ();
117+ if (this .output .getStackSize () % repeatOutput .getStackSize () != 0 ) ++outputQuantity ;
118+ repeatInput .setStackSize (repeatInput .getStackSize () * outputQuantity + inputSize );
119+
120+ tree .setHowManyEmitted (inputSize );
121+ r$wait = this .output .copy ().setStackSize (repeatInput .getStackSize ());
122+ setSpecialDeficiency (true );
93123 }
94124 }
95125 }
96126
97127 @ Intrinsic
98- public IAEItemStack getWaitingItem () {
99- return r$wait ;
128+ public boolean isSpecialDeficiency () {
129+ return r$specialDeficiency ;
130+ }
131+
132+ @ Intrinsic
133+ public void setSpecialDeficiency (boolean b ) {
134+ r$specialDeficiency = b ;
100135 }
101136}
0 commit comments