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.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -183,6 +184,8 @@ public class FluidNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
int flowSpeed = transferSpeed;
|
int flowSpeed = transferSpeed;
|
||||||
|
Map<IFluidHandler, Integer> accumulatedFill = new IdentityHashMap<>();
|
||||||
|
|
||||||
for (boolean simulate : Iterate.trueAndFalse) {
|
for (boolean simulate : Iterate.trueAndFalse) {
|
||||||
FluidAction action = simulate ? FluidAction.SIMULATE : FluidAction.EXECUTE;
|
FluidAction action = simulate ? FluidAction.SIMULATE : FluidAction.EXECUTE;
|
||||||
|
|
||||||
|
@ -211,8 +214,9 @@ public class FluidNetwork {
|
||||||
return;
|
return;
|
||||||
if (simulate)
|
if (simulate)
|
||||||
flowSpeed = transfer.getAmount();
|
flowSpeed = transfer.getAmount();
|
||||||
|
|
||||||
List<Pair<BlockFace, LazyOptional<IFluidHandler>>> availableOutputs = new ArrayList<>(targets);
|
List<Pair<BlockFace, LazyOptional<IFluidHandler>>> availableOutputs = new ArrayList<>(targets);
|
||||||
|
|
||||||
while (!availableOutputs.isEmpty() && transfer.getAmount() > 0) {
|
while (!availableOutputs.isEmpty() && transfer.getAmount() > 0) {
|
||||||
int dividedTransfer = transfer.getAmount() / availableOutputs.size();
|
int dividedTransfer = transfer.getAmount() / availableOutputs.size();
|
||||||
int remainder = transfer.getAmount() % availableOutputs.size();
|
int remainder = transfer.getAmount() % availableOutputs.size();
|
||||||
|
@ -234,12 +238,22 @@ public class FluidNetwork {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int simulatedTransfer = toTransfer;
|
||||||
|
if (simulate)
|
||||||
|
simulatedTransfer += accumulatedFill.getOrDefault(targetHandler, 0);
|
||||||
|
|
||||||
FluidStack divided = transfer.copy();
|
FluidStack divided = transfer.copy();
|
||||||
divided.setAmount(toTransfer);
|
divided.setAmount(simulatedTransfer);
|
||||||
int fill = targetHandler.fill(divided, action);
|
int fill = targetHandler.fill(divided, action);
|
||||||
|
|
||||||
|
if (simulate) {
|
||||||
|
accumulatedFill.put(targetHandler, Integer.valueOf(fill));
|
||||||
|
fill -= simulatedTransfer - toTransfer;
|
||||||
|
}
|
||||||
|
|
||||||
transfer.setAmount(transfer.getAmount() - fill);
|
transfer.setAmount(transfer.getAmount() - fill);
|
||||||
if (fill < toTransfer)
|
if (fill < simulatedTransfer)
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue