@@ -105,19 +105,14 @@ private void fillContentMatchList(Map<RecipeCapability<?>, List<Content>> entrie
105105 }
106106
107107 private ActionResult handleContents () {
108- var result = handleContentsInternal (io );
109- return result ;
110- }
111-
112- private ActionResult handleContentsInternal (IO capIO ) {
113108 if (recipeContents .isEmpty ()) return ActionResult .SUCCESS ;
114- if (!capabilityProxies .containsKey (capIO )) {
109+ if (!capabilityProxies .containsKey (io )) {
115110 return ActionResult .FAIL_NO_CAPABILITIES ;
116111 }
117112
118- List <RecipeHandlerList > handlers = capabilityProxies .getOrDefault (capIO , Collections .emptyList ());
113+ List <RecipeHandlerList > handlers = capabilityProxies .getOrDefault (io , Collections .emptyList ());
119114 // Only sort for non-tick outputs
120- if (!isTick && capIO .support (IO .OUT )) {
115+ if (!isTick && io .support (IO .OUT )) {
121116 handlers .sort (RecipeHandlerList .COMPARATOR .reversed ());
122117 }
123118
@@ -128,46 +123,82 @@ private ActionResult handleContentsInternal(IO capIO) {
128123 // Specifically check distinct handlers first
129124 for (RecipeHandlerList handler : handlerGroups .getOrDefault (RecipeHandlerGroupDistinctness .BUS_DISTINCT ,
130125 Collections .emptyList ())) {
126+ // Handle the contents of this handler and also all the bypassed handlers
131127 var res = handler .handleRecipe (io , recipe , searchRecipeContents , true );
128+ for (RecipeHandlerList bypass_handler : handlerGroups .getOrDefault (
129+ RecipeHandlerGroupDistinctness .BYPASS_DISTINCT ,
130+ Collections .emptyList ())) {
131+ res = bypass_handler .handleRecipe (io , recipe , res , true );
132+ }
132133 if (res .isEmpty ()) {
133134 if (!simulated ) {
135+ // Actually consume the contents of this handler and also all the bypassed handlers
134136 handler .handleRecipe (io , recipe , recipeContents , false );
137+ for (RecipeHandlerList bypass_handler : handlerGroups .getOrDefault (
138+ RecipeHandlerGroupDistinctness .BYPASS_DISTINCT ,
139+ Collections .emptyList ())) {
140+ res = bypass_handler .handleRecipe (io , recipe , res , false );
141+ }
135142 }
136143 recipeContents .clear ();
137144 return ActionResult .SUCCESS ;
138145 }
139146 }
140147
141- // Check the others
148+ // Check the other groups. For every group, try consuming the ingredients,
149+ // see if it succeeds.
142150 for (Map .Entry <RecipeHandlerGroup , List <RecipeHandlerList >> handlerListEntry : handlerGroups .entrySet ()) {
143151 if (handlerListEntry .getKey () == RecipeHandlerGroupDistinctness .BUS_DISTINCT ) continue ;
144152
145153 // List to keep track of the remaining items for this RecipeHandlerGroup
146154 Map <RecipeCapability <?>, List <Object >> copiedRecipeContents = searchRecipeContents ;
147155 boolean found = false ;
156+
148157 for (RecipeHandlerList handler : handlerListEntry .getValue ()) {
149158 copiedRecipeContents = handler .handleRecipe (io , recipe , copiedRecipeContents , true );
150159 if (copiedRecipeContents .isEmpty ()) {
151160 found = true ;
152161 break ;
153162 }
154163 }
164+ for (RecipeHandlerList bypass_handler : handlerGroups .getOrDefault (
165+ RecipeHandlerGroupDistinctness .BYPASS_DISTINCT ,
166+ Collections .emptyList ())) {
167+ copiedRecipeContents = bypass_handler .handleRecipe (io , recipe , copiedRecipeContents , true );
168+ if (copiedRecipeContents .isEmpty ()) {
169+ found = true ;
170+ break ;
171+ }
172+ }
173+
155174 if (!found ) continue ;
156175 if (simulated ) return ActionResult .SUCCESS ;
157- // Start actually removing items, keep track of the remaining items for this RecipeHandlerGroup
176+ // Start actually removing items.
177+ // Keep track of the remaining items for this RecipeHandlerGroup
158178 copiedRecipeContents = recipeContents ;
179+ // First go through the handlers of the group
159180 for (RecipeHandlerList handler : handlerListEntry .getValue ()) {
160181 copiedRecipeContents = handler .handleRecipe (io , recipe , copiedRecipeContents , false );
161182 if (copiedRecipeContents .isEmpty ()) {
162183 recipeContents .clear ();
163184 return ActionResult .SUCCESS ;
164185 }
165186 }
187+ // Then go through the handlers that bypass the distinctness system and empty those
188+ for (RecipeHandlerList bypass_handler : handlerGroups .getOrDefault (
189+ RecipeHandlerGroupDistinctness .BYPASS_DISTINCT ,
190+ Collections .emptyList ())) {
191+ copiedRecipeContents = bypass_handler .handleRecipe (io , recipe , copiedRecipeContents , false );
192+ if (copiedRecipeContents .isEmpty ()) {
193+ recipeContents .clear ();
194+ return ActionResult .SUCCESS ;
195+ }
196+ }
166197 }
167198
168199 for (var entry : recipeContents .entrySet ()) {
169200 if (entry .getValue () != null && !entry .getValue ().isEmpty ()) {
170- return ActionResult .fail (null , entry .getKey (), capIO );
201+ return ActionResult .fail (null , entry .getKey (), io );
171202 }
172203 }
173204
0 commit comments