diff --git a/src/main/java/mekanism/common/base/IFactory.java b/src/main/java/mekanism/common/base/IFactory.java index 6bab9eecf..03fe46711 100644 --- a/src/main/java/mekanism/common/base/IFactory.java +++ b/src/main/java/mekanism/common/base/IFactory.java @@ -201,7 +201,7 @@ public interface IFactory return usesFuel; } - public boolean fuelSpeedUpgrade() + public boolean fuelEnergyUpgrades() { return fuelSpeed; } diff --git a/src/main/java/mekanism/common/tile/TileEntityAdvancedElectricMachine.java b/src/main/java/mekanism/common/tile/TileEntityAdvancedElectricMachine.java index b1613b2a9..ad6ae4667 100644 --- a/src/main/java/mekanism/common/tile/TileEntityAdvancedElectricMachine.java +++ b/src/main/java/mekanism/common/tile/TileEntityAdvancedElectricMachine.java @@ -48,9 +48,12 @@ public abstract class TileEntityAdvancedElectricMachine= energyPerTick && gasTank.getStored() >= secondaryEnergyPerTick) + secondaryEnergyThisTick = useStatisticalMechanics() ? StatUtils.inversePoisson(secondaryEnergyPerTick) : (int)Math.ceil(secondaryEnergyPerTick); + + if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyThisTick) { setActive(true); @@ -185,23 +190,24 @@ public abstract class TileEntityAdvancedElectricMachine= getEnergy()) - { - changed = true; - setActive(false); - } + inactive = true; + setActive(false); } - if(changed && !canOperate(recipe) && getRecipe() == null) + if(inactive && getRecipe() == null) { operatingTicks = 0; } prevEnergy = getEnergy(); + if(!(gasTank.getGasType() == null || gasTank.getStored() == 0)) + { + prevGas = gasTank.getGasType(); + } } } @@ -266,26 +272,26 @@ public abstract class TileEntityAdvancedElectricMachine= energyUsage && injectTank.getStored() >= injectUsage && MekanismUtils.canFunction(this)) + injectUsageThisTick = StatUtils.inversePoisson(injectUsage); + + if(canOperate(recipe) && getEnergy() >= energyUsage && injectTank.getStored() >= injectUsageThisTick && MekanismUtils.canFunction(this)) { setActive(true); setEnergy(getEnergy() - energyUsage); @@ -249,7 +253,7 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri public void minorOperate() { - injectTank.draw(injectUsage, true); + injectTank.draw(injectUsageThisTick, true); } @Override @@ -463,7 +467,7 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri switch(upgrade) { case SPEED: - injectUsage = StatUtils.inversePoisson(MekanismUtils.getSecondaryEnergyPerTickMean(this, BASE_INJECT_USAGE)); + injectUsage = MekanismUtils.getSecondaryEnergyPerTickMean(this, BASE_INJECT_USAGE, true); ticksRequired = MekanismUtils.getTicks(this, BASE_TICKS_REQUIRED); case ENERGY: energyUsage = MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_USAGE); diff --git a/src/main/java/mekanism/common/tile/TileEntityFactory.java b/src/main/java/mekanism/common/tile/TileEntityFactory.java index b96cd621f..23c26e8ab 100644 --- a/src/main/java/mekanism/common/tile/TileEntityFactory.java +++ b/src/main/java/mekanism/common/tile/TileEntityFactory.java @@ -80,6 +80,8 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I /** How much secondary energy each operation consumes per tick */ public double secondaryEnergyPerTick = 0; + public int secondaryEnergyThisTick; + /** How long it takes this factory to switch recipe types. */ public int RECIPE_TICKS_REQUIRED = 40; @@ -317,14 +319,15 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I recipeTicks = 0; } + secondaryEnergyThisTick = recipeType.fuelEnergyUpgrades() ? StatUtils.inversePoisson(secondaryEnergyPerTick) : (int)Math.ceil(secondaryEnergyPerTick); for(int process = 0; process < tier.processes; process++) { - if(MekanismUtils.canFunction(this) && canOperate(getInputSlot(process), getOutputSlot(process)) && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyPerTick) + if(MekanismUtils.canFunction(this) && canOperate(getInputSlot(process), getOutputSlot(process)) && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyThisTick) { if((progress[process]+1) < ticksRequired) { progress[process]++; - gasTank.draw((int)secondaryEnergyPerTick, true); + gasTank.draw(secondaryEnergyThisTick, true); electricityStored -= energyPerTick; } else if((progress[process]+1) >= ticksRequired) @@ -332,14 +335,14 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I operate(getInputSlot(process), getOutputSlot(process)); progress[process] = 0; - gasTank.draw((int)secondaryEnergyPerTick, true); + gasTank.draw(secondaryEnergyThisTick, true); electricityStored -= energyPerTick; } } if(!canOperate(getInputSlot(process), getOutputSlot(process))) { - if(!recipeType.usesFuel() || !recipeType.hasRecipe(inventory[getInputSlot(process)])) + if(!(recipeType.usesFuel() && recipeType.hasRecipe(inventory[getInputSlot(process)]))) { progress[process] = 0; } @@ -357,7 +360,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I } } - if(MekanismUtils.canFunction(this) && hasOperation && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyPerTick) + if(MekanismUtils.canFunction(this) && hasOperation && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyThisTick) { setActive(true); } @@ -456,18 +459,9 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I } } - public int getSecondaryEnergyPerTick(RecipeType type) + public double getSecondaryEnergyPerTick(RecipeType type) { - double secondaryToUse = type.getSecondaryEnergyPerTick(); - - if(type.fuelSpeedUpgrade()) - { - secondaryToUse = MekanismUtils.getSecondaryEnergyPerTickMean(this, type.getSecondaryEnergyPerTick()); - return StatUtils.inversePoisson(secondaryToUse); - } - else { - return (int)Math.ceil(secondaryToUse); - } + return MekanismUtils.getSecondaryEnergyPerTickMean(this, type.getSecondaryEnergyPerTick(), type.fuelEnergyUpgrades()); } public void handleSecondaryFuel() @@ -616,7 +610,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I return false; } - return recipe.canOperate(inventory, inputSlot, outputSlot, gasTank, (int)secondaryEnergyPerTick); + return recipe.canOperate(inventory, inputSlot, outputSlot, gasTank, secondaryEnergyThisTick); } BasicMachineRecipe recipe = recipeType.getRecipe(inventory[inputSlot]); @@ -640,7 +634,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I { AdvancedMachineRecipe recipe = recipeType.getRecipe(inventory[inputSlot], gasTank.getGasType()); - recipe.operate(inventory, inputSlot, outputSlot, gasTank, (int)secondaryEnergyPerTick); + recipe.operate(inventory, inputSlot, outputSlot, gasTank, secondaryEnergyThisTick); } else { diff --git a/src/main/java/mekanism/common/util/MekanismUtils.java b/src/main/java/mekanism/common/util/MekanismUtils.java index cc0182036..1d1071ddf 100644 --- a/src/main/java/mekanism/common/util/MekanismUtils.java +++ b/src/main/java/mekanism/common/util/MekanismUtils.java @@ -576,6 +576,11 @@ public final class MekanismUtils tile.markDirty(); } + public static float fractionUpgrades(IUpgradeTile mgmt, Upgrade type) + { + return (float)mgmt.getComponent().getUpgrades(type)/(float)type.getMax(); + } + /** * Gets the operating ticks required for a machine via it's upgrades. * @param mgmt - tile containing upgrades @@ -584,7 +589,7 @@ public final class MekanismUtils */ public static int getTicks(IUpgradeTile mgmt, int def) { - return (int)(def * Math.pow(general.maxUpgradeMultiplier, (float)-mgmt.getComponent().getUpgrades(Upgrade.SPEED)/(float)Upgrade.SPEED.getMax())); + return (int)(def * Math.pow(general.maxUpgradeMultiplier, -fractionUpgrades(mgmt, Upgrade.SPEED))); } /** @@ -595,7 +600,7 @@ public final class MekanismUtils */ public static double getEnergyPerTick(IUpgradeTile mgmt, double def) { - return def * Math.pow(general.maxUpgradeMultiplier, (2*mgmt.getComponent().getUpgrades(Upgrade.SPEED)-(float)mgmt.getComponent().getUpgrades(Upgrade.ENERGY))/(float)Upgrade.ENERGY.getMax()); + return def * Math.pow(general.maxUpgradeMultiplier, 2*fractionUpgrades(mgmt, Upgrade.SPEED)-fractionUpgrades(mgmt, Upgrade.ENERGY)); } /** @@ -606,7 +611,7 @@ public final class MekanismUtils */ public static double getBaseEnergyPerTick(IUpgradeTile mgmt, double def) { - return def * Math.pow(general.maxUpgradeMultiplier, -(float)mgmt.getComponent().getUpgrades(Upgrade.ENERGY)/(float)Upgrade.ENERGY.getMax()); + return def * Math.pow(general.maxUpgradeMultiplier, -fractionUpgrades(mgmt, Upgrade.ENERGY)); } /** @@ -615,9 +620,14 @@ public final class MekanismUtils * @param def - the original, default secondary energy required * @return max secondary energy per tick */ - public static double getSecondaryEnergyPerTickMean(IUpgradeTile mgmt, int def) + public static double getSecondaryEnergyPerTickMean(IUpgradeTile mgmt, int def, boolean energyUpgrades) { - return (def * Math.pow(general.maxUpgradeMultiplier, mgmt.getComponent().getUpgrades(Upgrade.SPEED)/(float)Upgrade.SPEED.getMax())); + if(energyUpgrades) + { + return def * Math.pow(general.maxUpgradeMultiplier, 2 * fractionUpgrades(mgmt, Upgrade.SPEED) - fractionUpgrades(mgmt, Upgrade.ENERGY)); + } + + return def * Math.pow(general.maxUpgradeMultiplier, fractionUpgrades(mgmt, Upgrade.SPEED)); } /** @@ -628,7 +638,7 @@ public final class MekanismUtils */ public static double getMaxEnergy(IUpgradeTile mgmt, double def) { - return def * Math.pow(general.maxUpgradeMultiplier, (float)mgmt.getComponent().getUpgrades(Upgrade.ENERGY)/(float)Upgrade.ENERGY.getMax()); + return def * Math.pow(general.maxUpgradeMultiplier, fractionUpgrades(mgmt, Upgrade.ENERGY)); } /**