Skip to content

Commit

Permalink
fix(PipeSystem): fluid transport in pipe router
Browse files Browse the repository at this point in the history
  • Loading branch information
vvvbbbcz committed Sep 19, 2024
1 parent b631dc2 commit 8113c32
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions src/api/java/net/industrybase/api/pipe/unit/PipeRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,38 +115,56 @@ public void addTick(ArrayDeque<PipeUnit> tasks, ArrayDeque<PipeUnit> next, Direc
if (this.fullTick()) { // TODO
double minPressure = Double.MAX_VALUE;
ArrayList<Direction> minDirections = new ArrayList<>(6);
ArrayList<Direction> tickAboveZero = new ArrayList<>(6);
ArrayList<Direction> tickBelowZero = new ArrayList<>(6);

// check
for (Direction value : Direction.values()) {
double neighborPressure = this.neighborPressures[value.ordinal()];
if (this.ticks[value.ordinal()] > 0.0D) {
if (neighborPressure > 0.0D && neighborPressure < minPressure) {
minPressure = neighborPressure;
minDirections.clear();
minDirections.add(value);
} else if (neighborPressure == minPressure) {
minDirections.add(value);
int valueIndex = value.ordinal();
double neighborPressure = this.neighborPressures[valueIndex];

if (this.neighbors[valueIndex] != null) {
if (this.ticks[valueIndex] > 0.0D) {
tickAboveZero.add(value);

if (neighborPressure > 0.0D && neighborPressure < minPressure) {
minPressure = neighborPressure;
minDirections.clear();
minDirections.add(value);
} else if (neighborPressure == minPressure) {
minDirections.add(value);
}
} else {
tickBelowZero.add(value);
}
}

}

// reset ticks
minDirections.forEach(value -> {
int valueIndex = value.ordinal();
this.totalTick = this.ticks[valueIndex];
this.totalTick -= this.ticks[valueIndex];
this.ticks[valueIndex] = 0.0D;
}); // reset ticks
});

if (minDirections.isEmpty()) return; // if not neighbor pressure above 0.0D

for (Direction value : Direction.values()) {
if (this.ticks[value.ordinal()] > 0.0D) {
this.setPressure(next, tasks, direction, minPressure);
}
if (value != Direction.UP) {
if (value != direction) {
this.setPressure(next, tasks, value, minPressure);
// execute set pressure
for (Direction below : tickBelowZero) {
this.setPressure(next, tasks, below, minPressure);
}

for (Direction above : tickAboveZero) {
if (this.neighborPressures[above.ordinal()] > minPressure) {
this.setPressure(next, tasks, above, minPressure);
} else {
if (tickBelowZero.isEmpty()) {
this.setPressure(next, tasks, above, minPressure);
}
PipeUnit neighbor = this.neighbors[value.ordinal()];
nonUpPressure += neighbor == null ? 0.0D : this.neighborPressures[value.getOpposite().ordinal()];
}

nonUpPressure += this.neighborPressures[above.getOpposite().ordinal()];
}
}
if (this.full()) {
Expand Down

0 comments on commit 8113c32

Please sign in to comment.