diff --git a/buildcraft_resources/assets/buildcraft/lang/en_US.lang b/buildcraft_resources/assets/buildcraft/lang/en_US.lang index 4c779f9b..5832bfe3 100644 --- a/buildcraft_resources/assets/buildcraft/lang/en_US.lang +++ b/buildcraft_resources/assets/buildcraft/lang/en_US.lang @@ -269,6 +269,8 @@ gate.trigger.time.0=Night gate.trigger.time.6=Morning gate.trigger.time.12=Afternoon gate.trigger.time.18=Evening +gate.trigger.fuelLevelBelow=Fuel level below %d%% +gate.trigger.coolantLevelBelow=Coolant level below %d%% gui.fluidtank.empty=Empty diff --git a/buildcraft_resources/assets/buildcraftenergy/textures/items/triggers/trigger_coolant_below_threshold.png b/buildcraft_resources/assets/buildcraftenergy/textures/items/triggers/trigger_coolant_below_threshold.png new file mode 100644 index 00000000..76a29d1f Binary files /dev/null and b/buildcraft_resources/assets/buildcraftenergy/textures/items/triggers/trigger_coolant_below_threshold.png differ diff --git a/buildcraft_resources/assets/buildcraftenergy/textures/items/triggers/trigger_fuel_below_threshold.png b/buildcraft_resources/assets/buildcraftenergy/textures/items/triggers/trigger_fuel_below_threshold.png new file mode 100644 index 00000000..6feb3a48 Binary files /dev/null and b/buildcraft_resources/assets/buildcraftenergy/textures/items/triggers/trigger_fuel_below_threshold.png differ diff --git a/common/buildcraft/BuildCraftEnergy.java b/common/buildcraft/BuildCraftEnergy.java index f4ff3c82..2e78618f 100644 --- a/common/buildcraft/BuildCraftEnergy.java +++ b/common/buildcraft/BuildCraftEnergy.java @@ -74,7 +74,9 @@ import buildcraft.energy.TileEngineStone; import buildcraft.energy.fuels.CoolantManager; import buildcraft.energy.fuels.FuelManager; import buildcraft.energy.statements.EnergyStatementProvider; +import buildcraft.energy.statements.TriggerCoolantBelowThreshold; import buildcraft.energy.statements.TriggerEngineHeat; +import buildcraft.energy.statements.TriggerFuelBelowThreshold; import buildcraft.energy.worldgen.BiomeGenOilDesert; import buildcraft.energy.worldgen.BiomeGenOilOcean; import buildcraft.energy.worldgen.BiomeInitializer; @@ -106,12 +108,19 @@ public class BuildCraftEnergy extends BuildCraftMod { public static boolean canOilBurn; public static boolean isOilDense; public static double oilWellScalar = 1.0; + public static ITriggerExternal triggerBlueEngineHeat = new TriggerEngineHeat(EnergyStage.BLUE); public static ITriggerExternal triggerGreenEngineHeat = new TriggerEngineHeat(EnergyStage.GREEN); public static ITriggerExternal triggerYellowEngineHeat = new TriggerEngineHeat(EnergyStage.YELLOW); public static ITriggerExternal triggerRedEngineHeat = new TriggerEngineHeat(EnergyStage.RED); public static ITriggerExternal triggerEngineOverheat = new TriggerEngineHeat(EnergyStage.OVERHEAT); + public static ITriggerExternal triggerFuelBelow25 = new TriggerFuelBelowThreshold(0.25F); + public static ITriggerExternal triggerFuelBelow50 = new TriggerFuelBelowThreshold(0.50F); + + public static ITriggerExternal triggerCoolantBelow25 = new TriggerCoolantBelowThreshold(0.25F); + public static ITriggerExternal triggerCoolantBelow50 = new TriggerCoolantBelowThreshold(0.50F); + private static Fluid buildcraftFluidOil; private static Fluid buildcraftFluidFuel; private static Fluid buildcraftFluidRedPlasma; diff --git a/common/buildcraft/energy/TileEngineIron.java b/common/buildcraft/energy/TileEngineIron.java index 1b30b2a4..60559890 100644 --- a/common/buildcraft/energy/TileEngineIron.java +++ b/common/buildcraft/energy/TileEngineIron.java @@ -8,6 +8,9 @@ */ package buildcraft.energy; +import java.util.LinkedList; +import java.util.List; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; @@ -23,13 +26,19 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; +import buildcraft.BuildCraftCore; import buildcraft.BuildCraftEnergy; + import buildcraft.api.core.StackKey; import buildcraft.api.fuels.BuildcraftFuelRegistry; import buildcraft.api.fuels.ICoolant; import buildcraft.api.fuels.IFuel; import buildcraft.api.fuels.ISolidCoolant; +import buildcraft.api.statements.IActionExternal; +import buildcraft.api.statements.IOverrideDefaultStatements; +import buildcraft.api.statements.ITriggerExternal; import buildcraft.api.transport.IItemPipe; + import buildcraft.core.GuiIds; import buildcraft.core.lib.engines.TileEngineWithInventory; import buildcraft.core.lib.fluids.Tank; @@ -37,7 +46,7 @@ import buildcraft.core.lib.fluids.TankManager; import buildcraft.core.lib.fluids.TankUtils; import buildcraft.core.lib.inventory.InvUtils; -public class TileEngineIron extends TileEngineWithInventory implements IFluidHandler { +public class TileEngineIron extends TileEngineWithInventory implements IFluidHandler, IOverrideDefaultStatements { public static int MAX_LIQUID = FluidContainerRegistry.BUCKET_VOLUME * 10; public static float HEAT_PER_RF = 0.00023F; @@ -110,6 +119,28 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan } } + public boolean hasFuelBelowThreshold(float threshold) { + FluidStack fuel = tankFuel.getFluid(); + + if (fuel == null) { + return true; + } + + float percentage = (float) fuel.amount / (float) MAX_LIQUID; + return percentage < threshold; + } + + public boolean hasCoolantBelowThreshold(float threshold) { + FluidStack coolant = tankCoolant.getFluid(); + + if (coolant == null) { + return true; + } + + float percentage = (float) coolant.amount / (float) MAX_LIQUID; + return percentage < threshold; + } + private float getBiomeTempScalar() { if (biomeCache == null) { biomeCache = worldObj.getBiomeGenForCoords(xCoord, zCoord); @@ -444,4 +475,33 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan public boolean hasCustomInventoryName() { return false; } + + @Override + public List overrideTriggers() { + List triggers = new LinkedList(); + + triggers.add(BuildCraftCore.triggerEmptyInventory); + triggers.add(BuildCraftCore.triggerContainsInventory); + triggers.add(BuildCraftCore.triggerSpaceInventory); + triggers.add(BuildCraftCore.triggerFullInventory); + + triggers.add(BuildCraftEnergy.triggerBlueEngineHeat); + triggers.add(BuildCraftEnergy.triggerGreenEngineHeat); + triggers.add(BuildCraftEnergy.triggerYellowEngineHeat); + triggers.add(BuildCraftEnergy.triggerRedEngineHeat); + triggers.add(BuildCraftEnergy.triggerEngineOverheat); + + triggers.add(BuildCraftEnergy.triggerCoolantBelow25); + triggers.add(BuildCraftEnergy.triggerCoolantBelow50); + + triggers.add(BuildCraftEnergy.triggerFuelBelow25); + triggers.add(BuildCraftEnergy.triggerFuelBelow50); + + return triggers; + } + + @Override + public List overrideActions() { + return null; + } } diff --git a/common/buildcraft/energy/statements/TriggerCoolantBelowThreshold.java b/common/buildcraft/energy/statements/TriggerCoolantBelowThreshold.java new file mode 100644 index 00000000..a79834b9 --- /dev/null +++ b/common/buildcraft/energy/statements/TriggerCoolantBelowThreshold.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + *

+ * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.energy.statements; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.tileentity.TileEntity; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.api.statements.IStatementContainer; +import buildcraft.api.statements.IStatementParameter; +import buildcraft.api.statements.ITriggerExternal; +import buildcraft.core.lib.utils.StringUtils; +import buildcraft.core.statements.BCStatement; +import buildcraft.energy.TileEngineIron; + +public class TriggerCoolantBelowThreshold extends BCStatement implements ITriggerExternal { + + private float threshold; + + public TriggerCoolantBelowThreshold(float threshold) { + super("buildcraft:trigger.coolantLevelBelow." + (int) (threshold * 100)); + this.threshold = threshold; + } + + @Override + public String getDescription() { + return String.format(StringUtils.localize("gate.trigger.coolantLevelBelow"), (int) (threshold * 100)); + } + + @Override + public boolean isTriggerActive(TileEntity target, ForgeDirection side, IStatementContainer source, IStatementParameter[] parameters) { + if (!(target instanceof TileEngineIron)) { + return false; + } + + return ((TileEngineIron) target).hasCoolantBelowThreshold(threshold); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + icon = iconRegister.registerIcon("buildcraftenergy:triggers/trigger_coolant_below_threshold"); + } +} diff --git a/common/buildcraft/energy/statements/TriggerFuelBelowThreshold.java b/common/buildcraft/energy/statements/TriggerFuelBelowThreshold.java new file mode 100644 index 00000000..382f996b --- /dev/null +++ b/common/buildcraft/energy/statements/TriggerFuelBelowThreshold.java @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team + * http://www.mod-buildcraft.com + *

+ * BuildCraft is distributed under the terms of the Minecraft Mod Public + * License 1.0, or MMPL. Please check the contents of the license located in + * http://www.mod-buildcraft.com/MMPL-1.0.txt + */ +package buildcraft.energy.statements; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.tileentity.TileEntity; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.api.statements.IStatementContainer; +import buildcraft.api.statements.IStatementParameter; +import buildcraft.api.statements.ITriggerExternal; +import buildcraft.core.lib.utils.StringUtils; +import buildcraft.core.statements.BCStatement; +import buildcraft.energy.TileEngineIron; + +public class TriggerFuelBelowThreshold extends BCStatement implements ITriggerExternal { + + private float threshold; + + public TriggerFuelBelowThreshold(float threshold) { + super("buildcraft:trigger.fuelLevelBelow." + (int) (threshold * 100)); + this.threshold = threshold; + } + + @Override + public String getDescription() { + return String.format(StringUtils.localize("gate.trigger.fuelLevelBelow"), (int) (threshold * 100)); + } + + @Override + public boolean isTriggerActive(TileEntity target, ForgeDirection side, IStatementContainer source, IStatementParameter[] parameters) { + if (!(target instanceof TileEngineIron)) { + return false; + } + + return ((TileEngineIron) target).hasFuelBelowThreshold(threshold); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister iconRegister) { + icon = iconRegister.registerIcon("buildcraftenergy:triggers/trigger_fuel_below_threshold"); + } +}