Merge branch 'master' into development (@unpairedbracket, make sure I did this right)

Conflicts:
	src/main/java/mekanism/common/tile/TileEntityAdvancedElectricMachine.java
	src/main/java/mekanism/common/util/MekanismUtils.java
This commit is contained in:
Aidan C. Brady committed 2015-02-19 16:12:28 -05:00
commit 2fe4cf290d
7 files changed
+73 -34

No files matched your search

@@ -120,7 +120,7 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
operatingTicks = 0;
}
gasTank.draw(StatUtils.inversePoisson(secondaryEnergyPerTick), true);
gasTank.draw((int)secondaryEnergyPerTick, true);
electricityStored -= energyPerTick;
}
else {
@@ -160,6 +160,16 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
}
}
}
public boolean upgradeableSecondaryEfficiency()
{
return false;
}
public boolean useStatisticalMechanics()
{
return false;
}
@Override
public boolean isItemValidForSlot(int slotID, ItemStack itemstack)
@@ -198,10 +208,12 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
public RECIPE getRecipe()
{
AdvancedMachineInput input = getInput();
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
{
cachedRecipe = RecipeHandler.getRecipe(input, getRecipes());
}
return cachedRecipe;
}
@@ -330,7 +342,19 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
if(upgrade == Upgrade.SPEED)
{
secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTickMean(this, BASE_SECONDARY_ENERGY_PER_TICK);
double secondaryToUse = BASE_SECONDARY_ENERGY_PER_TICK;
if(upgradeableSecondaryEfficiency())
{
secondaryToUse = MekanismUtils.getSecondaryEnergyPerTickMean(this, BASE_SECONDARY_ENERGY_PER_TICK);
}
secondaryEnergyPerTick = (int)Math.ceil(secondaryToUse);
if(useStatisticalMechanics())
{
secondaryEnergyPerTick = StatUtils.inversePoisson(secondaryToUse);
}
}
}
@@ -27,12 +27,11 @@ 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.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import io.netty.buffer.ByteBuf;
public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectricBlock implements ITubeConnection, IRedstoneControl, IGasHandler, IUpgradeTile, ISustainedData
@@ -462,7 +461,8 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri
switch(upgrade)
{
case SPEED:
injectUsage = MekanismUtils.getSecondaryEnergyPerTick(this, BASE_INJECT_USAGE);
double toUse = MekanismUtils.getSecondaryEnergyPerTickMean(this, BASE_INJECT_USAGE);
injectUsage = StatUtils.inversePoisson((int)Math.ceil(toUse));
ticksRequired = MekanismUtils.getTicks(this, BASE_TICKS_REQUIRED);
case ENERGY:
energyUsage = MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_USAGE);
@@ -91,4 +91,16 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr
{
return gas == GasRegistry.getGas("sulfuricAcid") || gas == GasRegistry.getGas("water") || gas == GasRegistry.getGas("hydrogenChloride");
}
@Override
public boolean upgradeableSecondaryEfficiency()
{
return true;
}
@Override
public boolean useStatisticalMechanics()
{
return true;
}
}
@@ -199,8 +199,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
{
recipeTicks++;
}
else
{
else {
recipeTicks = 0;
ItemStack returnStack = getMachineStack();
@@ -218,7 +217,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
recipeType = toSet;
gasTank.setGas(null);
secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick());
secondaryEnergyPerTick = getSecondaryEnergyPerTick(recipeType);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
@@ -235,12 +234,12 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
for(int process = 0; process < tier.processes; process++)
{
if(MekanismUtils.canFunction(this) && canOperate(getInputSlot(process), getOutputSlot(process)) && getEnergy() >= 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);
@@ -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;
}
}
@@ -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
@@ -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;
}
}