diff --git a/src/main/java/mekanism/common/tile/TileEntityAdvancedElectricMachine.java b/src/main/java/mekanism/common/tile/TileEntityAdvancedElectricMachine.java index f748aca0d..58b4fd41f 100644 --- a/src/main/java/mekanism/common/tile/TileEntityAdvancedElectricMachine.java +++ b/src/main/java/mekanism/common/tile/TileEntityAdvancedElectricMachine.java @@ -120,7 +120,7 @@ public abstract class TileEntityAdvancedElectricMachine= energyPerTick && gasTank.getStored() >= getSecondaryEnergyPerTick()) + if(MekanismUtils.canFunction(this) && canOperate(getInputSlot(process), getOutputSlot(process)) && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyPerTick) { if((progress[process]+1) < ticksRequired) { progress[process]++; - gasTank.draw(getSecondaryEnergyPerTick(), true); + gasTank.draw((int)secondaryEnergyPerTick, true); electricityStored -= energyPerTick; } else if((progress[process]+1) >= ticksRequired) @@ -248,7 +247,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I operate(getInputSlot(process), getOutputSlot(process)); progress[process] = 0; - gasTank.draw(getSecondaryEnergyPerTick(), true); + gasTank.draw((int)secondaryEnergyPerTick, true); electricityStored -= energyPerTick; } } @@ -273,7 +272,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I } } - if(MekanismUtils.canFunction(this) && hasOperation && getEnergy() >= energyPerTick && gasTank.getStored() >= getSecondaryEnergyPerTick()) + if(MekanismUtils.canFunction(this) && hasOperation && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyPerTick) { setActive(true); } @@ -366,9 +365,10 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I } } - public int getSecondaryEnergyPerTick() + public int getSecondaryEnergyPerTick(RecipeType type) { - return StatUtils.inversePoisson(secondaryEnergyPerTick); + double toUse = MekanismUtils.getSecondaryEnergyPerTickMean(this, type.getSecondaryEnergyPerTick()); + return StatUtils.inversePoisson((int)Math.ceil(toUse)); } public void handleSecondaryFuel() @@ -577,7 +577,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I if(recipeType != oldRecipe) { - secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick()); + secondaryEnergyPerTick = getSecondaryEnergyPerTick(recipeType); } recipeTicks = dataStream.readInt(); @@ -621,7 +621,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I if(recipeType != oldRecipe) { - secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick()); + secondaryEnergyPerTick = getSecondaryEnergyPerTick(recipeType); } recipeTicks = nbtTags.getInteger("recipeTicks"); @@ -941,7 +941,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I { case SPEED: ticksRequired = MekanismUtils.getTicks(this, BASE_TICKS_REQUIRED); - secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTickMean(this, recipeType.getSecondaryEnergyPerTick()); + secondaryEnergyPerTick = getSecondaryEnergyPerTick(recipeType); case ENERGY: energyPerTick = MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_PER_TICK); maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY); diff --git a/src/main/java/mekanism/common/tile/TileEntityPurificationChamber.java b/src/main/java/mekanism/common/tile/TileEntityPurificationChamber.java index 9ec24997a..cb0fb7d21 100644 --- a/src/main/java/mekanism/common/tile/TileEntityPurificationChamber.java +++ b/src/main/java/mekanism/common/tile/TileEntityPurificationChamber.java @@ -84,4 +84,16 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac { return gas == GasRegistry.getGas("oxygen"); } + + @Override + public boolean upgradeableSecondaryEfficiency() + { + return true; + } + + @Override + public boolean useStatisticalMechanics() + { + return true; + } } diff --git a/src/main/java/mekanism/common/util/MekanismUtils.java b/src/main/java/mekanism/common/util/MekanismUtils.java index d3b23acdc..1a9101819 100644 --- a/src/main/java/mekanism/common/util/MekanismUtils.java +++ b/src/main/java/mekanism/common/util/MekanismUtils.java @@ -627,17 +627,6 @@ public final class MekanismUtils return def * Math.pow(general.maxUpgradeMultiplier, (2*mgmt.getComponent().getUpgrades(Upgrade.SPEED)-(float)mgmt.getComponent().getUpgrades(Upgrade.ENERGY))/(float)Upgrade.SPEED.getMax()); } - /** - * Gets the secondary energy required per tick for a machine via upgrades. - * @param mgmt - tile containing upgrades - * @param def - the original, default secondary energy required - * @return max secondary energy per tick - */ - public static int getSecondaryEnergyPerTick(IUpgradeTile mgmt, int def) - { - return (int)getSecondaryEnergyPerTickMean(mgmt, def); - } - /** * Gets the secondary energy required per tick for a machine via upgrades. * @param mgmt - tile containing upgrades diff --git a/src/main/java/mekanism/common/util/StatUtils.java b/src/main/java/mekanism/common/util/StatUtils.java index f0657e09e..6f71feecb 100644 --- a/src/main/java/mekanism/common/util/StatUtils.java +++ b/src/main/java/mekanism/common/util/StatUtils.java @@ -15,16 +15,18 @@ public class StatUtils public static int inversePoisson(double mean) { - double r = rand.nextDouble() * exp(mean); + double r = rand.nextDouble()*exp(mean); int m = 0; double p = 1; - double stirlingValue = mean * E; - double stirlingCoeff = 1 / sqrt(2 * PI); - while ((p < r) && (m < 3*ceil(mean))) + double stirlingValue = mean*E; + double stirlingCoeff = 1/sqrt(2*PI); + + while((p < r) && (m < 3*ceil(mean))) { - m ++; - p += stirlingCoeff/sqrt(m) * pow((stirlingValue/m), m); + m++; + p += stirlingCoeff/sqrt(m)*pow((stirlingValue/m), m); } + return m; } }