11package de .dafuqs .spectrum .blocks .pastel_network .network ;
22
3- import com .mojang .serialization .*;
4- import com .mojang .serialization .codecs .*;
53import de .dafuqs .spectrum .blocks .pastel_network .nodes .*;
64import de .dafuqs .spectrum .helpers .*;
75import de .dafuqs .spectrum .networking .s2c_payloads .*;
@@ -137,7 +135,6 @@ private boolean transferBetween(PastelNodeBlockEntity sourceNode, IItemHandler s
137135 proposals .put (stack , proposals .getOrDefault (stack , 0L ) + stack .getCount ());
138136 }
139137
140- // TODO: this is jank. Improve
141138 for (ItemStack stack : proposals .keySet ()) {
142139 long proposedAmount = Math .min (Math .min (proposals .get (stack ), sourceNode .getMaxTransferredAmount ()), totalAvailableStorage );
143140 if (proposedAmount == 0 )
@@ -152,28 +149,24 @@ private boolean transferBetween(PastelNodeBlockEntity sourceNode, IItemHandler s
152149
153150 Optional <PastelTransmission > transmission = createTransmissionOnValidPath (sourceNode , destinationNode , new PastelPayload .ItemPastelPayload (proposedStack .copyWithCount (simulatedAmount )), sourceNode .getTransferTime ());
154151 if (transmission .isPresent ()) {
155- int toRemove = simulatedAmount ;
156- while (toRemove > 0 ) {
157- for (ItemStack matchingStack : matchingStacks .getB ()) {
158- int amountToShrink = Math .min (toRemove , matchingStack .getCount ());
159- matchingStack .shrink (amountToShrink );
160- toRemove -= amountToShrink ;
161- }
152+ int extracted = 0 ;
153+ for (int i = 0 ; i < sourceStorage .getSlots (); i ++) {
154+ if (ItemStack .isSameItemSameComponents (proposedStack , sourceStorage .getStackInSlot (i )))
155+ extracted += sourceStorage .extractItem (i , simulatedAmount - extracted , false ).getCount ();
156+ if (extracted == simulatedAmount )
157+ break ;
162158 }
163159
164- Optional <PastelTransmission > optionalTransmission = createTransmissionOnValidPath (sourceNode , destinationNode , new PastelPayload .ItemPastelPayload (proposedStack .copyWithCount (simulatedAmount )), sourceNode .getTransferTime ());
165- if (optionalTransmission .isPresent ()) {
166- PastelTransmission trans = optionalTransmission .get ();
167- int travelTime = trans .getTransmissionDuration ();
168- this .network .addTransmission (trans , travelTime );
169- PastelTransmissionPayload .sendPastelTransmissionParticle (this .network , trans .getTransmissionDuration (), transmission .get ());
170-
171- destinationNode .markTransferred (transferMode != TransferMode .PUSH );
172- sourceNode .markTransferred (transferMode != TransferMode .PULL );
173-
174- destinationNode .addItemCountUnderway (simulatedAmount );
175- return true ;
176- }
160+ PastelTransmission trans = transmission .get ();
161+ int travelTime = trans .getTransmissionDuration ();
162+ this .network .addTransmission (trans , travelTime );
163+ PastelTransmissionPayload .sendPastelTransmissionParticle (this .network , trans .getTransmissionDuration (), transmission .get ());
164+
165+ destinationNode .markTransferred (transferMode != TransferMode .PUSH );
166+ sourceNode .markTransferred (transferMode != TransferMode .PULL );
167+
168+ destinationNode .addItemCountUnderway (simulatedAmount );
169+ return true ;
177170 }
178171 }
179172 return false ;
0 commit comments