Introduce statistical consumption of gases.
This commit is contained in:
parent
e98026d78d
commit
a91dcc49d4
4 changed files with 46 additions and 3 deletions
src/main/java/mekanism/common
|
@ -20,6 +20,7 @@ import mekanism.common.util.ChargeUtils;
|
|||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import mekanism.common.util.StatUtils;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -111,7 +112,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
|
|||
operatingTicks = 0;
|
||||
}
|
||||
|
||||
gasTank.draw(MekanismUtils.getSecondaryEnergyPerTick(this, SECONDARY_ENERGY_PER_TICK), true);
|
||||
gasTank.draw(StatUtils.inversePoisson(MekanismUtils.getSecondaryEnergyPerTickMean(this, SECONDARY_ENERGY_PER_TICK)), true);
|
||||
electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -32,6 +32,7 @@ import mekanism.common.tile.component.TileComponentUpgrade;
|
|||
import mekanism.common.util.ChargeUtils;
|
||||
import mekanism.common.util.InventoryUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import mekanism.common.util.StatUtils;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -351,7 +352,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
|
|||
|
||||
public int getSecondaryEnergyPerTick()
|
||||
{
|
||||
return MekanismUtils.getSecondaryEnergyPerTick(this, RecipeType.values()[recipeType].getSecondaryEnergyPerTick());
|
||||
return StatUtils.inversePoisson(MekanismUtils.getSecondaryEnergyPerTickMean(this, RecipeType.values()[recipeType].getSecondaryEnergyPerTick()));
|
||||
}
|
||||
|
||||
public void handleSecondaryFuel()
|
||||
|
|
|
@ -634,7 +634,18 @@ public final class MekanismUtils
|
|||
*/
|
||||
public static int getSecondaryEnergyPerTick(IUpgradeManagement mgmt, int def)
|
||||
{
|
||||
return (int)(def * Math.pow(Mekanism.maxUpgradeMultiplier, (mgmt.getSpeedMultiplier()-mgmt.getEnergyMultiplier())/8.0));
|
||||
return (int)getSecondaryEnergyPerTickMean(mgmt, def);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 double getSecondaryEnergyPerTickMean(IUpgradeManagement mgmt, int def)
|
||||
{
|
||||
return (def * Math.pow(Mekanism.maxUpgradeMultiplier, (mgmt.getSpeedMultiplier()-mgmt.getEnergyMultiplier())/8.0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
30
src/main/java/mekanism/common/util/StatUtils.java
Normal file
30
src/main/java/mekanism/common/util/StatUtils.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
package mekanism.common.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static java.lang.Math.ceil;
|
||||
import static java.lang.Math.sqrt;
|
||||
import static java.lang.Math.exp;
|
||||
import static java.lang.Math.pow;
|
||||
import static java.lang.Math.PI;
|
||||
import static java.lang.Math.E;
|
||||
|
||||
public class StatUtils
|
||||
{
|
||||
public static Random rand = new Random();
|
||||
|
||||
public static int inversePoisson(double 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)))
|
||||
{
|
||||
m ++;
|
||||
p += stirlingCoeff/sqrt(m) * pow((stirlingValue/m), m);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue