Energy usage calculations are now much more efficient
This commit is contained in:
parent
763aef4fd0
commit
a6e8fc8de0
10 changed files with 45 additions and 22 deletions
|
@ -51,7 +51,7 @@ public class GuiChemicalInfuser extends GuiMekanism
|
||||||
|
|
||||||
if(tileEntity.getRecipe() != null)
|
if(tileEntity.getRecipe() != null)
|
||||||
{
|
{
|
||||||
usage = tileEntity.getUpgradedUsage(tileEntity.getRecipe())*MekanismUtils.getPureEnergyPerTick(tileEntity, tileEntity.BASE_ENERGY_USAGE);
|
usage = tileEntity.getUpgradedUsage(tileEntity.getRecipe())*tileEntity.energyPerTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
String multiplier = MekanismUtils.getEnergyDisplay(usage);
|
String multiplier = MekanismUtils.getEnergyDisplay(usage);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class GuiChemicalWasher extends GuiMekanism
|
||||||
@Override
|
@Override
|
||||||
public List<String> getInfo()
|
public List<String> getInfo()
|
||||||
{
|
{
|
||||||
String multiplier = MekanismUtils.getEnergyDisplay(MekanismUtils.getPureEnergyPerTick(tileEntity, tileEntity.BASE_ENERGY_USAGE)*tileEntity.getUpgradedUsage());
|
String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyPerTick*tileEntity.getUpgradedUsage());
|
||||||
return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy()));
|
return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy()));
|
||||||
}
|
}
|
||||||
}, this, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalWasher.png")));
|
}, this, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalWasher.png")));
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class GuiElectrolyticSeparator extends GuiMekanism
|
||||||
|
|
||||||
if(tileEntity.getRecipe() != null)
|
if(tileEntity.getRecipe() != null)
|
||||||
{
|
{
|
||||||
usage = tileEntity.getUpgradedUsage(tileEntity.getRecipe())*MekanismUtils.getPureEnergyPerTick(tileEntity, tileEntity.getRecipe().extraEnergy);
|
usage = tileEntity.getUpgradedUsage(tileEntity.getRecipe())*tileEntity.energyPerTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
String multiplier = MekanismUtils.getEnergyDisplay(usage);
|
String multiplier = MekanismUtils.getEnergyDisplay(usage);
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class GuiRotaryCondensentrator extends GuiMekanism
|
||||||
@Override
|
@Override
|
||||||
public List<String> getInfo()
|
public List<String> getInfo()
|
||||||
{
|
{
|
||||||
String multiplier = MekanismUtils.getEnergyDisplay(MekanismUtils.getPureEnergyPerTick(tileEntity, tileEntity.BASE_ENERGY_USAGE)*tileEntity.getUpgradedUsage());
|
String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyPerTick*tileEntity.getUpgradedUsage());
|
||||||
return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy()));
|
return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy()));
|
||||||
}
|
}
|
||||||
}, this, MekanismUtils.getResource(ResourceType.GUI, "GuiRotaryCondensentrator.png")));
|
}, this, MekanismUtils.getResource(ResourceType.GUI, "GuiRotaryCondensentrator.png")));
|
||||||
|
|
|
@ -10,12 +10,12 @@ import net.minecraftforge.fluids.FluidTank;
|
||||||
|
|
||||||
public class SeparatorRecipe extends MachineRecipe<FluidInput, ChemicalPairOutput, SeparatorRecipe>
|
public class SeparatorRecipe extends MachineRecipe<FluidInput, ChemicalPairOutput, SeparatorRecipe>
|
||||||
{
|
{
|
||||||
public double extraEnergy;
|
public double energyUsage;
|
||||||
|
|
||||||
public SeparatorRecipe(FluidInput input, double energy, ChemicalPairOutput output)
|
public SeparatorRecipe(FluidInput input, double energy, ChemicalPairOutput output)
|
||||||
{
|
{
|
||||||
super(input, output);
|
super(input, output);
|
||||||
extraEnergy = energy;
|
energyUsage = energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SeparatorRecipe(FluidStack input, double energy, GasStack left, GasStack right)
|
public SeparatorRecipe(FluidStack input, double energy, GasStack left, GasStack right)
|
||||||
|
@ -26,7 +26,7 @@ public class SeparatorRecipe extends MachineRecipe<FluidInput, ChemicalPairOutpu
|
||||||
@Override
|
@Override
|
||||||
public SeparatorRecipe copy()
|
public SeparatorRecipe copy()
|
||||||
{
|
{
|
||||||
return new SeparatorRecipe(getInput().copy(), extraEnergy, getOutput().copy());
|
return new SeparatorRecipe(getInput().copy(), energyUsage, getOutput().copy());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canOperate(FluidTank fluidTank, GasTank leftTank, GasTank rightTank)
|
public boolean canOperate(FluidTank fluidTank, GasTank leftTank, GasTank rightTank)
|
||||||
|
|
|
@ -58,6 +58,8 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
|
||||||
public double prevEnergy;
|
public double prevEnergy;
|
||||||
|
|
||||||
public final double BASE_ENERGY_USAGE = usage.chemicalInfuserUsage;
|
public final double BASE_ENERGY_USAGE = usage.chemicalInfuserUsage;
|
||||||
|
|
||||||
|
public double energyPerTick = BASE_ENERGY_USAGE;
|
||||||
|
|
||||||
public ChemicalInfuserRecipe cachedRecipe;
|
public ChemicalInfuserRecipe cachedRecipe;
|
||||||
|
|
||||||
|
@ -119,10 +121,10 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
|
||||||
|
|
||||||
ChemicalInfuserRecipe recipe = getRecipe();
|
ChemicalInfuserRecipe recipe = getRecipe();
|
||||||
|
|
||||||
if(canOperate(recipe) && getEnergy() >= MekanismUtils.getPureEnergyPerTick(this, BASE_ENERGY_USAGE) && MekanismUtils.canFunction(this))
|
if(canOperate(recipe) && getEnergy() >= energyPerTick && MekanismUtils.canFunction(this))
|
||||||
{
|
{
|
||||||
setActive(true);
|
setActive(true);
|
||||||
setEnergy(getEnergy() - MekanismUtils.getPureEnergyPerTick(this, BASE_ENERGY_USAGE));
|
setEnergy(getEnergy() - energyPerTick);
|
||||||
|
|
||||||
operate(recipe);
|
operate(recipe);
|
||||||
}
|
}
|
||||||
|
@ -167,7 +169,7 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
|
||||||
}
|
}
|
||||||
|
|
||||||
possibleProcess = Math.min(centerTank.getNeeded()/recipe.recipeOutput.output.amount, possibleProcess);
|
possibleProcess = Math.min(centerTank.getNeeded()/recipe.recipeOutput.output.amount, possibleProcess);
|
||||||
possibleProcess = Math.min((int)(getEnergy()/MekanismUtils.getPureEnergyPerTick(this, BASE_ENERGY_USAGE)), possibleProcess);
|
possibleProcess = Math.min((int)(getEnergy()/energyPerTick), possibleProcess);
|
||||||
|
|
||||||
return possibleProcess;
|
return possibleProcess;
|
||||||
}
|
}
|
||||||
|
@ -535,6 +537,7 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
|
||||||
{
|
{
|
||||||
case ENERGY:
|
case ENERGY:
|
||||||
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
|
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
|
||||||
|
energyPerTick = MekanismUtils.getBaseEnergyPerTick(this, BASE_ENERGY_USAGE);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,8 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
|
||||||
public double prevEnergy;
|
public double prevEnergy;
|
||||||
|
|
||||||
public final double BASE_ENERGY_USAGE = usage.chemicalWasherUsage;
|
public final double BASE_ENERGY_USAGE = usage.chemicalWasherUsage;
|
||||||
|
|
||||||
|
public double energyPerTick = BASE_ENERGY_USAGE;
|
||||||
|
|
||||||
public WasherRecipe cachedRecipe;
|
public WasherRecipe cachedRecipe;
|
||||||
|
|
||||||
|
@ -123,13 +125,13 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
|
||||||
|
|
||||||
WasherRecipe recipe = getRecipe();
|
WasherRecipe recipe = getRecipe();
|
||||||
|
|
||||||
if(canOperate(recipe) && getEnergy() >= MekanismUtils.getPureEnergyPerTick(this, BASE_ENERGY_USAGE) && MekanismUtils.canFunction(this))
|
if(canOperate(recipe) && getEnergy() >= energyPerTick && MekanismUtils.canFunction(this))
|
||||||
{
|
{
|
||||||
setActive(true);
|
setActive(true);
|
||||||
|
|
||||||
int operations = operate(recipe);
|
int operations = operate(recipe);
|
||||||
|
|
||||||
setEnergy(getEnergy() - MekanismUtils.getPureEnergyPerTick(this, BASE_ENERGY_USAGE)*operations);
|
setEnergy(getEnergy() - energyPerTick*operations);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(prevEnergy >= getEnergy())
|
if(prevEnergy >= getEnergy())
|
||||||
|
@ -264,7 +266,7 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
|
||||||
{
|
{
|
||||||
int possibleProcess = (int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED));
|
int possibleProcess = (int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED));
|
||||||
possibleProcess = Math.min(Math.min(inputTank.getStored(), outputTank.getNeeded()), possibleProcess);
|
possibleProcess = Math.min(Math.min(inputTank.getStored(), outputTank.getNeeded()), possibleProcess);
|
||||||
possibleProcess = Math.min((int)(getEnergy()/MekanismUtils.getPureEnergyPerTick(this, BASE_ENERGY_USAGE)), possibleProcess);
|
possibleProcess = Math.min((int)(getEnergy()/energyPerTick), possibleProcess);
|
||||||
|
|
||||||
return Math.min(fluidTank.getFluidAmount()/WATER_USAGE, possibleProcess);
|
return Math.min(fluidTank.getFluidAmount()/WATER_USAGE, possibleProcess);
|
||||||
}
|
}
|
||||||
|
@ -636,6 +638,7 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
|
||||||
{
|
{
|
||||||
case ENERGY:
|
case ENERGY:
|
||||||
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
|
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
|
||||||
|
energyPerTick = MekanismUtils.getBaseEnergyPerTick(this, BASE_ENERGY_USAGE);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,10 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
||||||
|
|
||||||
/** Type type of gas this block is dumping. */
|
/** Type type of gas this block is dumping. */
|
||||||
public GasMode dumpRight = GasMode.IDLE;
|
public GasMode dumpRight = GasMode.IDLE;
|
||||||
|
|
||||||
|
public double BASE_ENERGY_USAGE;
|
||||||
|
|
||||||
|
public double energyPerTick;
|
||||||
|
|
||||||
public boolean isActive = false;
|
public boolean isActive = false;
|
||||||
|
|
||||||
|
@ -144,13 +148,22 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
||||||
|
|
||||||
SeparatorRecipe recipe = getRecipe();
|
SeparatorRecipe recipe = getRecipe();
|
||||||
|
|
||||||
if(canOperate(recipe) && getEnergy() >= MekanismUtils.getPureEnergyPerTick(this, recipe.extraEnergy))
|
if(canOperate(recipe) && getEnergy() >= energyPerTick)
|
||||||
{
|
{
|
||||||
|
boolean update = BASE_ENERGY_USAGE != recipe.energyUsage;
|
||||||
|
|
||||||
|
BASE_ENERGY_USAGE = recipe.energyUsage;
|
||||||
|
|
||||||
|
if(update)
|
||||||
|
{
|
||||||
|
recalculateUpgradables(Upgrade.ENERGY);
|
||||||
|
}
|
||||||
|
|
||||||
setActive(true);
|
setActive(true);
|
||||||
|
|
||||||
int operations = operate(recipe);
|
int operations = operate(recipe);
|
||||||
|
|
||||||
setEnergy(getEnergy() - MekanismUtils.getPureEnergyPerTick(this, recipe.extraEnergy)*operations);
|
setEnergy(getEnergy() - energyPerTick*operations);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setActive(false);
|
setActive(false);
|
||||||
|
@ -250,7 +263,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
||||||
}
|
}
|
||||||
|
|
||||||
possibleProcess = Math.min((int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED)), possibleProcess);
|
possibleProcess = Math.min((int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED)), possibleProcess);
|
||||||
possibleProcess = Math.min((int)(getEnergy()/MekanismUtils.getPureEnergyPerTick(this, recipe.extraEnergy)), possibleProcess);
|
possibleProcess = Math.min((int)(getEnergy()/energyPerTick), possibleProcess);
|
||||||
|
|
||||||
return Math.min(fluidTank.getFluidAmount()/recipe.recipeInput.ingredient.amount, possibleProcess);
|
return Math.min(fluidTank.getFluidAmount()/recipe.recipeInput.ingredient.amount, possibleProcess);
|
||||||
}
|
}
|
||||||
|
@ -734,6 +747,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
||||||
{
|
{
|
||||||
case ENERGY:
|
case ENERGY:
|
||||||
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
|
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
|
||||||
|
energyPerTick = MekanismUtils.getBaseEnergyPerTick(this, BASE_ENERGY_USAGE);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,8 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
|
||||||
|
|
||||||
public final double BASE_ENERGY_USAGE = usage.rotaryCondensentratorUsage;
|
public final double BASE_ENERGY_USAGE = usage.rotaryCondensentratorUsage;
|
||||||
|
|
||||||
|
public double energyPerTick = BASE_ENERGY_USAGE;
|
||||||
|
|
||||||
public TileComponentUpgrade upgradeComponent = new TileComponentUpgrade(this, 5);
|
public TileComponentUpgrade upgradeComponent = new TileComponentUpgrade(this, 5);
|
||||||
|
|
||||||
/** This machine's current RedstoneControl type. */
|
/** This machine's current RedstoneControl type. */
|
||||||
|
@ -171,14 +173,14 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getEnergy() >= BASE_ENERGY_USAGE && MekanismUtils.canFunction(this) && isValidGas(gasTank.getGas()) && (fluidTank.getFluid() == null || (fluidTank.getFluid().amount < MAX_FLUID && gasEquals(gasTank.getGas(), fluidTank.getFluid()))))
|
if(getEnergy() >= energyPerTick && MekanismUtils.canFunction(this) && isValidGas(gasTank.getGas()) && (fluidTank.getFluid() == null || (fluidTank.getFluid().amount < MAX_FLUID && gasEquals(gasTank.getGas(), fluidTank.getFluid()))))
|
||||||
{
|
{
|
||||||
int usage = getUpgradedUsage();
|
int usage = getUpgradedUsage();
|
||||||
|
|
||||||
setActive(true);
|
setActive(true);
|
||||||
fluidTank.fill(new FluidStack(gasTank.getGas().getGas().getFluid(), usage), true);
|
fluidTank.fill(new FluidStack(gasTank.getGas().getGas().getFluid(), usage), true);
|
||||||
gasTank.draw(usage, true);
|
gasTank.draw(usage, true);
|
||||||
setEnergy(getEnergy() - BASE_ENERGY_USAGE*usage);
|
setEnergy(getEnergy() - energyPerTick*usage);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(prevEnergy >= getEnergy())
|
if(prevEnergy >= getEnergy())
|
||||||
|
@ -278,14 +280,14 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getEnergy() >= MekanismUtils.getPureEnergyPerTick(this, BASE_ENERGY_USAGE) && MekanismUtils.canFunction(this) && isValidFluid(fluidTank.getFluid()) && (gasTank.getGas() == null || (gasTank.getStored() < MAX_FLUID && gasEquals(gasTank.getGas(), fluidTank.getFluid()))))
|
if(getEnergy() >= energyPerTick && MekanismUtils.canFunction(this) && isValidFluid(fluidTank.getFluid()) && (gasTank.getGas() == null || (gasTank.getStored() < MAX_FLUID && gasEquals(gasTank.getGas(), fluidTank.getFluid()))))
|
||||||
{
|
{
|
||||||
int operations = getUpgradedUsage();
|
int operations = getUpgradedUsage();
|
||||||
|
|
||||||
setActive(true);
|
setActive(true);
|
||||||
gasTank.receive(new GasStack(GasRegistry.getGas(fluidTank.getFluid().getFluid()), operations), true);
|
gasTank.receive(new GasStack(GasRegistry.getGas(fluidTank.getFluid().getFluid()), operations), true);
|
||||||
fluidTank.drain(operations, true);
|
fluidTank.drain(operations, true);
|
||||||
setEnergy(getEnergy() - MekanismUtils.getPureEnergyPerTick(this, BASE_ENERGY_USAGE)*operations);
|
setEnergy(getEnergy() - energyPerTick*operations);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(prevEnergy >= getEnergy())
|
if(prevEnergy >= getEnergy())
|
||||||
|
@ -311,7 +313,7 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
|
||||||
possibleProcess = Math.min(Math.min(fluidTank.getFluidAmount(), gasTank.getNeeded()), possibleProcess);
|
possibleProcess = Math.min(Math.min(fluidTank.getFluidAmount(), gasTank.getNeeded()), possibleProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
possibleProcess = Math.min((int)(getEnergy()/MekanismUtils.getPureEnergyPerTick(this, BASE_ENERGY_USAGE)), possibleProcess);
|
possibleProcess = Math.min((int)(getEnergy()/energyPerTick), possibleProcess);
|
||||||
|
|
||||||
return possibleProcess;
|
return possibleProcess;
|
||||||
}
|
}
|
||||||
|
@ -646,6 +648,7 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
|
||||||
{
|
{
|
||||||
case ENERGY:
|
case ENERGY:
|
||||||
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
|
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
|
||||||
|
energyPerTick = MekanismUtils.getBaseEnergyPerTick(this, BASE_ENERGY_USAGE);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -599,7 +599,7 @@ public final class MekanismUtils
|
||||||
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*mgmt.getComponent().getUpgrades(Upgrade.SPEED)-(float)mgmt.getComponent().getUpgrades(Upgrade.ENERGY))/(float)Upgrade.ENERGY.getMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getPureEnergyPerTick(IUpgradeTile mgmt, double def)
|
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, -(float)mgmt.getComponent().getUpgrades(Upgrade.ENERGY)/(float)Upgrade.ENERGY.getMax());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue