mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-18 07:53:07 +01:00
Curse of the simulation
- Fixed fluid pipes occasionally losing fluid content when distributing to multiple containers
This commit is contained in:
parent
efdcbb4154
commit
1b602c00d5
1 changed files with 18 additions and 4 deletions
|
@ -4,6 +4,7 @@ import java.lang.ref.WeakReference;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -183,6 +184,8 @@ public class FluidNetwork {
|
|||
}
|
||||
|
||||
int flowSpeed = transferSpeed;
|
||||
Map<IFluidHandler, Integer> accumulatedFill = new IdentityHashMap<>();
|
||||
|
||||
for (boolean simulate : Iterate.trueAndFalse) {
|
||||
FluidAction action = simulate ? FluidAction.SIMULATE : FluidAction.EXECUTE;
|
||||
|
||||
|
@ -213,6 +216,7 @@ public class FluidNetwork {
|
|||
flowSpeed = transfer.getAmount();
|
||||
|
||||
List<Pair<BlockFace, LazyOptional<IFluidHandler>>> availableOutputs = new ArrayList<>(targets);
|
||||
|
||||
while (!availableOutputs.isEmpty() && transfer.getAmount() > 0) {
|
||||
int dividedTransfer = transfer.getAmount() / availableOutputs.size();
|
||||
int remainder = transfer.getAmount() % availableOutputs.size();
|
||||
|
@ -235,11 +239,21 @@ public class FluidNetwork {
|
|||
continue;
|
||||
}
|
||||
|
||||
int simulatedTransfer = toTransfer;
|
||||
if (simulate)
|
||||
simulatedTransfer += accumulatedFill.getOrDefault(targetHandler, 0);
|
||||
|
||||
FluidStack divided = transfer.copy();
|
||||
divided.setAmount(toTransfer);
|
||||
divided.setAmount(simulatedTransfer);
|
||||
int fill = targetHandler.fill(divided, action);
|
||||
|
||||
if (simulate) {
|
||||
accumulatedFill.put(targetHandler, Integer.valueOf(fill));
|
||||
fill -= simulatedTransfer - toTransfer;
|
||||
}
|
||||
|
||||
transfer.setAmount(transfer.getAmount() - fill);
|
||||
if (fill < toTransfer)
|
||||
if (fill < simulatedTransfer)
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue