From 636815bb5d32edd0914818cfec49b680ff2c6e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salom=C3=A3o?= Date: Tue, 23 Feb 2021 21:52:42 -0300 Subject: [PATCH] Add to Air collector logic --- .../gregtech/api/situation/Situations.java | 2 ++ .../electric/MetaTileEntityAirCollector.java | 26 ++++++++++++++----- .../resources/assets/gregtech/lang/en_us.lang | 3 ++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/gregtech/api/situation/Situations.java b/src/main/java/gregtech/api/situation/Situations.java index a27f697483..08ea4273ea 100644 --- a/src/main/java/gregtech/api/situation/Situations.java +++ b/src/main/java/gregtech/api/situation/Situations.java @@ -23,6 +23,8 @@ public class Situations { public static Situation NO_EXPORT_TANK = new Situation(204, "no_export_tank", SituationTypes.ERROR); public static Situation EXPECTED_CAPABILITY_UNAVAILABLE = new Situation(205, "null_capability", SituationTypes.ERROR); public static Situation WATER_CHECK_FAILED = new Situation(206, "water_check_failed", SituationTypes.ERROR); + public static Situation BLOCKED_INTAKES = new Situation(207, "blocked_intakes", SituationTypes.ERROR); + public static Situation DIMENSION_LACKS_ATMOSPHERE = new Situation(208, "dimension_lacks_atmosphere", SituationTypes.ERROR); public static void init() { GTLog.logger.info("Registering situations..."); diff --git a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityAirCollector.java b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityAirCollector.java index 2f4d396960..baca7408e2 100644 --- a/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityAirCollector.java +++ b/src/main/java/gregtech/common/metatileentities/electric/MetaTileEntityAirCollector.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.stream.IntStream; +import static gregtech.api.situation.Situations.*; + public class MetaTileEntityAirCollector extends TieredMetaTileEntity { private static final int PRODUCTION_CYCLE_LENGTH = 20; @@ -48,12 +50,19 @@ public void update() { if (!getWorld().isRemote) { long energyToConsume = GTValues.V[getTier()]; - if (checkDimension() && checkOpenSides() && getTimer() % PRODUCTION_CYCLE_LENGTH == 0L && energyContainer.getEnergyStored() >= energyToConsume) { - int fluidAmount = getCollectedFluidAmount(); - FluidStack fluidStack = Materials.Air.getFluid(fluidAmount); - if (exportFluids.fill(fluidStack, false) == fluidAmount) { - exportFluids.fill(fluidStack, true); - energyContainer.removeEnergy(energyToConsume); + if (getTimer() % PRODUCTION_CYCLE_LENGTH == 0L ) { + if (energyContainer.getEnergyStored() >= energyToConsume) { + if (checkDimension() && checkOpenSides()) { + this.setSituation(WORKING); + int fluidAmount = getCollectedFluidAmount(); + FluidStack fluidStack = Materials.Air.getFluid(fluidAmount); + if (exportFluids.fill(fluidStack, false) == fluidAmount) { + exportFluids.fill(fluidStack, true); + energyContainer.removeEnergy(energyToConsume); + } + } + } else { + setSituation(INSUFFICIENT_POWER_TO_START); } } if (getTimer() % 5 == 0) { @@ -69,12 +78,15 @@ private boolean checkOpenSides() { if (getWorld().isAirBlock(getPos().offset(side))) return true; } + setSituation(BLOCKED_INTAKES); return false; } private boolean checkDimension() { int dimensionId = getWorld().provider.getDimension(); - return IntStream.of(ConfigHolder.machineSpecific.airCollectorDimensionBlacklist).noneMatch(x -> x == dimensionId); + boolean air = IntStream.of(ConfigHolder.machineSpecific.airCollectorDimensionBlacklist).noneMatch(x -> x == dimensionId); + if (!air) setSituation(DIMENSION_LACKS_ATMOSPHERE); + return air; } private int getCollectedFluidAmount() { diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 1713ed9cc3..fa4220ac49 100755 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -777,7 +777,8 @@ gregtech.situation.no_import_inventory=Cant access inventory to import from gregtech.situation.no_export_inventory=Cant access inventory to export to gregtech.situation.no_import_tank=Cant access tank to import from gregtech.situation.no_export_tank=Cant access tank to export to - +gregtech.situation.blocked_intakes=Blocked intakes +gregtech.situation.dimension_lacks_atmosphere=Dimension lacks atmosphere # %s is a localized material name item.material.oreprefix.oreBlackgranite=Granite %s Ore