@@ -84,27 +84,25 @@ public void tick(ItemStack module, PipeBlockEntity tile) {
84
84
if (craft .moduleSlot == slot ) {
85
85
network .startProfile ("crafting_ingredients" );
86
86
var ingredient = craft .ingredientsToRequest .getFirst ();
87
- var toRequest = ingredient .map (l -> l .stack , s -> s ). copy () ;
87
+ var toRequest = ingredient .map (l -> l .stack , s -> s );
88
88
var dest = tile .getAvailableDestination (Direction .values (), toRequest , true , true );
89
89
if (dest != null ) {
90
90
// if we're ensuring the correct item order and the item is already on the way, don't do anything yet
91
91
if (module .get (Contents .TYPE ).insertionType != InsertionType .PER_ITEM || craft .travelingIngredients .isEmpty ()) {
92
92
var equalityTypes = ItemFilter .getEqualityTypes (tile );
93
- var requested = ingredient .map (l -> {
94
- // we can ignore the return value here since we're using a lock, so we know that the item is already waiting for us there
95
- network .requestExistingItem (l .location , tile .getBlockPos (), dest .getLeft (), l , dest .getRight (), equalityTypes );
96
- network .resolveNetworkLock (l );
97
- return toRequest ;
98
- }, s -> {
99
- var remain = network .requestExistingItem (tile .getBlockPos (), dest .getLeft (), null , dest .getRight (), equalityTypes );
100
- var ret = s .copyWithCount (s .getCount () - remain .getCount ());
101
- s .setCount (remain .getCount ());
93
+ var remain = ingredient .map (l -> {
94
+ var ret = network .requestExistingItem (l .location , tile .getBlockPos (), dest .getLeft (), l , dest .getRight (), equalityTypes );
95
+ if (ret .getCount () != l .stack .getCount ())
96
+ network .resolveNetworkLock (l );
102
97
return ret ;
103
- });
104
- if (!requested .isEmpty ()) {
105
- if (toRequest .getCount () - requested .getCount () <= 0 )
106
- craft .ingredientsToRequest .remove (ingredient );
107
- craft .travelingIngredients .add (requested );
98
+ }, s -> network .requestExistingItem (tile .getBlockPos (), dest .getLeft (), null , dest .getRight (), equalityTypes ));
99
+ // dest may be able to accept less than toRequest, so the amount that remains there also needs to be taken into account
100
+ remain .grow (toRequest .getCount () - dest .getRight ().getCount ());
101
+ if (remain .getCount () != dest .getRight ().getCount ()) {
102
+ if (!remain .isEmpty ())
103
+ craft .ingredientsToRequest .add (craft .ingredientsToRequest .indexOf (ingredient ), Either .right (remain ));
104
+ craft .ingredientsToRequest .remove (ingredient );
105
+ craft .travelingIngredients .add (toRequest .copyWithCount (toRequest .getCount () - remain .getCount ()));
108
106
craft .inProgress = true ;
109
107
}
110
108
}
0 commit comments