Adding triggers for fuel and coolant.

Adding triggers for low levels of fuel and coolant in combustion
engines. The goal is to make it easier to refill with fluid containers
like wax capsules.
This commit is contained in:
SandGrainOne 2015-10-27 22:12:36 +01:00
parent d32e50c16d
commit 5a49b05448
7 changed files with 180 additions and 1 deletions

View file

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

View file

@ -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;

View file

@ -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<ITriggerExternal> overrideTriggers() {
List<ITriggerExternal> triggers = new LinkedList<ITriggerExternal>();
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<IActionExternal> overrideActions() {
return null;
}
}

View file

@ -0,0 +1,54 @@
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
* <p/>
* 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");
}
}

View file

@ -0,0 +1,54 @@
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
* <p/>
* 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");
}
}