Skip to content

Commit 9ddb6d4

Browse files
committed
Add dual input support (fixes #10)
1 parent 97829c7 commit 9ddb6d4

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/main/java/net/neganote/gtutilities/common/machine/multiblock/PTERBMachine.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiPart;
1818
import com.gregtechceu.gtceu.api.machine.multiblock.PartAbility;
1919
import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine;
20+
import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank;
2021
import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic;
2122
import com.gregtechceu.gtceu.api.misc.EnergyContainerList;
2223
import com.gregtechceu.gtceu.api.pattern.TraceabilityPredicate;
2324
import com.gregtechceu.gtceu.api.recipe.ingredient.FluidIngredient;
2425
import com.gregtechceu.gtceu.common.data.GTItems;
26+
import com.gregtechceu.gtceu.common.machine.multiblock.part.DualHatchPartMachine;
2527
import com.gregtechceu.gtceu.common.machine.multiblock.part.FluidHatchPartMachine;
2628
import com.gregtechceu.gtceu.config.ConfigHolder;
2729
import com.gregtechceu.gtceu.utils.FormattingUtil;
@@ -41,7 +43,6 @@
4143
import net.minecraft.server.level.ServerLevel;
4244
import net.minecraft.world.entity.player.Player;
4345
import net.minecraft.world.level.block.Block;
44-
import net.minecraftforge.fluids.FluidStack;
4546
import net.neganote.gtutilities.common.materials.UtilMaterials;
4647
import net.neganote.gtutilities.config.UtilConfig;
4748
import net.neganote.gtutilities.saveddata.PTERBSavedData;
@@ -129,15 +130,22 @@ public void convertEnergyTick() {
129130
if (isWorkingEnabled() && getRecipeLogic().getStatus() == RecipeLogic.Status.WORKING &&
130131
UtilConfig.coolantEnabled() && coolantTimer == 0 && frequency != 0) {
131132

132-
FluidHatchPartMachine coolantHatch = Objects.requireNonNull(
133-
(FluidHatchPartMachine) getMachine(Objects.requireNonNull(getLevel()), coolantHatchPos));
133+
MetaMachine coolantHatch = Objects
134+
.requireNonNull(getMachine(Objects.requireNonNull(getLevel()), coolantHatchPos));
134135

135-
FluidStack coolant = coolantHatch.tank.getFluidInTank(0);
136-
if (coolant.getFluid() == UtilMaterials.QuantumCoolant.getFluid() && coolant.getAmount() >= coolantDrain) {
137-
coolantHatch.tank.handleRecipe(IO.IN, null,
138-
List.of(FluidIngredient.of(coolantDrain, UtilMaterials.QuantumCoolant.getFluid())), null,
139-
false);
136+
NotifiableFluidTank tank;
137+
138+
if (coolantHatch instanceof FluidHatchPartMachine fluidHatch) {
139+
tank = fluidHatch.tank;
140+
} else if (coolantHatch instanceof DualHatchPartMachine dualHatch) {
141+
tank = dualHatch.tank;
140142
} else {
143+
throw new IllegalStateException("Tank must be a valid fluid or dual input hatch");
144+
}
145+
146+
var ingredient = FluidIngredient.of(coolantDrain, UtilMaterials.QuantumCoolant.getFluid());
147+
List<FluidIngredient> left = tank.handleRecipe(IO.IN, null, List.of(ingredient), null, false);
148+
if (left != null && !left.isEmpty()) {
141149
if (!ConfigHolder.INSTANCE.machines.harmlessActiveTransformers) {
142150
explode();
143151
} else {
@@ -225,6 +233,9 @@ public void onStructureFormed() {
225233
if (part instanceof FluidHatchPartMachine machine) {
226234
this.coolantHatchPos = machine.getPos();
227235
continue;
236+
} else if (part instanceof DualHatchPartMachine machine) {
237+
this.coolantHatchPos = machine.getPos();
238+
continue;
228239
}
229240
IO io = ioMap.getOrDefault(part.self().getPos().asLong(), IO.BOTH);
230241
if (io == IO.NONE) continue;

0 commit comments

Comments
 (0)