Skip to content

Commit

Permalink
hopefully fix crash related to refinery fluid redistribution
Browse files Browse the repository at this point in the history
  • Loading branch information
desht committed Aug 8, 2024
1 parent ac7c6da commit 59f9ad3
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,22 @@ public void tickServer() {
* When this is called, there will be a valid recipe and at least two outputs present.
*/
private void redistributeFluids() {
FluidTank[] tempTanks = new FluidTank[outputCount];
for (int i = 0; i < outputCount; i++) {
int nTanks = Math.min(outputCount, currentRecipe.getOutputs().size());

FluidTank[] tempTanks = new FluidTank[nTanks];
for (int i = 0; i < nTanks; i++) {
tempTanks[i] = new FluidTank(PneumaticValues.NORMAL_TANK_CAPACITY);
}

// now scan all refineries and ensure each one has the correct output, according to the current recipe
for (int i = 0; i < outputCount && i < currentRecipe.getOutputs().size(); i++) {
for (int i = 0; i < nTanks; i++) {
final FluidStack wantedFluid = currentRecipe.getOutputs().get(i);
getOutputHandler(i).ifPresent(outputHandler -> {
FluidStack fluid = outputHandler.getFluidInTank(0);
if (!FluidStack.isSameFluidSameComponents(fluid, wantedFluid)) {
// this fluid shouldn't be here; find the appropriate output tank to move it to,
// using an intermediate temporary tank to allow for possible swapping of fluids
for (int j = 0; j < currentRecipe.getOutputs().size(); j++) {
for (int j = 0; j < nTanks; j++) {
if (FluidStack.isSameFluidSameComponents(currentRecipe.getOutputs().get(j), fluid)) {
tryMoveFluid(outputHandler, tempTanks[j]);
break;
Expand Down

0 comments on commit 59f9ad3

Please sign in to comment.