Skip to content

Commit f97013d

Browse files
committed
add overloaded method
fix distinct fluids
1 parent 50785c5 commit f97013d

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

src/main/java/gregtech/api/capability/impl/MultiblockRecipeLogic.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gregtech.api.capability.impl;
22

33
import gregtech.api.GTValues;
4+
import gregtech.api.capability.DualHandler;
45
import gregtech.api.capability.IEnergyContainer;
56
import gregtech.api.capability.IMultiblockController;
67
import gregtech.api.capability.IMultipleRecipeMaps;
@@ -99,6 +100,21 @@ protected IMultipleTankHandler getInputTank() {
99100
return controller.getInputFluidInventory();
100101
}
101102

103+
/**
104+
* Overload of {@link #getInputTank()} to gather extra fluid tanks
105+
* that could exist in a distinct item handler (such as a {@link DualHandler})
106+
*
107+
* @param items Handler to gather fluid tanks from
108+
* @return a new FluidTankList with extra fluid tanks on top of the existing fluid tanks
109+
*/
110+
protected IMultipleTankHandler getInputTank(IItemHandler items) {
111+
var tanks = new ArrayList<>(getInputTank().getFluidTanks());
112+
if (items instanceof IMultipleTankHandler tankHandler) {
113+
tanks.addAll(tankHandler.getFluidTanks());
114+
}
115+
return new FluidTankList(getInputTank().allowSameFluidFill(), tanks);
116+
}
117+
102118
@Override
103119
protected IMultipleTankHandler getOutputTank() {
104120
RecipeMapMultiblockController controller = (RecipeMapMultiblockController) metaTileEntity;
@@ -222,7 +238,7 @@ protected void trySearchNewRecipeDistinct() {
222238
continue;
223239
}
224240
// Look for a new recipe after a cache miss
225-
currentRecipe = findRecipe(maxVoltage, bus, getInputTank());
241+
currentRecipe = findRecipe(maxVoltage, bus, getInputTank(bus));
226242
// Cache the current recipe, if one is found
227243
if (currentRecipe != null && checkRecipe(currentRecipe)) {
228244
this.previousRecipe = currentRecipe;
@@ -252,7 +268,7 @@ public void invalidateInputs() {
252268
}
253269

254270
protected boolean checkPreviousRecipeDistinct(IItemHandlerModifiable previousBus) {
255-
return previousRecipe != null && previousRecipe.matches(false, previousBus, getInputTank());
271+
return previousRecipe != null && previousRecipe.matches(false, previousBus, getInputTank(previousBus));
256272
}
257273

258274
protected boolean prepareRecipeDistinct(Recipe recipe) {
@@ -262,14 +278,15 @@ protected boolean prepareRecipeDistinct(Recipe recipe) {
262278
recipe = findParallelRecipe(
263279
recipe,
264280
currentDistinctInputBus,
265-
getInputTank(),
281+
getInputTank(currentDistinctInputBus),
266282
getOutputInventory(),
267283
getOutputTank(),
268284
getMaxParallelVoltage(),
269285
getParallelLimit());
270286

271287
if (recipe != null) {
272-
recipe = setupAndConsumeRecipeInputs(recipe, currentDistinctInputBus, getInputTank());
288+
recipe = setupAndConsumeRecipeInputs(recipe, currentDistinctInputBus,
289+
getInputTank(currentDistinctInputBus));
273290
if (recipe != null) {
274291
setupRecipe(recipe);
275292
return true;

src/main/java/gregtech/api/metatileentity/multiblock/RecipeMapMultiblockController.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public abstract class RecipeMapMultiblockController extends MultiblockWithDispla
4848
protected IItemHandlerModifiable outputInventory;
4949
protected IMultipleTankHandler inputFluidInventory;
5050
protected IMultipleTankHandler outputFluidInventory;
51+
protected IMultipleTankHandler extendedFluidInputs;
5152
protected IEnergyContainer energyContainer;
5253

5354
private boolean isDistinct = false;
@@ -74,7 +75,10 @@ public IItemHandlerModifiable getOutputInventory() {
7475
}
7576

7677
public IMultipleTankHandler getInputFluidInventory() {
77-
return inputFluidInventory;
78+
// if distinct, return the normal input fluid inventory,
79+
// as recipe logic handles gathering extra fluids
80+
// if not distinct, return all the fluids instead
81+
return isDistinct() ? inputFluidInventory : extendedFluidInputs;
7882
}
7983

8084
public IMultipleTankHandler getOutputFluidInventory() {
@@ -120,9 +124,12 @@ public boolean isActive() {
120124

121125
protected void initializeAbilities() {
122126
this.inputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.IMPORT_ITEMS));
123-
this.inputFluidInventory = createFluidList(MultiblockAbility.IMPORT_ITEMS, MultiblockAbility.IMPORT_FLUIDS);
127+
this.inputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(),
128+
getAbilities(MultiblockAbility.IMPORT_FLUIDS));
129+
this.extendedFluidInputs = extendedImportFluidList(this.inputFluidInventory);
124130
this.outputInventory = new ItemHandlerList(getAbilities(MultiblockAbility.EXPORT_ITEMS));
125-
this.outputFluidInventory = createFluidList(MultiblockAbility.EXPORT_ITEMS, MultiblockAbility.EXPORT_FLUIDS);
131+
this.outputFluidInventory = new FluidTankList(allowSameFluidFillForOutputs(),
132+
getAbilities(MultiblockAbility.EXPORT_FLUIDS));
126133

127134
List<IEnergyContainer> inputEnergy = new ArrayList<>(getAbilities(MultiblockAbility.INPUT_ENERGY));
128135
inputEnergy.addAll(getAbilities(MultiblockAbility.SUBSTATION_INPUT_ENERGY));
@@ -138,19 +145,17 @@ private void resetTileAbilities() {
138145
this.energyContainer = new EnergyContainerList(Lists.newArrayList());
139146
}
140147

141-
protected IMultipleTankHandler createFluidList(MultiblockAbility<IItemHandlerModifiable> items,
142-
MultiblockAbility<IFluidTank> fluids) {
143-
var tanks = new AbilityInstances(fluids);
144-
tanks.addAll(getAbilities(fluids));
145-
for (var handler : getAbilities(items)) {
148+
protected IMultipleTankHandler extendedImportFluidList(IMultipleTankHandler fluids) {
149+
List<IFluidTank> tanks = new ArrayList<>(fluids.getFluidTanks());
150+
for (var handler : getAbilities(MultiblockAbility.IMPORT_ITEMS)) {
146151
if (handler instanceof IFluidTank tank) {
147152
tanks.add(tank);
148153
} else if (handler instanceof IMultipleTankHandler multipleTankHandler) {
149154
tanks.addAll(multipleTankHandler.getFluidTanks());
150155
}
151156
}
152157

153-
return new FluidTankList(allowSameFluidFillForOutputs(), tanks.cast());
158+
return new FluidTankList(allowSameFluidFillForOutputs(), tanks);
154159
}
155160

156161
protected boolean allowSameFluidFillForOutputs() {

0 commit comments

Comments
 (0)