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.)
This commit is contained in:
Ben Spiers 2014-09-06 21:14:49 +01:00
parent 3160ec0691
commit b75ff5d9a1
33 changed files with 407 additions and 206 deletions

View file

@ -38,7 +38,7 @@ public class GuiAdvancedElectricMachine extends GuiMekanism
@Override
public List<String> 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));

View file

@ -36,7 +36,7 @@ public class GuiChanceMachine extends GuiMekanism
@Override
public List<String> 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));

View file

@ -59,7 +59,7 @@ public class GuiChemicalCrystallizer extends GuiMekanism
@Override
public List<String> 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")));

View file

@ -37,7 +37,7 @@ public class GuiChemicalDissolutionChamber extends GuiMekanism
@Override
public List<String> 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")));

View file

@ -37,7 +37,7 @@ public class GuiChemicalOxidizer extends GuiMekanism
@Override
public List<String> 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")));

View file

@ -36,7 +36,7 @@ public class GuiElectricMachine extends GuiMekanism
@Override
public List<String> 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));

View file

@ -38,7 +38,7 @@ public class GuiFactory extends GuiMekanism
@Override
public List<String> 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));

View file

@ -42,7 +42,7 @@ public class GuiMetallurgicInfuser extends GuiMekanism
@Override
public List<String> 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")));

View file

@ -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"));

View file

@ -102,7 +102,7 @@ public interface IFactory
{
if(usesFuel)
{
return getTile().SECONDARY_ENERGY_PER_TICK;
return getTile().BASE_SECONDARY_ENERGY_PER_TICK;
}
return 0;

View file

@ -16,4 +16,13 @@ public abstract class ChanceMachineRecipe<RECIPE extends ChanceMachineRecipe<REC
{
return getInput().useItemStackFromInventory(inventory, inputIndex, false) && getOutput().applyOutputs(inventory, primaryIndex, secondaryIndex, false);
}
public void operate(ItemStack[] inventory)
{
if(getInput().useItemStackFromInventory(inventory, 0, true))
{
getOutput().applyOutputs(inventory, 2, 4, true);
}
}
}

View file

@ -11,6 +11,7 @@ import mekanism.api.gas.ITubeConnection;
import mekanism.common.Mekanism;
import mekanism.common.MekanismItems;
import mekanism.common.SideData;
import mekanism.common.Upgrade;
import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.inputs.AdvancedMachineInput;
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
@ -34,8 +35,11 @@ import dan200.computercraft.api.peripheral.IComputerAccess;
public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedMachineRecipe<RECIPE>> extends TileEntityBasicMachine<AdvancedMachineInput, ItemStackOutput, RECIPE> 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<RECIPE extends AdvancedM
inventory = new ItemStack[5];
SECONDARY_ENERGY_PER_TICK = secondaryPerTick;
BASE_SECONDARY_ENERGY_PER_TICK = secondaryPerTick;
secondaryEnergyPerTick = secondaryPerTick;
upgradeComponent = new TileComponentUpgrade(this, 4);
ejectorComponent = new TileComponentEjector(this, sideOutputs.get(3));
@ -98,23 +103,23 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
boolean changed = false;
RECIPE recipe = RecipeHandler.getRecipe(getInput(), getRecipes());
RECIPE recipe = getRecipe();
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= 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<RECIPE extends AdvancedM
}
}
if(changed && !canOperate(recipe) && RecipeHandler.getRecipe(getInput(), getRecipes()) == null)
if(changed && !canOperate(recipe) && getRecipe() == null)
{
operatingTicks = 0;
}
@ -135,7 +140,7 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
public void handleSecondaryFuel()
{
if(inventory[1] != null)
if(inventory[1] != null && gasTank.getNeeded() > 0)
{
GasStack stack = getItemGas(inventory[1]);
int gasNeeded = gasTank.getNeeded();
@ -190,13 +195,18 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
@Override
public RECIPE getRecipe()
{
return RecipeHandler.getRecipe(getInput(), getRecipes());
AdvancedMachineInput input = getInput();
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
{
cachedRecipe = RecipeHandler.getRecipe(input, getRecipes());
}
return cachedRecipe;
}
@Override
public void operate(RECIPE recipe)
{
recipe.operate(inventory, 0, 2, gasTank, MekanismUtils.getSecondaryEnergyPerTick(this, SECONDARY_ENERGY_PER_TICK));
recipe.operate(inventory, 0, 2, gasTank, secondaryEnergyPerTick);
markDirty();
ejectorComponent.onOutput();
@ -205,7 +215,7 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
@Override
public boolean canOperate(RECIPE recipe)
{
return recipe != null && recipe.canOperate(inventory, 0, 2, gasTank, MekanismUtils.getSecondaryEnergyPerTick(this, SECONDARY_ENERGY_PER_TICK));
return recipe != null && recipe.canOperate(inventory, 0, 2, gasTank, secondaryEnergyPerTick);
}
@Override
@ -311,6 +321,17 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
return false;
}
@Override
public void recalculateUpgradables(Upgrade upgrade)
{
super.recalculateUpgradables(upgrade);
if(upgrade == Upgrade.SPEED)
{
secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTick(this, BASE_SECONDARY_ENERGY_PER_TICK);
}
}
@Override
@Method(modid = "ComputerCraft")
public String[] getMethodNames()
@ -337,9 +358,9 @@ public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedM
case 5:
return new Object[] {canOperate(RecipeHandler.getRecipe(getInput(), getRecipes()))};
case 6:
return new Object[] {MekanismUtils.getMaxEnergy(this, getMaxEnergy())};
return new Object[] {maxEnergy};
case 7:
return new Object[] {(MekanismUtils.getMaxEnergy(this, getMaxEnergy())-getEnergy())};
return new Object[] {maxEnergy-getEnergy()};
default:
Mekanism.logger.error("Attempted to call unknown method with computer ID " + computer.getID());
return new Object[] {"Unknown command."};

View file

@ -7,6 +7,7 @@ import mekanism.api.MekanismConfig.general;
import mekanism.api.Range4D;
import mekanism.common.Mekanism;
import mekanism.common.SideData;
import mekanism.common.Upgrade;
import mekanism.common.base.IEjector;
import mekanism.common.base.IElectricMachine;
import mekanism.common.base.IInvConfiguration;
@ -39,14 +40,20 @@ public abstract class TileEntityBasicMachine<INPUT extends MachineInput<INPUT>,
/** An arraylist of SideData for this machine. */
public ArrayList<SideData> sideOutputs = new ArrayList<SideData>();
/** 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<INPUT extends MachineInput<INPUT>,
/** 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<INPUT extends MachineInput<INPUT>,
* @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<INPUT extends MachineInput<INPUT>,
*/
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<INPUT extends MachineInput<INPUT>,
}
}
@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()

View file

@ -54,21 +54,21 @@ public abstract class TileEntityChanceMachine<RECIPE extends ChanceMachineRecipe
RECIPE recipe = getRecipe();
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= 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<RECIPE extends ChanceMachineRecipe
@Override
public void operate(RECIPE recipe)
{
if(recipe.getInput().useItemStackFromInventory(inventory, 0, true))
{
recipe.getOutput().applyOutputs(inventory, 2, 4, true);
}
recipe.operate(inventory);
markDirty();
ejectorComponent.onOutput();
@ -148,7 +145,12 @@ public abstract class TileEntityChanceMachine<RECIPE extends ChanceMachineRecipe
@Override
public RECIPE getRecipe()
{
return RecipeHandler.getChanceRecipe(getInput(), getRecipes());
ItemStackInput input = getInput();
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
{
cachedRecipe = RecipeHandler.getChanceRecipe(input, getRecipes());
}
return cachedRecipe;
}
@Override

View file

@ -16,6 +16,7 @@ import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.Mekanism;
import mekanism.common.SideData;
import mekanism.common.Upgrade;
import mekanism.common.base.IEjector;
import mekanism.common.base.IInvConfiguration;
import mekanism.common.base.IRedstoneControl;
@ -45,7 +46,6 @@ import io.netty.buffer.ByteBuf;
public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock implements IGasHandler, ITubeConnection, IRedstoneControl, IInvConfiguration, IUpgradeTile, ISustainedData
{
public static final int MAX_GAS = 10000;
public static final int MAX_FLUID = 10000;
public byte[] sideConfig = new byte[] {0, 3, 0, 0, 1, 2};
@ -53,15 +53,13 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock
public GasTank inputTank = new GasTank(MAX_GAS);
public static int WATER_USAGE = 5;
public int updateDelay;
public int gasOutput = 16;
public int operatingTicks;
public int TICKS_REQUIRED = 200;
public int BASE_TICKS_REQUIRED = 200;
public int ticksRequired = 200;
public boolean isActive;
@ -73,7 +71,11 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock
public float spin;
public final double ENERGY_USAGE = usage.chemicalCrystallizerUsage;
public final double BASE_ENERGY_USAGE = usage.chemicalCrystallizerUsage;
public double energyUsage = usage.chemicalCrystallizerUsage;
public CrystallizerRecipe cachedRecipe;
/** This machine's current RedstoneControl type. */
public RedstoneControl controlType = RedstoneControl.DISABLED;
@ -129,12 +131,12 @@ public class TileEntityChemicalCrystallizer extends TileEntityNoisyElectricBlock
inputTank.receive(GasTransmission.removeGas(inventory[0], inputTank.getGasType(), inputTank.getNeeded()), true);
}
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= 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,20 +302,9 @@ 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));
}
@Override
public double getMaxEnergy()
{
return MekanismUtils.getMaxEnergy(this, MAX_ELECTRICITY);
return ((double)operatingTicks) / (double)ticksRequired;
}
@Override
@ -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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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)

View file

@ -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);
}
}
}

View file

@ -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()

View file

@ -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) {}
}

View file

@ -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);
}
}
}

View file

@ -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)

View file

@ -62,21 +62,20 @@ public abstract class TileEntityElectricMachine<RECIPE extends BasicMachineRecip
RECIPE recipe = getRecipe();
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= 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<RECIPE extends BasicMachineRecip
return false;
}
@Override
public ItemStackInput getInput()
{
return new ItemStackInput(inventory[0]);
}
@Override
public RECIPE getRecipe()
{
return RecipeHandler.getRecipe(getInput(), getRecipes());
ItemStackInput input = getInput();
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
{
cachedRecipe = RecipeHandler.getRecipe(input, getRecipes());
}
return cachedRecipe;
}
@Override

View file

@ -73,6 +73,8 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
public boolean isActive = false;
public SeparatorRecipe cachedRecipe;
public TileEntityElectrolyticSeparator()
{
super("ElectrolyticSeparator", MachineType.ELECTROLYTIC_SEPARATOR.baseEnergy);
@ -201,7 +203,12 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
public SeparatorRecipe getRecipe()
{
return RecipeHandler.getElectrolyticSeparatorRecipe(getInput());
FluidInput input = getInput();
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
{
cachedRecipe = RecipeHandler.getElectrolyticSeparatorRecipe(getInput());
}
return cachedRecipe;
}
public FluidInput getInput()
@ -322,7 +329,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
*/
public int getScaledEnergyLevel(int i)
{
return (int)(electricityStored*i / MAX_ELECTRICITY);
return (int)(electricityStored*i / BASE_MAX_ENERGY);
}
@Override
@ -495,9 +502,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
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[] {fluidTank.getFluid() != null ? fluidTank.getFluid().amount : 0};
case 5:

View file

@ -22,6 +22,7 @@ import mekanism.common.Mekanism;
import mekanism.common.MekanismItems;
import mekanism.common.SideData;
import mekanism.common.Tier.FactoryTier;
import mekanism.common.Upgrade;
import mekanism.common.base.IEjector;
import mekanism.common.base.IFactory.RecipeType;
import mekanism.common.base.IInvConfiguration;
@ -66,10 +67,19 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
public int[] progress;
/** How many ticks it takes, by default, to run an operation. */
public int TICKS_REQUIRED = 200;
public int BASE_TICKS_REQUIRED = 200;
/** How many ticks it takes, with upgrades, to run an operation */
public int ticksRequired = 200;
/** How much energy each operation consumes per tick, without upgrades. */
public double BASE_ENERGY_PER_TICK = usage.factoryUsage;
/** How much energy each operation consumes per tick. */
public double ENERGY_PER_TICK = usage.factoryUsage;
public double energyPerTick = usage.factoryUsage;
/** How much secondary energy each operation consumes per tick */
public int secondaryEnergyPerTick = 0;
/** How long it takes this factory to switch recipe types. */
public int RECIPE_TICKS_REQUIRED = 40;
@ -187,7 +197,7 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
{
recipeTicks++;
}
else if(recipeTicks == RECIPE_TICKS_REQUIRED)
else
{
recipeTicks = 0;
@ -206,6 +216,8 @@ public class TileEntityFactory extends TileEntityNoisyElectricBlock implements I
recipeType = toSet;
gasTank.setGas(null);
secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTick(this, recipeType.getSecondaryEnergyPerTick());
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
MekanismUtils.saveChunk(this);
@ -221,21 +233,21 @@ 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() >= 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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -81,26 +81,26 @@ public class TileEntityPRC extends TileEntityBasicMachine<PressurizedInput, Pres
ChargeUtils.discharge(1, this);
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= 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<PressurizedInput, Pres
@Override
public PressurizedRecipe getRecipe()
{
return RecipeHandler.getPRCRecipe(getInput());
PressurizedInput input = getInput();
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
{
cachedRecipe = RecipeHandler.getPRCRecipe(input);
}
return cachedRecipe;
}
@Override
@ -178,12 +183,6 @@ public class TileEntityPRC extends TileEntityBasicMachine<PressurizedInput, Pres
return recipe != null && recipe.canOperate(inventory, inputFluidTank, inputGasTank, outputGasTank);
}
@Override
public double getMaxEnergy()
{
return MekanismUtils.getMaxEnergy(this, MAX_ELECTRICITY);
}
@Override
public boolean canExtractItem(int slotID, ItemStack itemstack, int side)
{

View file

@ -107,16 +107,8 @@ public class TileComponentUpgrade implements ITileComponent
public void addUpgrade(Upgrade upgrade)
{
upgrades.put(upgrade, Math.min(upgrade.getMax(), getUpgrades(upgrade)+1));
}
public void setUpgrades(Upgrade upgrade, int amount)
{
upgrades.put(upgrade, amount);
if(upgrades.get(upgrade) == 0)
{
upgrades.remove(upgrade);
}
tileEntity.recalculateUpgradables(upgrade);
}
public void removeUpgrade(Upgrade upgrade)
@ -127,6 +119,8 @@ public class TileComponentUpgrade implements ITileComponent
{
upgrades.remove(upgrade);
}
tileEntity.recalculateUpgradables(upgrade);
}
public void setSupported(Upgrade upgrade)
@ -162,6 +156,11 @@ public class TileComponentUpgrade implements ITileComponent
}
upgradeTicks = dataStream.readInt();
for(Upgrade upgrade : getSupportedTypes())
{
tileEntity.recalculateUpgradables(upgrade);
}
}
@Override
@ -182,6 +181,10 @@ public class TileComponentUpgrade implements ITileComponent
public void read(NBTTagCompound nbtTags)
{
upgrades = Upgrade.buildMap(nbtTags);
for(Upgrade upgrade : getSupportedTypes())
{
tileEntity.recalculateUpgradables(upgrade);
}
}
@Override

View file

@ -1034,7 +1034,6 @@ public final class MekanismUtils
return true;
}
World world = tileEntity.getWorldObj();
IRedstoneControl control = (IRedstoneControl)tileEntity;
if(control.getControlType() == RedstoneControl.DISABLED)

View file

@ -156,7 +156,7 @@ public class TileEntityBioGenerator extends TileEntityGenerator implements IFlui
@Override
public boolean canOperate()
{
return electricityStored < MAX_ELECTRICITY && bioFuelSlot.fluidStored > 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:

View file

@ -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:

View file

@ -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:

View file

@ -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