From b75ff5d9a15e86077e78433c41a890482264d579 Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Sat, 6 Sep 2014 21:14:49 +0100 Subject: [PATCH] Cache all the things. (Provided those things are computationally expensive to recalculate, and the memory cost of caching them is less than the time cost of recalculating them each time.) --- .../gui/GuiAdvancedElectricMachine.java | 2 +- .../mekanism/client/gui/GuiChanceMachine.java | 2 +- .../client/gui/GuiChemicalCrystallizer.java | 2 +- .../gui/GuiChemicalDissolutionChamber.java | 2 +- .../client/gui/GuiChemicalOxidizer.java | 2 +- .../client/gui/GuiElectricMachine.java | 2 +- .../java/mekanism/client/gui/GuiFactory.java | 2 +- .../client/gui/GuiMetallurgicInfuser.java | 2 +- src/main/java/mekanism/common/Upgrade.java | 2 +- .../java/mekanism/common/base/IFactory.java | 2 +- .../recipe/machines/ChanceMachineRecipe.java | 9 +++ .../TileEntityAdvancedElectricMachine.java | 51 +++++++++---- .../common/tile/TileEntityBasicMachine.java | 49 +++++++++---- .../common/tile/TileEntityChanceMachine.java | 22 +++--- .../tile/TileEntityChemicalCrystallizer.java | 56 ++++++++------ .../TileEntityChemicalDissolutionChamber.java | 65 ++++++++++------- .../tile/TileEntityChemicalInfuser.java | 9 ++- .../tile/TileEntityChemicalOxidizer.java | 46 ++++++++---- .../common/tile/TileEntityChemicalWasher.java | 9 ++- .../common/tile/TileEntityContainerBlock.java | 5 +- .../common/tile/TileEntityDigitalMiner.java | 31 +++++--- .../common/tile/TileEntityElectricBlock.java | 25 +++++-- .../tile/TileEntityElectricMachine.java | 18 +++-- .../tile/TileEntityElectrolyticSeparator.java | 15 +++- .../common/tile/TileEntityFactory.java | 73 ++++++++++++++----- .../tile/TileEntityMetallurgicInfuser.java | 37 +++++++--- .../mekanism/common/tile/TileEntityPRC.java | 27 ++++--- .../tile/component/TileComponentUpgrade.java | 23 +++--- .../mekanism/common/util/MekanismUtils.java | 1 - .../common/tile/TileEntityBioGenerator.java | 6 +- .../common/tile/TileEntityHeatGenerator.java | 6 +- .../common/tile/TileEntitySolarGenerator.java | 4 +- .../common/tile/TileEntityWindTurbine.java | 6 +- 33 files changed, 407 insertions(+), 206 deletions(-) diff --git a/src/main/java/mekanism/client/gui/GuiAdvancedElectricMachine.java b/src/main/java/mekanism/client/gui/GuiAdvancedElectricMachine.java index a6c070a0b..ee36dcb6f 100644 --- a/src/main/java/mekanism/client/gui/GuiAdvancedElectricMachine.java +++ b/src/main/java/mekanism/client/gui/GuiAdvancedElectricMachine.java @@ -38,7 +38,7 @@ public class GuiAdvancedElectricMachine extends GuiMekanism @Override public List getInfo() { - String multiplier = MekanismUtils.getEnergyDisplay(MekanismUtils.getEnergyPerTick(tileEntity, tileEntity.ENERGY_PER_TICK)); + String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyPerTick); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); } }, this, tileEntity.guiLocation)); diff --git a/src/main/java/mekanism/client/gui/GuiChanceMachine.java b/src/main/java/mekanism/client/gui/GuiChanceMachine.java index 194905de8..0f0a2b6d4 100644 --- a/src/main/java/mekanism/client/gui/GuiChanceMachine.java +++ b/src/main/java/mekanism/client/gui/GuiChanceMachine.java @@ -36,7 +36,7 @@ public class GuiChanceMachine extends GuiMekanism @Override public List getInfo() { - String multiplier = MekanismUtils.getEnergyDisplay(MekanismUtils.getEnergyPerTick(tileEntity, tileEntity.ENERGY_PER_TICK)); + String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyPerTick); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); } }, this, tileEntity.guiLocation)); diff --git a/src/main/java/mekanism/client/gui/GuiChemicalCrystallizer.java b/src/main/java/mekanism/client/gui/GuiChemicalCrystallizer.java index a53f654c1..a45f5b68c 100644 --- a/src/main/java/mekanism/client/gui/GuiChemicalCrystallizer.java +++ b/src/main/java/mekanism/client/gui/GuiChemicalCrystallizer.java @@ -59,7 +59,7 @@ public class GuiChemicalCrystallizer extends GuiMekanism @Override public List getInfo() { - String multiplier = MekanismUtils.getEnergyDisplay(MekanismUtils.getEnergyPerTick(tileEntity, tileEntity.ENERGY_USAGE)); + String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyUsage); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); } }, this, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalCrystallizer.png"))); diff --git a/src/main/java/mekanism/client/gui/GuiChemicalDissolutionChamber.java b/src/main/java/mekanism/client/gui/GuiChemicalDissolutionChamber.java index fb397192c..ab4c26511 100644 --- a/src/main/java/mekanism/client/gui/GuiChemicalDissolutionChamber.java +++ b/src/main/java/mekanism/client/gui/GuiChemicalDissolutionChamber.java @@ -37,7 +37,7 @@ public class GuiChemicalDissolutionChamber extends GuiMekanism @Override public List getInfo() { - String multiplier = MekanismUtils.getEnergyDisplay(MekanismUtils.getEnergyPerTick(tileEntity, tileEntity.ENERGY_USAGE)); + String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyUsage); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); } }, this, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalDissolutionChamber.png"))); diff --git a/src/main/java/mekanism/client/gui/GuiChemicalOxidizer.java b/src/main/java/mekanism/client/gui/GuiChemicalOxidizer.java index 085763a96..96194deef 100644 --- a/src/main/java/mekanism/client/gui/GuiChemicalOxidizer.java +++ b/src/main/java/mekanism/client/gui/GuiChemicalOxidizer.java @@ -37,7 +37,7 @@ public class GuiChemicalOxidizer extends GuiMekanism @Override public List getInfo() { - String multiplier = MekanismUtils.getEnergyDisplay(MekanismUtils.getEnergyPerTick(tileEntity, tileEntity.ENERGY_USAGE)); + String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyUsage); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); } }, this, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalOxidizer.png"))); diff --git a/src/main/java/mekanism/client/gui/GuiElectricMachine.java b/src/main/java/mekanism/client/gui/GuiElectricMachine.java index 471d2241a..2384751fa 100644 --- a/src/main/java/mekanism/client/gui/GuiElectricMachine.java +++ b/src/main/java/mekanism/client/gui/GuiElectricMachine.java @@ -36,7 +36,7 @@ public class GuiElectricMachine extends GuiMekanism @Override public List getInfo() { - String multiplier = MekanismUtils.getEnergyDisplay(MekanismUtils.getEnergyPerTick(tileEntity, tileEntity.ENERGY_PER_TICK)); + String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyPerTick); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); } }, this, tileEntity.guiLocation)); diff --git a/src/main/java/mekanism/client/gui/GuiFactory.java b/src/main/java/mekanism/client/gui/GuiFactory.java index e32e7e495..6de96af1f 100644 --- a/src/main/java/mekanism/client/gui/GuiFactory.java +++ b/src/main/java/mekanism/client/gui/GuiFactory.java @@ -38,7 +38,7 @@ public class GuiFactory extends GuiMekanism @Override public List getInfo() { - String multiplier = MekanismUtils.getEnergyDisplay(MekanismUtils.getEnergyPerTick(tileEntity, tileEntity.ENERGY_PER_TICK)); + String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyPerTick); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); } }, this, tileEntity.tier.guiLocation)); diff --git a/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java b/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java index 661681587..c4ca7aad3 100644 --- a/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java +++ b/src/main/java/mekanism/client/gui/GuiMetallurgicInfuser.java @@ -42,7 +42,7 @@ public class GuiMetallurgicInfuser extends GuiMekanism @Override public List getInfo() { - String multiplier = MekanismUtils.getEnergyDisplay(MekanismUtils.getEnergyPerTick(tileEntity, tileEntity.ENERGY_PER_TICK)); + String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyPerTick); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); } }, this, MekanismUtils.getResource(ResourceType.GUI, "GuiMetallurgicInfuser.png"))); diff --git a/src/main/java/mekanism/common/Upgrade.java b/src/main/java/mekanism/common/Upgrade.java index 0a097c20d..a900c652f 100644 --- a/src/main/java/mekanism/common/Upgrade.java +++ b/src/main/java/mekanism/common/Upgrade.java @@ -98,7 +98,7 @@ public enum Upgrade for(int tagCount = 0; tagCount < list.tagCount(); tagCount++) { - NBTTagCompound compound = (NBTTagCompound)list.getCompoundTagAt(tagCount); + NBTTagCompound compound = list.getCompoundTagAt(tagCount); Upgrade upgrade = Upgrade.values()[compound.getInteger("type")]; upgrades.put(upgrade, compound.getInteger("amount")); diff --git a/src/main/java/mekanism/common/base/IFactory.java b/src/main/java/mekanism/common/base/IFactory.java index 4f66f596f..03b24a311 100644 --- a/src/main/java/mekanism/common/base/IFactory.java +++ b/src/main/java/mekanism/common/base/IFactory.java @@ -102,7 +102,7 @@ public interface IFactory { if(usesFuel) { - return getTile().SECONDARY_ENERGY_PER_TICK; + return getTile().BASE_SECONDARY_ENERGY_PER_TICK; } return 0; diff --git a/src/main/java/mekanism/common/recipe/machines/ChanceMachineRecipe.java b/src/main/java/mekanism/common/recipe/machines/ChanceMachineRecipe.java index 45b711635..e292a21aa 100644 --- a/src/main/java/mekanism/common/recipe/machines/ChanceMachineRecipe.java +++ b/src/main/java/mekanism/common/recipe/machines/ChanceMachineRecipe.java @@ -16,4 +16,13 @@ public abstract class ChanceMachineRecipe> extends TileEntityBasicMachine implements IGasHandler, ITubeConnection { - /** How much secondary energy (fuel) this machine uses per tick. */ - public int SECONDARY_ENERGY_PER_TICK; + /** How much secondary energy (fuel) this machine uses per tick, not including upgrades. */ + public int BASE_SECONDARY_ENERGY_PER_TICK; + + /** How much secondary energy this machine uses per tick, including upgrades. */ + public int secondaryEnergyPerTick; public static int MAX_GAS = 200; @@ -70,7 +74,8 @@ public abstract class TileEntityAdvancedElectricMachine= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK) && gasTank.getStored() >= (int)MekanismUtils.getSecondaryEnergyPerTick(this, SECONDARY_ENERGY_PER_TICK)) + if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyPerTick) { setActive(true); operatingTicks++; - if(operatingTicks >= MekanismUtils.getTicks(this, TICKS_REQUIRED)) + if(operatingTicks >= ticksRequired) { operate(recipe); operatingTicks = 0; } - gasTank.draw(MekanismUtils.getSecondaryEnergyPerTick(this, SECONDARY_ENERGY_PER_TICK), true); - electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK); + gasTank.draw(secondaryEnergyPerTick, true); + electricityStored -= energyPerTick; } else { if(prevEnergy >= getEnergy()) @@ -124,7 +129,7 @@ public abstract class TileEntityAdvancedElectricMachine 0) { GasStack stack = getItemGas(inventory[1]); int gasNeeded = gasTank.getNeeded(); @@ -190,13 +195,18 @@ public abstract class TileEntityAdvancedElectricMachine, /** An arraylist of SideData for this machine. */ public ArrayList sideOutputs = new ArrayList(); - /** How much energy this machine uses per tick. */ - public double ENERGY_PER_TICK; + /** How much energy this machine uses per tick, un-upgraded. */ + public double BASE_ENERGY_PER_TICK; + + /** How much energy this machine uses per tick including upgrades */ + public double energyPerTick; /** How many ticks this machine has operated for. */ public int operatingTicks = 0; - /** Ticks required to operate -- or smelt an item. */ - public int TICKS_REQUIRED; + /** Un-upgraded ticks required to operate -- or smelt an item. */ + public int BASE_TICKS_REQUIRED; + + /** Ticks required including upgrades */ + public int ticksRequired; /** How many ticks must pass until this block's active state can sync with the client. */ public int updateDelay; @@ -66,6 +73,8 @@ public abstract class TileEntityBasicMachine, /** This machine's previous amount of energy. */ public double prevEnergy; + public RECIPE cachedRecipe = null; + public TileComponentUpgrade upgradeComponent; public TileComponentEjector ejectorComponent; @@ -75,14 +84,16 @@ public abstract class TileEntityBasicMachine, * @param name - full name of this machine * @param location - GUI texture path of this machine * @param perTick - the energy this machine consumes every tick in it's active state - * @param ticksRequired - how many ticks it takes to run a cycle + * @param baseTicksRequired - how many ticks it takes to run a cycle * @param maxEnergy - how much energy this machine can store */ - public TileEntityBasicMachine(String soundPath, String name, ResourceLocation location, double perTick, int ticksRequired, double maxEnergy) + public TileEntityBasicMachine(String soundPath, String name, ResourceLocation location, double perTick, int baseTicksRequired, double maxEnergy) { super("machine." + soundPath, name, maxEnergy); - ENERGY_PER_TICK = perTick; - TICKS_REQUIRED = ticksRequired; + BASE_ENERGY_PER_TICK = perTick; + energyPerTick = perTick; + BASE_TICKS_REQUIRED = baseTicksRequired; + ticksRequired = baseTicksRequired; guiLocation = location; isActive = false; } @@ -193,13 +204,7 @@ public abstract class TileEntityBasicMachine, */ public double getScaledProgress() { - return ((double)operatingTicks) / ((double)MekanismUtils.getTicks(this, TICKS_REQUIRED)); - } - - @Override - public double getMaxEnergy() - { - return MekanismUtils.getMaxEnergy(this, MAX_ELECTRICITY); + return ((double)operatingTicks) / ((double)ticksRequired); } @Override @@ -222,6 +227,20 @@ public abstract class TileEntityBasicMachine, } } + @Override + public void recalculateUpgradables(Upgrade upgrade) + { + super.recalculateUpgradables(upgrade); + + switch(upgrade) + { + case SPEED: + ticksRequired = MekanismUtils.getTicks(this, BASE_TICKS_REQUIRED); + case ENERGY: //and SPEED fall-through. + energyPerTick = MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_PER_TICK); + } + } + @Override @Method(modid = "ComputerCraft") public String getType() diff --git a/src/main/java/mekanism/common/tile/TileEntityChanceMachine.java b/src/main/java/mekanism/common/tile/TileEntityChanceMachine.java index e791e2acd..887bd4ba4 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChanceMachine.java +++ b/src/main/java/mekanism/common/tile/TileEntityChanceMachine.java @@ -54,21 +54,21 @@ public abstract class TileEntityChanceMachine= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK)) + if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= energyPerTick) { setActive(true); - if((operatingTicks+1) < MekanismUtils.getTicks(this, TICKS_REQUIRED)) + electricityStored -= energyPerTick; + + if((operatingTicks+1) < ticksRequired) { operatingTicks++; - electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK); } - else if((operatingTicks+1) >= MekanismUtils.getTicks(this, TICKS_REQUIRED)) + else { operate(recipe); operatingTicks = 0; - electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK); } } else { @@ -115,10 +115,7 @@ public abstract class TileEntityChanceMachine= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE)) + if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= energyUsage) { setActive(true); - setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE)); - if((operatingTicks+1) < MekanismUtils.getTicks(this, TICKS_REQUIRED)) + setEnergy(getEnergy() - energyUsage); + if((operatingTicks+1) < ticksRequired) { operatingTicks++; } @@ -167,7 +169,12 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock public CrystallizerRecipe getRecipe() { - return RecipeHandler.getChemicalCrystallizerRecipe(getInput()); + GasInput input = getInput(); + if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput())) + { + cachedRecipe = RecipeHandler.getChemicalCrystallizerRecipe(getInput()); + } + return cachedRecipe; } public boolean canOperate(CrystallizerRecipe recipe) @@ -295,22 +302,11 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock return i != 0 && i != 1; } - public int getScaledInputGasLevel(int i) - { - return inputTank != null ? inputTank.getStored()*i / MAX_GAS : 0; - } - public double getScaledProgress() { - return ((double)operatingTicks) / ((double)MekanismUtils.getTicks(this, TICKS_REQUIRED)); + return ((double)operatingTicks) / (double)ticksRequired; } - @Override - public double getMaxEnergy() - { - return MekanismUtils.getMaxEnergy(this, MAX_ELECTRICITY); - } - @Override public void setActive(boolean active) { @@ -488,4 +484,18 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock { inputTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("inputTank"))); } + + @Override + public void recalculateUpgradables(Upgrade upgrade) + { + super.recalculateUpgradables(upgrade); + + switch(upgrade) + { + case SPEED: + 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/TileEntityChemicalDissolutionChamber.java b/src/main/java/mekanism/common/tile/TileEntityChemicalDissolutionChamber.java index 975d6738f..60ef2cf8d 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChemicalDissolutionChamber.java +++ b/src/main/java/mekanism/common/tile/TileEntityChemicalDissolutionChamber.java @@ -14,6 +14,7 @@ import mekanism.api.gas.IGasHandler; import mekanism.api.gas.IGasItem; import mekanism.api.gas.ITubeConnection; import mekanism.common.Mekanism; +import mekanism.common.Upgrade; import mekanism.common.base.IRedstoneControl; import mekanism.common.base.ISustainedData; import mekanism.common.base.IUpgradeTile; @@ -41,7 +42,9 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri public static final int MAX_GAS = 10000; - public static final int INJECT_USAGE = 1; + public static final int BASE_INJECT_USAGE = 1; + + public int injectUsage = 1; public int updateDelay; @@ -55,9 +58,15 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri public int operatingTicks = 0; - public int TICKS_REQUIRED = 100; + public int BASE_TICKS_REQUIRED = 100; - public final double ENERGY_USAGE = usage.chemicalDissolutionChamberUsage; + public int ticksRequired = 100; + + public final double BASE_ENERGY_USAGE = usage.chemicalDissolutionChamberUsage; + + public double energyUsage = usage.chemicalDissolutionChamberUsage; + + public DissolutionRecipe cachedRecipe; public TileComponentUpgrade upgradeComponent = new TileComponentUpgrade(this, 4); @@ -99,7 +108,7 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri ChargeUtils.discharge(3, this); - if(inventory[0] != null && (injectTank.getGas() == null || injectTank.getStored() < injectTank.getMaxGas())) + if(inventory[0] != null && injectTank.getNeeded() > 0) { injectTank.receive(GasTransmission.removeGas(inventory[0], GasRegistry.getGas("sulfuricAcid"), injectTank.getNeeded()), true); } @@ -111,13 +120,13 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri boolean changed = false; - if(canOperate(recipe) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE) && injectTank.getStored() >= INJECT_USAGE && MekanismUtils.canFunction(this)) + if(canOperate(recipe) && getEnergy() >= energyUsage && injectTank.getStored() >= injectUsage && MekanismUtils.canFunction(this)) { setActive(true); - setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE)); + setEnergy(getEnergy() - energyUsage); minorOperate(); - if((operatingTicks+1) < MekanismUtils.getTicks(this, TICKS_REQUIRED)) + if((operatingTicks+1) < ticksRequired) { operatingTicks++; } @@ -205,12 +214,17 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri public double getScaledProgress() { - return ((double)operatingTicks) / ((double)TICKS_REQUIRED); + return ((double)operatingTicks) / ((double)BASE_TICKS_REQUIRED); } public DissolutionRecipe getRecipe() { - return RecipeHandler.getDissolutionRecipe(getInput()); + ItemStackInput input = getInput(); + if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput())) + { + cachedRecipe = RecipeHandler.getDissolutionRecipe(getInput()); + } + return cachedRecipe; } public ItemStackInput getInput() @@ -232,7 +246,7 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri public void minorOperate() { - injectTank.draw(INJECT_USAGE, true); + injectTank.draw(injectUsage, true); } @Override @@ -325,22 +339,6 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri return i != 0 && i != 1; } - @Override - public double getMaxEnergy() - { - return MekanismUtils.getMaxEnergy(this, MAX_ELECTRICITY); - } - - public int getScaledInjectGasLevel(int i) - { - return injectTank.getGas() != null ? injectTank.getStored()*i / MAX_GAS : 0; - } - - public int getScaledOutputGasLevel(int i) - { - return outputTank.getGas() != null ? outputTank.getStored()*i / MAX_GAS : 0; - } - @Override public void setActive(boolean active) { @@ -447,4 +445,19 @@ public class TileEntityChemicalDissolutionChamber extends TileEntityNoisyElectri injectTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("injectTank"))); outputTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("outputTank"))); } + + @Override + public void recalculateUpgradables(Upgrade upgrade) + { + super.recalculateUpgradables(upgrade); + + switch(upgrade) + { + case SPEED: + injectUsage = MekanismUtils.getSecondaryEnergyPerTick(this, BASE_INJECT_USAGE); + 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/TileEntityChemicalInfuser.java b/src/main/java/mekanism/common/tile/TileEntityChemicalInfuser.java index 24d755154..d08f373b8 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChemicalInfuser.java +++ b/src/main/java/mekanism/common/tile/TileEntityChemicalInfuser.java @@ -54,6 +54,8 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl public final double ENERGY_USAGE = usage.chemicalInfuserUsage; + public ChemicalInfuserRecipe cachedRecipe; + /** This machine's current RedstoneControl type. */ public RedstoneControl controlType = RedstoneControl.DISABLED; @@ -148,7 +150,12 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl public ChemicalInfuserRecipe getRecipe() { - return RecipeHandler.getChemicalInfuserRecipe(getInput()); + ChemicalPairInput input = getInput(); + if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput())) + { + cachedRecipe = RecipeHandler.getChemicalInfuserRecipe(getInput()); + } + return cachedRecipe; } public boolean canOperate(ChemicalInfuserRecipe recipe) diff --git a/src/main/java/mekanism/common/tile/TileEntityChemicalOxidizer.java b/src/main/java/mekanism/common/tile/TileEntityChemicalOxidizer.java index 0ab1d7c2d..cfe9287bd 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChemicalOxidizer.java +++ b/src/main/java/mekanism/common/tile/TileEntityChemicalOxidizer.java @@ -13,6 +13,7 @@ import mekanism.api.gas.IGasHandler; import mekanism.api.gas.IGasItem; import mekanism.api.gas.ITubeConnection; import mekanism.common.Mekanism; +import mekanism.common.Upgrade; import mekanism.common.base.IRedstoneControl; import mekanism.common.base.ISustainedData; import mekanism.common.base.IUpgradeTile; @@ -51,9 +52,15 @@ public class TileEntityChemicalOxidizer extends TileEntityNoisyElectricBlock imp public int operatingTicks = 0; - public int TICKS_REQUIRED = 100; + public int BASE_TICKS_REQUIRED = 100; - public final double ENERGY_USAGE = usage.rotaryCondensentratorUsage; + public int ticksRequired = BASE_TICKS_REQUIRED; + + public final double BASE_ENERGY_USAGE = usage.rotaryCondensentratorUsage; + + public double energyUsage = BASE_ENERGY_USAGE; + + public OxidationRecipe cachedRecipe; public RedstoneControl controlType = RedstoneControl.DISABLED; @@ -99,12 +106,12 @@ public class TileEntityChemicalOxidizer extends TileEntityNoisyElectricBlock imp gasTank.draw(GasTransmission.addGas(inventory[2], gasTank.getGas()), true); } - if(canOperate(recipe) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE) && MekanismUtils.canFunction(this)) + if(canOperate(recipe) && getEnergy() >= energyUsage && MekanismUtils.canFunction(this)) { setActive(true); - setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE)); + setEnergy(getEnergy() - energyUsage); - if(operatingTicks < MekanismUtils.getTicks(this, TICKS_REQUIRED)) + if(operatingTicks < ticksRequired) { operatingTicks++; } @@ -188,12 +195,17 @@ public class TileEntityChemicalOxidizer extends TileEntityNoisyElectricBlock imp public double getScaledProgress() { - return ((double)operatingTicks) / ((double)MekanismUtils.getTicks(this, TICKS_REQUIRED)); + return ((double)operatingTicks) / ((double)ticksRequired); } public OxidationRecipe getRecipe() { - return RecipeHandler.getOxidizerRecipe(getInput()); + ItemStackInput input = getInput(); + if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput())) + { + cachedRecipe = RecipeHandler.getOxidizerRecipe(getInput()); + } + return cachedRecipe; } public ItemStackInput getInput() @@ -283,12 +295,6 @@ public class TileEntityChemicalOxidizer extends TileEntityNoisyElectricBlock imp return i != 0 && i != 1; } - @Override - public double getMaxEnergy() - { - return MekanismUtils.getMaxEnergy(this, MAX_ELECTRICITY); - } - @Override public void setActive(boolean active) { @@ -360,4 +366,18 @@ public class TileEntityChemicalOxidizer extends TileEntityNoisyElectricBlock imp { gasTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("gasTank"))); } + + @Override + public void recalculateUpgradables(Upgrade upgrade) + { + super.recalculateUpgradables(upgrade); + + switch(upgrade) + { + case SPEED: + 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/TileEntityChemicalWasher.java b/src/main/java/mekanism/common/tile/TileEntityChemicalWasher.java index 6c3ccd421..62c093141 100644 --- a/src/main/java/mekanism/common/tile/TileEntityChemicalWasher.java +++ b/src/main/java/mekanism/common/tile/TileEntityChemicalWasher.java @@ -67,6 +67,8 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple public final double ENERGY_USAGE = usage.chemicalWasherUsage; + public WasherRecipe cachedRecipe; + /** This machine's current RedstoneControl type. */ public RedstoneControl controlType = RedstoneControl.DISABLED; @@ -148,7 +150,12 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple public WasherRecipe getRecipe() { - return RecipeHandler.getChemicalWasherRecipe(getInput()); + GasInput input = getInput(); + if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput())) + { + cachedRecipe = RecipeHandler.getChemicalWasherRecipe(getInput()); + } + return cachedRecipe; } public GasInput getInput() diff --git a/src/main/java/mekanism/common/tile/TileEntityContainerBlock.java b/src/main/java/mekanism/common/tile/TileEntityContainerBlock.java index e6bc16ead..fe58d1564 100644 --- a/src/main/java/mekanism/common/tile/TileEntityContainerBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityContainerBlock.java @@ -1,5 +1,6 @@ package mekanism.common.tile; +import mekanism.common.Upgrade; import mekanism.common.base.ISustainedInventory; import mekanism.common.util.InventoryUtils; import mekanism.common.util.MekanismUtils; @@ -40,7 +41,7 @@ public abstract class TileEntityContainerBlock extends TileEntityBasicBlock impl for(int tagCount = 0; tagCount < tagList.tagCount(); tagCount++) { - NBTTagCompound tagCompound = (NBTTagCompound)tagList.getCompoundTagAt(tagCount); + NBTTagCompound tagCompound = tagList.getCompoundTagAt(tagCount); byte slotID = tagCompound.getByte("Slot"); if(slotID >= 0 && slotID < getSizeInventory()) @@ -243,4 +244,6 @@ public abstract class TileEntityContainerBlock extends TileEntityBasicBlock impl { return true; } + + public void recalculateUpgradables(Upgrade upgradeType) {} } diff --git a/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java b/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java index cfc213889..34f46ccb9 100644 --- a/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java +++ b/src/main/java/mekanism/common/tile/TileEntityDigitalMiner.java @@ -15,6 +15,7 @@ import mekanism.api.MekanismConfig.usage; import mekanism.api.Range4D; import mekanism.common.HashList; import mekanism.common.Mekanism; +import mekanism.common.Upgrade; import mekanism.common.base.IActiveState; import mekanism.common.base.IAdvancedBoundingBlock; import mekanism.common.base.ILogisticalTransporter; @@ -74,7 +75,9 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I public ThreadMinerSearch searcher = new ThreadMinerSearch(this); - public final double ENERGY_USAGE = usage.digitalMinerUsage; + public final double BASE_ENERGY_USAGE = usage.digitalMinerUsage; + + public double energyUsage = usage.digitalMinerUsage; public int radius; @@ -90,6 +93,8 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I public int delay; + public int delayLength; + public int clientToMine; public boolean isActive; @@ -318,7 +323,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I public double getPerTick() { - double ret = MekanismUtils.getEnergyPerTick(this, ENERGY_USAGE); + double ret = energyUsage; if(silkTouch) { @@ -336,7 +341,7 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I public int getDelay() { - return MekanismUtils.getTicks(this, 80); + return delayLength; } /* @@ -987,12 +992,6 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I return new Coord4D(x, y, z, worldObj.provider.dimensionId); } - @Override - public double getMaxEnergy() - { - return MekanismUtils.getMaxEnergy(this, MAX_ELECTRICITY); - } - @Override public boolean isPowered() { @@ -1459,4 +1458,18 @@ public class TileEntityDigitalMiner extends TileEntityElectricBlock implements I } } } + + @Override + public void recalculateUpgradables(Upgrade upgrade) + { + super.recalculateUpgradables(upgrade); + + switch(upgrade) + { + case SPEED: + delayLength = MekanismUtils.getTicks(this, 80); + case ENERGY: + energyUsage = MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_USAGE); + } + } } diff --git a/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java b/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java index 02f0829cb..f099c0b41 100644 --- a/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityElectricBlock.java @@ -10,7 +10,9 @@ import mekanism.api.energy.IStrictEnergyAcceptor; import mekanism.api.energy.IStrictEnergyStorage; import mekanism.api.transmitters.IGridTransmitter; import mekanism.common.Mekanism; +import mekanism.common.Upgrade; import mekanism.common.base.ITileNetwork; +import mekanism.common.base.IUpgradeTile; import mekanism.common.util.MekanismUtils; import net.minecraft.nbt.NBTTagCompound; @@ -47,7 +49,10 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i public double electricityStored; /** Maximum amount of energy this machine can hold. */ - public double MAX_ELECTRICITY; + public double BASE_MAX_ENERGY; + + /** Actual maximum energy storage, including upgrades */ + public double maxEnergy; /** BuildCraft power handler. */ public PowerHandler powerHandler; @@ -56,12 +61,13 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i * The base of all blocks that deal with electricity. It has a facing state, initialized state, * and a current amount of stored energy. * @param name - full name of this block - * @param maxEnergy - how much energy this block can store + * @param baseMaxEnergy - how much energy this block can store */ - public TileEntityElectricBlock(String name, double maxEnergy) + public TileEntityElectricBlock(String name, double baseMaxEnergy) { super(name); - MAX_ELECTRICITY = maxEnergy; + BASE_MAX_ENERGY = baseMaxEnergy; + maxEnergy = BASE_MAX_ENERGY; if(MekanismUtils.useBuildCraft()) configure(); @@ -144,7 +150,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i @Override public double getMaxEnergy() { - return MAX_ELECTRICITY; + return maxEnergy; } @Override @@ -216,6 +222,15 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i nbtTags.setDouble("electricityStored", getEnergy()); } + @Override + public void recalculateUpgradables(Upgrade upgrade) + { + if(this instanceof IUpgradeTile && upgrade == Upgrade.ENERGY) + { + maxEnergy = MekanismUtils.getMaxEnergy(((IUpgradeTile)this), BASE_MAX_ENERGY); + } + } + @Override @Method(modid = "BuildCraftAPI|power") public PowerReceiver getPowerReceiver(ForgeDirection side) diff --git a/src/main/java/mekanism/common/tile/TileEntityElectricMachine.java b/src/main/java/mekanism/common/tile/TileEntityElectricMachine.java index cd834aad3..32e88792b 100644 --- a/src/main/java/mekanism/common/tile/TileEntityElectricMachine.java +++ b/src/main/java/mekanism/common/tile/TileEntityElectricMachine.java @@ -62,21 +62,20 @@ public abstract class TileEntityElectricMachine= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK)) + if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= energyPerTick) { setActive(true); + electricityStored -= energyPerTick; - if((operatingTicks+1) < MekanismUtils.getTicks(this, TICKS_REQUIRED)) + if((operatingTicks+1) < ticksRequired) { operatingTicks++; - electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK); } - else if((operatingTicks+1) >= MekanismUtils.getTicks(this, TICKS_REQUIRED)) + else if((operatingTicks+1) >= ticksRequired) { operate(recipe); operatingTicks = 0; - electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK); } } else { @@ -118,14 +117,21 @@ public abstract class TileEntityElectricMachine= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK) && gasTank.getStored() >= getSecondaryEnergyPerTick()) + if(MekanismUtils.canFunction(this) && canOperate(getInputSlot(process), getOutputSlot(process)) && getEnergy() >= energyPerTick && gasTank.getStored() >= getSecondaryEnergyPerTick()) { - if((progress[process]+1) < MekanismUtils.getTicks(this, TICKS_REQUIRED)) + if((progress[process]+1) < ticksRequired) { progress[process]++; gasTank.draw(getSecondaryEnergyPerTick(), true); - electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK); + electricityStored -= energyPerTick; } - else if((progress[process]+1) >= MekanismUtils.getTicks(this, TICKS_REQUIRED)) + else if((progress[process]+1) >= ticksRequired) { operate(getInputSlot(process), getOutputSlot(process)); progress[process] = 0; gasTank.draw(getSecondaryEnergyPerTick(), true); - electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK); + electricityStored -= energyPerTick; } } @@ -259,7 +271,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I } } - if(MekanismUtils.canFunction(this) && hasOperation && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK) && gasTank.getStored() >= getSecondaryEnergyPerTick()) + if(MekanismUtils.canFunction(this) && hasOperation && getEnergy() >= energyPerTick && gasTank.getStored() >= getSecondaryEnergyPerTick()) { setActive(true); } @@ -354,7 +366,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I public int getSecondaryEnergyPerTick() { - return MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick()); + return secondaryEnergyPerTick; } public void handleSecondaryFuel() @@ -474,7 +486,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I public int getScaledProgress(int i, int process) { - return progress[process]*i / MekanismUtils.getTicks(this, TICKS_REQUIRED); + return progress[process]*i / ticksRequired; } public int getScaledGasLevel(int i) @@ -503,7 +515,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I return false; } - return recipe.canOperate(inventory, inputSlot, outputSlot, gasTank, MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick())); + return recipe.canOperate(inventory, inputSlot, outputSlot, gasTank, secondaryEnergyPerTick); } BasicMachineRecipe recipe = recipeType.getRecipe(inventory[inputSlot]); @@ -527,7 +539,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I { AdvancedMachineRecipe recipe = recipeType.getRecipe(inventory[inputSlot], gasTank.getGasType()); - recipe.operate(inventory, inputSlot, outputSlot, gasTank, MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick())); + recipe.operate(inventory, inputSlot, outputSlot, gasTank, secondaryEnergyPerTick); } else { @@ -558,7 +570,14 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I super.handlePacketData(dataStream); clientActive = dataStream.readBoolean(); + RecipeType oldRecipe = recipeType; recipeType = RecipeType.values()[dataStream.readInt()]; + + if(recipeType != oldRecipe) + { + secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick()); + } + recipeTicks = dataStream.readInt(); controlType = RedstoneControl.values()[dataStream.readInt()]; sorting = dataStream.readBoolean(); @@ -595,7 +614,14 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I super.readFromNBT(nbtTags); clientActive = isActive = nbtTags.getBoolean("isActive"); + RecipeType oldRecipe = recipeType; recipeType = RecipeType.values()[nbtTags.getInteger("recipeType")]; + + if(recipeType != oldRecipe) + { + secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick()); + } + recipeTicks = nbtTags.getInteger("recipeTicks"); controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")]; sorting = nbtTags.getBoolean("sorting"); @@ -761,12 +787,6 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I return this == other; } - @Override - public double getMaxEnergy() - { - return MekanismUtils.getMaxEnergy(this, MAX_ELECTRICITY); - } - @Override public void setActive(boolean active) { @@ -903,4 +923,19 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I { return false; } + + @Override + public void recalculateUpgradables(Upgrade upgrade) + { + super.recalculateUpgradables(upgrade); + + switch(upgrade) + { + case SPEED: + ticksRequired = MekanismUtils.getTicks(this, BASE_TICKS_REQUIRED); + secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick()); + case ENERGY: + energyPerTick = MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_PER_TICK); + } + } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java b/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java index cf7285fb0..9352600c7 100644 --- a/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java +++ b/src/main/java/mekanism/common/tile/TileEntityMetallurgicInfuser.java @@ -14,6 +14,7 @@ import mekanism.common.Mekanism; import mekanism.common.MekanismItems; import mekanism.common.PacketHandler; import mekanism.common.SideData; +import mekanism.common.Upgrade; import mekanism.common.base.IEjector; import mekanism.common.base.IInvConfiguration; import mekanism.common.base.IRedstoneControl; @@ -54,10 +55,14 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i public int MAX_INFUSE = 1000; /** How much energy this machine consumes per-tick. */ - public double ENERGY_PER_TICK = usage.metallurgicInfuserUsage; + public double BASE_ENERGY_PER_TICK = usage.metallurgicInfuserUsage; + + public double energyPerTick = BASE_ENERGY_PER_TICK; /** How many ticks it takes to run an operation. */ - public int TICKS_REQUIRED = 200; + public int BASE_TICKS_REQUIRED = 200; + + public int ticksRequired = BASE_TICKS_REQUIRED; /** The amount of infuse this machine has stored. */ public InfuseStorage infuseStored = new InfuseStorage(); @@ -153,14 +158,14 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i MetallurgicInfuserRecipe recipe = RecipeHandler.getMetallurgicInfuserRecipe(getInput()); - if(MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK)) + if(MekanismUtils.canFunction(this) && getEnergy() >= energyPerTick) { if(canOperate(recipe)) { setActive(true); - setEnergy(getEnergy() - MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK)); + setEnergy(getEnergy() - energyPerTick); - if((operatingTicks + 1) < MekanismUtils.getTicks(this, TICKS_REQUIRED)) + if((operatingTicks + 1) < ticksRequired) { operatingTicks++; } else @@ -275,7 +280,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i public double getScaledProgress() { - return ((double)operatingTicks) / ((double)MekanismUtils.getTicks(this, TICKS_REQUIRED)); + return ((double)operatingTicks) / ((double)ticksRequired); } @Override @@ -439,12 +444,6 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i return sideOutputs.get(sideConfig[MekanismUtils.getBaseOrientation(side, facing)]).availableSlots; } - @Override - public double getMaxEnergy() - { - return MekanismUtils.getMaxEnergy(this, MAX_ELECTRICITY); - } - @Override public boolean canSetFacing(int side) { @@ -525,4 +524,18 @@ public class TileEntityMetallurgicInfuser extends TileEntityNoisyElectricBlock i { return ejectorComponent; } + + @Override + public void recalculateUpgradables(Upgrade upgrade) + { + super.recalculateUpgradables(upgrade); + + switch(upgrade) + { + case SPEED: + ticksRequired = MekanismUtils.getTicks(this, BASE_TICKS_REQUIRED); + case ENERGY: + energyPerTick = MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_PER_TICK); + } + } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/tile/TileEntityPRC.java b/src/main/java/mekanism/common/tile/TileEntityPRC.java index 8d7f2c59c..7956d6b7f 100644 --- a/src/main/java/mekanism/common/tile/TileEntityPRC.java +++ b/src/main/java/mekanism/common/tile/TileEntityPRC.java @@ -81,26 +81,26 @@ public class TileEntityPRC extends TileEntityBasicMachine= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK)) + if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= energyPerTick) { - TICKS_REQUIRED = recipe.ticks; + BASE_TICKS_REQUIRED = recipe.ticks; setActive(true); - if((operatingTicks+1) < MekanismUtils.getTicks(this, TICKS_REQUIRED)) + if((operatingTicks+1) < ticksRequired) { operatingTicks++; - electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK); + electricityStored -= energyPerTick; } - else if((operatingTicks+1) >= MekanismUtils.getTicks(this, TICKS_REQUIRED) && electricityStored >= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK + recipe.extraEnergy)) + else if((operatingTicks+1) >= ticksRequired && getEnergy() >= MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_PER_TICK + recipe.extraEnergy)) { operate(recipe); operatingTicks = 0; - electricityStored -= MekanismUtils.getEnergyPerTick(this, ENERGY_PER_TICK + recipe.extraEnergy); + electricityStored -= MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_PER_TICK + recipe.extraEnergy); } } else { - TICKS_REQUIRED = 100; + BASE_TICKS_REQUIRED = 100; if(prevEnergy >= getEnergy()) { @@ -154,7 +154,12 @@ public class TileEntityPRC extends TileEntityBasicMachine 0 && MekanismUtils.canFunction(this); + return electricityStored < BASE_MAX_ENERGY && bioFuelSlot.fluidStored > 0 && MekanismUtils.canFunction(this); } @Override @@ -241,9 +241,9 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements IFlui case 1: return new Object[] {output}; case 2: - return new Object[] {MAX_ELECTRICITY}; + return new Object[] {BASE_MAX_ENERGY}; case 3: - return new Object[] {(MAX_ELECTRICITY-electricityStored)}; + return new Object[] {(BASE_MAX_ENERGY -electricityStored)}; case 4: return new Object[] {bioFuelSlot.fluidStored}; case 5: diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java index 332dc10a6..104063ce8 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityHeatGenerator.java @@ -143,7 +143,7 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu @Override public boolean canOperate() { - return electricityStored < MAX_ELECTRICITY && lavaTank.getFluid() != null && lavaTank.getFluid().amount >= 10 && MekanismUtils.canFunction(this); + return electricityStored < BASE_MAX_ENERGY && lavaTank.getFluid() != null && lavaTank.getFluid().amount >= 10 && MekanismUtils.canFunction(this); } @Override @@ -288,9 +288,9 @@ public class TileEntityHeatGenerator extends TileEntityGenerator implements IFlu case 1: return new Object[] {output}; case 2: - return new Object[] {MAX_ELECTRICITY}; + return new Object[] {BASE_MAX_ENERGY}; case 3: - return new Object[] {(MAX_ELECTRICITY-electricityStored)}; + return new Object[] {(BASE_MAX_ENERGY -electricityStored)}; case 4: return new Object[] {lavaTank.getFluid() != null ? lavaTank.getFluid().amount : 0}; case 5: diff --git a/src/main/java/mekanism/generators/common/tile/TileEntitySolarGenerator.java b/src/main/java/mekanism/generators/common/tile/TileEntitySolarGenerator.java index 55e230547..a6fe83c3a 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntitySolarGenerator.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntitySolarGenerator.java @@ -161,9 +161,9 @@ public class TileEntitySolarGenerator extends TileEntityGenerator case 1: return new Object[] {output}; case 2: - return new Object[] {MAX_ELECTRICITY}; + return new Object[] {BASE_MAX_ENERGY}; case 3: - return new Object[] {(MAX_ELECTRICITY-electricityStored)}; + return new Object[] {(BASE_MAX_ENERGY -electricityStored)}; case 4: return new Object[] {seesSun}; default: diff --git a/src/main/java/mekanism/generators/common/tile/TileEntityWindTurbine.java b/src/main/java/mekanism/generators/common/tile/TileEntityWindTurbine.java index cd897ea8f..441ca1fde 100644 --- a/src/main/java/mekanism/generators/common/tile/TileEntityWindTurbine.java +++ b/src/main/java/mekanism/generators/common/tile/TileEntityWindTurbine.java @@ -91,9 +91,9 @@ public class TileEntityWindTurbine extends TileEntityGenerator implements IBound case 1: return new Object[] {output}; case 2: - return new Object[] {MAX_ELECTRICITY}; + return new Object[] {BASE_MAX_ENERGY}; case 3: - return new Object[] {(MAX_ELECTRICITY-electricityStored)}; + return new Object[] {(BASE_MAX_ENERGY -electricityStored)}; case 4: return new Object[] {getMultiplier()}; default: @@ -105,7 +105,7 @@ public class TileEntityWindTurbine extends TileEntityGenerator implements IBound @Override public boolean canOperate() { - return electricityStored < MAX_ELECTRICITY && getMultiplier() > 0 && MekanismUtils.canFunction(this); + return electricityStored < BASE_MAX_ENERGY && getMultiplier() > 0 && MekanismUtils.canFunction(this); } @Override