Skip to content

Commit

Permalink
Fix Distillation Tower machines crashing (#2646)
Browse files Browse the repository at this point in the history
  • Loading branch information
krossgg authored Dec 27, 2024
1 parent ca303c5 commit c7509a3
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.gregtechceu.gtceu.api.capability.recipe.*;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.feature.IRecipeLogicMachine;
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiPart;
import com.gregtechceu.gtceu.api.machine.multiblock.PartAbility;
import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine;
import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank;
Expand Down Expand Up @@ -76,31 +77,31 @@ public void onStructureFormed() {
getDefinition().setPartSorter(Comparator.comparingInt(p -> p.self().getPos().getY()));
getDefinition().setAllowExtendedFacing(false);
super.onStructureFormed();
var parts = getParts().stream()
final int startY = getPos().getY() + yOffset;
List<IMultiPart> parts = getParts().stream()
.filter(part -> PartAbility.EXPORT_FLUIDS.isApplicable(part.self().getBlockState().getBlock()))
.filter(part -> part.self().getPos().getY() >= startY)
.toList();

if (!parts.isEmpty()) {
// Loop from controller y + offset -> highest output hatch
int y = getPos().getY() + yOffset;
// Loop from controller y + offset -> the highest output hatch
int maxY = parts.get(parts.size() - 1).self().getPos().getY();
fluidOutputs = new ObjectArrayList<>(maxY - y);
for (int outputIndex = 0; y <= maxY; ++y) {
fluidOutputs = new ObjectArrayList<>(maxY - startY);
int outputIndex = 0;
for (int y = startY; y <= maxY; ++y) {
if (parts.size() <= outputIndex) {
fluidOutputs.add(VoidFluidHandler.INSTANCE);
continue;
}

var part = parts.get(outputIndex);
if (part.self().getPos().getY() == y) {
part.getRecipeHandlers().stream()
var handler = part.getRecipeHandlers().stream()
.filter(IFluidHandler.class::isInstance)
.findFirst()
.ifPresentOrElse(h -> {
fluidOutputs.add((IFluidHandler) h);
if (firstValid == null) firstValid = (IFluidHandler) h;
},
() -> fluidOutputs.add(VoidFluidHandler.INSTANCE));
.map(IFluidHandler.class::cast)
.orElse(VoidFluidHandler.INSTANCE);
addOutput(handler);
outputIndex++;
} else if (part.self().getPos().getY() > y) {
fluidOutputs.add(VoidFluidHandler.INSTANCE);
Expand All @@ -115,6 +116,11 @@ public void onStructureFormed() {
} else onStructureInvalid();
}

private void addOutput(IFluidHandler handler) {
fluidOutputs.add(handler);
if (firstValid == null && handler != VoidFluidHandler.INSTANCE) firstValid = handler;
}

@Override
public void onStructureInvalid() {
fluidOutputs = null;
Expand Down Expand Up @@ -178,7 +184,7 @@ public Iterator<GTRecipe> searchRecipe() {
var recipeType = machine.getRecipeType();
if (recipeType == GTRecipeTypes.DISTILLERY_RECIPES) return super.searchRecipe();

// Do recipe searching ourselves so we can match the outputs how we want
// Do recipe searching ourselves, so we can match the outputs how we want
IRecipeCapabilityHolder holder = this.machine;
if (!holder.hasProxies()) return null;
var iterator = recipeType.getLookup().getRecipeIterator(holder, recipe -> !recipe.isFuel &&
Expand Down

0 comments on commit c7509a3

Please sign in to comment.