Chemical Infuser, Chemical Washer and Electrolytic Separator are now upgradeable

This commit is contained in:
Aidan C. Brady 2015-02-18 19:33:03 -05:00
parent f320aa4337
commit b419519cc0
10 changed files with 166 additions and 50 deletions

View file

@ -19,7 +19,6 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityChemicalInfuser; import mekanism.common.tile.TileEntityChemicalInfuser;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType; import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -37,11 +36,19 @@ public class GuiChemicalInfuser extends GuiMekanism
tileEntity = tentity; tileEntity = tentity;
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalInfuser.png"))); guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalInfuser.png")));
guiElements.add(new GuiUpgradeTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalInfuser.png")));
guiElements.add(new GuiEnergyInfo(new IInfoHandler() { guiElements.add(new GuiEnergyInfo(new IInfoHandler() {
@Override @Override
public List<String> getInfo() public List<String> getInfo()
{ {
String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.ENERGY_USAGE); double usage = 0;
if(tileEntity.getRecipe() != null)
{
usage = tileEntity.getUpgradedUsage(tileEntity.getRecipe())*tileEntity.BASE_ENERGY_USAGE;
}
String multiplier = MekanismUtils.getEnergyDisplay(usage);
return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy()));
} }
}, this, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalInfuser.png"))); }, this, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalInfuser.png")));

View file

@ -45,7 +45,7 @@ public class GuiChemicalWasher extends GuiMekanism
@Override @Override
public List<String> getInfo() public List<String> getInfo()
{ {
String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.energyUsage); String multiplier = MekanismUtils.getEnergyDisplay(tileEntity.BASE_ENERGY_USAGE*tileEntity.getUpgradedUsage());
return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy()));
} }
}, this, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalWasher.png"))); }, this, MekanismUtils.getResource(ResourceType.GUI, "GuiChemicalWasher.png")));

View file

@ -21,7 +21,6 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityElectrolyticSeparator; import mekanism.common.tile.TileEntityElectrolyticSeparator;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType; import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.fluids.FluidTank; import net.minecraftforge.fluids.FluidTank;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -40,11 +39,19 @@ public class GuiElectrolyticSeparator extends GuiMekanism
tileEntity = tentity; tileEntity = tentity;
guiElements.add(new GuiUpgradeTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiElectrolyticSeparator.png")));
guiElements.add(new GuiEnergyInfo(new IInfoHandler() { guiElements.add(new GuiEnergyInfo(new IInfoHandler() {
@Override @Override
public List<String> getInfo() public List<String> getInfo()
{ {
String multiplier = MekanismUtils.getEnergyDisplay(general.FROM_H2*2); double usage = 0;
if(tileEntity.getRecipe() != null)
{
usage = tileEntity.getUpgradedUsage(tileEntity.getRecipe())*tileEntity.getRecipe().extraEnergy;
}
String multiplier = MekanismUtils.getEnergyDisplay(usage);
return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy())); return ListUtils.asList("Using: " + multiplier + "/t", "Needed: " + MekanismUtils.getEnergyDisplay(tileEntity.getMaxEnergy()-tileEntity.getEnergy()));
} }
}, this, MekanismUtils.getResource(ResourceType.GUI, "GuiElectrolyticSeparator.png"))); }, this, MekanismUtils.getResource(ResourceType.GUI, "GuiElectrolyticSeparator.png")));

View file

@ -154,7 +154,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer
{ {
super(Material.iron); super(Material.iron);
setHardness(3.5F); setHardness(3.5F);
setResistance(8F); setResistance(16F);
setCreativeTab(Mekanism.tabMekanism); setCreativeTab(Mekanism.tabMekanism);
blockType = type; blockType = type;
} }

View file

@ -580,9 +580,9 @@ public final class RecipeHandler
{ {
Map.Entry entry = (Map.Entry)obj; Map.Entry entry = (Map.Entry)obj;
if(entry.getKey() instanceof FluidStack) if(entry.getKey() instanceof FluidInput)
{ {
if(((FluidStack)entry.getKey()).getFluid() == input) if(((FluidInput)entry.getKey()).ingredient.getFluid() == input)
{ {
return true; return true;
} }

View file

@ -31,14 +31,14 @@ public class SeparatorRecipe extends MachineRecipe<FluidInput, ChemicalPairOutpu
public boolean canOperate(FluidTank fluidTank, GasTank leftTank, GasTank rightTank) public boolean canOperate(FluidTank fluidTank, GasTank leftTank, GasTank rightTank)
{ {
return getInput().useFluid(fluidTank, false, 1) && getOutput().applyOutputs(leftTank, rightTank, false); return getInput().useFluid(fluidTank, false, 1) && getOutput().applyOutputs(leftTank, rightTank, false, 1);
} }
public void operate(FluidTank fluidTank, GasTank leftTank, GasTank rightTank) public void operate(FluidTank fluidTank, GasTank leftTank, GasTank rightTank, int scale)
{ {
if(getInput().useFluid(fluidTank, true, 1)) if(getInput().useFluid(fluidTank, true, scale))
{ {
getOutput().applyOutputs(leftTank, rightTank, true); getOutput().applyOutputs(leftTank, rightTank, true, scale);
} }
} }
} }

View file

@ -55,25 +55,29 @@ public class ChemicalPairOutput extends MachineOutput<ChemicalPairOutput>
return new ChemicalPairOutput(rightGas, leftGas); return new ChemicalPairOutput(rightGas, leftGas);
} }
public boolean applyOutputs(GasTank leftTank, GasTank rightTank, boolean doEmit) public boolean applyOutputs(GasTank leftTank, GasTank rightTank, boolean doEmit, int scale)
{ {
if(leftTank.canReceive(leftGas.getGas()) && rightTank.canReceive(rightGas.getGas())) if(leftTank.canReceive(leftGas.getGas()) && rightTank.canReceive(rightGas.getGas()))
{ {
if(leftTank.getNeeded() >= leftGas.amount && rightTank.getNeeded() >= rightGas.amount) if(leftTank.getNeeded() >= leftGas.amount*scale && rightTank.getNeeded() >= rightGas.amount*scale)
{ {
leftTank.receive(leftGas, doEmit); leftTank.receive(leftGas.copy().withAmount(leftGas.amount*scale), doEmit);
rightTank.receive(rightGas, doEmit); rightTank.receive(rightGas.copy().withAmount(rightGas.amount*scale), doEmit);
return true;
}
} else if(leftTank.canReceive(rightGas.getGas()) && rightTank.canReceive(leftGas.getGas()))
{
if(leftTank.getNeeded() >= rightGas.amount && rightTank.getNeeded() >= leftGas.amount)
{
leftTank.receive(rightGas, doEmit);
rightTank.receive(leftGas, doEmit);
return true; return true;
} }
} }
else if(leftTank.canReceive(rightGas.getGas()) && rightTank.canReceive(leftGas.getGas()))
{
if(leftTank.getNeeded() >= rightGas.amount*scale && rightTank.getNeeded() >= leftGas.amount*scale)
{
leftTank.receive(rightGas.copy().withAmount(rightGas.amount*scale), doEmit);
rightTank.receive(leftGas.copy().withAmount(leftGas.amount*scale), doEmit);
return true;
}
}
return false; return false;
} }

View file

@ -1,5 +1,7 @@
package mekanism.common.tile; package mekanism.common.tile;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
import mekanism.api.Coord4D; import mekanism.api.Coord4D;
@ -14,17 +16,19 @@ import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem; import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection; import mekanism.api.gas.ITubeConnection;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.Upgrade;
import mekanism.common.base.IRedstoneControl; import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.ISustainedData; import mekanism.common.base.ISustainedData;
import mekanism.common.base.IUpgradeTile;
import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.inputs.ChemicalPairInput; import mekanism.common.recipe.inputs.ChemicalPairInput;
import mekanism.common.recipe.machines.ChemicalInfuserRecipe; import mekanism.common.recipe.machines.ChemicalInfuserRecipe;
import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.ChargeUtils; import mekanism.common.util.ChargeUtils;
import mekanism.common.util.InventoryUtils; import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -32,9 +36,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import io.netty.buffer.ByteBuf; public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock implements IGasHandler, ITubeConnection, IRedstoneControl, ISustainedData, IUpgradeTile
public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock implements IGasHandler, ITubeConnection, IRedstoneControl, ISustainedData
{ {
public GasTank leftTank = new GasTank(MAX_GAS); public GasTank leftTank = new GasTank(MAX_GAS);
public GasTank rightTank = new GasTank(MAX_GAS); public GasTank rightTank = new GasTank(MAX_GAS);
@ -52,17 +54,19 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
public double prevEnergy; public double prevEnergy;
public final double ENERGY_USAGE = usage.chemicalInfuserUsage; public final double BASE_ENERGY_USAGE = usage.chemicalInfuserUsage;
public ChemicalInfuserRecipe cachedRecipe; public ChemicalInfuserRecipe cachedRecipe;
public TileComponentUpgrade upgradeComponent = new TileComponentUpgrade(this, 4);
/** This machine's current RedstoneControl type. */ /** This machine's current RedstoneControl type. */
public RedstoneControl controlType = RedstoneControl.DISABLED; public RedstoneControl controlType = RedstoneControl.DISABLED;
public TileEntityChemicalInfuser() public TileEntityChemicalInfuser()
{ {
super("machine.cheminfuser", "ChemicalInfuser", MachineType.CHEMICAL_INFUSER.baseEnergy); super("machine.cheminfuser", "ChemicalInfuser", MachineType.CHEMICAL_INFUSER.baseEnergy);
inventory = new ItemStack[4]; inventory = new ItemStack[5];
} }
@Override @Override
@ -110,10 +114,10 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
centerTank.draw(GasTransmission.addGas(inventory[2], centerTank.getGas()), true); centerTank.draw(GasTransmission.addGas(inventory[2], centerTank.getGas()), true);
} }
if(canOperate(recipe) && getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this)) if(canOperate(recipe) && getEnergy() >= BASE_ENERGY_USAGE && MekanismUtils.canFunction(this))
{ {
setActive(true); setActive(true);
setEnergy(getEnergy() - ENERGY_USAGE); setEnergy(getEnergy() - BASE_ENERGY_USAGE);
operate(recipe); operate(recipe);
} }
@ -143,6 +147,27 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
} }
} }
public int getUpgradedUsage(ChemicalInfuserRecipe recipe)
{
int possibleProcess = 0;
if(leftTank.getGasType() == recipe.recipeInput.leftGas.getGas())
{
possibleProcess = leftTank.getStored()/recipe.recipeInput.leftGas.amount;
possibleProcess = Math.min(rightTank.getStored()/recipe.recipeInput.rightGas.amount, possibleProcess);
}
else {
possibleProcess = leftTank.getStored()/recipe.recipeInput.rightGas.amount;
possibleProcess = Math.min(rightTank.getStored()/recipe.recipeInput.leftGas.amount, possibleProcess);
}
possibleProcess = Math.min(centerTank.getNeeded()/recipe.recipeOutput.output.amount, possibleProcess);
possibleProcess = Math.min((int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED)), possibleProcess);
possibleProcess = Math.min((int)(getEnergy()/BASE_ENERGY_USAGE), possibleProcess);
return possibleProcess;
}
public ChemicalPairInput getInput() public ChemicalPairInput getInput()
{ {
return new ChemicalPairInput(leftTank.getGas(), rightTank.getGas()); return new ChemicalPairInput(leftTank.getGas(), rightTank.getGas());
@ -151,10 +176,12 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
public ChemicalInfuserRecipe getRecipe() public ChemicalInfuserRecipe getRecipe()
{ {
ChemicalPairInput input = getInput(); ChemicalPairInput input = getInput();
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput())) if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
{ {
cachedRecipe = RecipeHandler.getChemicalInfuserRecipe(getInput()); cachedRecipe = RecipeHandler.getChemicalInfuserRecipe(getInput());
} }
return cachedRecipe; return cachedRecipe;
} }
@ -488,4 +515,22 @@ public class TileEntityChemicalInfuser extends TileEntityNoisyElectricBlock impl
rightTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("rightTank"))); rightTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("rightTank")));
centerTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("centerTank"))); centerTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("centerTank")));
} }
@Override
public TileComponentUpgrade getComponent()
{
return upgradeComponent;
}
@Override
public void recalculateUpgradables(Upgrade upgrade)
{
super.recalculateUpgradables(upgrade);
switch(upgrade)
{
case ENERGY:
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
}
}
} }

View file

@ -69,8 +69,6 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
public final double BASE_ENERGY_USAGE = usage.chemicalWasherUsage; public final double BASE_ENERGY_USAGE = usage.chemicalWasherUsage;
public double energyUsage = usage.chemicalWasherUsage;
public WasherRecipe cachedRecipe; public WasherRecipe cachedRecipe;
public TileComponentUpgrade upgradeComponent = new TileComponentUpgrade(this, 4); public TileComponentUpgrade upgradeComponent = new TileComponentUpgrade(this, 4);
@ -120,13 +118,13 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
outputTank.draw(GasTransmission.addGas(inventory[2], outputTank.getGas()), true); outputTank.draw(GasTransmission.addGas(inventory[2], outputTank.getGas()), true);
} }
if(canOperate(recipe) && getEnergy() >= energyUsage && MekanismUtils.canFunction(this)) if(canOperate(recipe) && getEnergy() >= BASE_ENERGY_USAGE && MekanismUtils.canFunction(this))
{ {
setActive(true); setActive(true);
operate(recipe); int operations = operate(recipe);
setEnergy(getEnergy() - energyUsage); setEnergy(getEnergy() - BASE_ENERGY_USAGE*operations);
} }
else { else {
if(prevEnergy >= getEnergy()) if(prevEnergy >= getEnergy())
@ -176,9 +174,13 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
return recipe != null && recipe.canOperate(inputTank, fluidTank, outputTank); return recipe != null && recipe.canOperate(inputTank, fluidTank, outputTank);
} }
public void operate(WasherRecipe recipe) public int operate(WasherRecipe recipe)
{ {
recipe.operate(inputTank, fluidTank, outputTank, getUpgradedUsage()); int operations = getUpgradedUsage();
recipe.operate(inputTank, fluidTank, outputTank, operations);
return operations;
} }
private void manageBuckets() private void manageBuckets()
@ -257,6 +259,7 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
{ {
int possibleProcess = Math.min(inputTank.getStored(), outputTank.getNeeded()); int possibleProcess = Math.min(inputTank.getStored(), outputTank.getNeeded());
possibleProcess = Math.min((int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED)), possibleProcess); possibleProcess = Math.min((int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED)), possibleProcess);
possibleProcess = Math.min((int)(getEnergy()/BASE_ENERGY_USAGE), possibleProcess);
return Math.min(fluidTank.getFluidAmount()/WATER_USAGE, possibleProcess); return Math.min(fluidTank.getFluidAmount()/WATER_USAGE, possibleProcess);
} }
@ -643,7 +646,6 @@ public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock imple
switch(upgrade) switch(upgrade)
{ {
case ENERGY: case ENERGY:
energyUsage = MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_USAGE);
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY); maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
} }
} }

View file

@ -1,5 +1,7 @@
package mekanism.common.tile; package mekanism.common.tile;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
import mekanism.api.Coord4D; import mekanism.api.Coord4D;
@ -13,7 +15,9 @@ import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem; import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection; import mekanism.api.gas.ITubeConnection;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.Upgrade;
import mekanism.common.base.ISustainedData; import mekanism.common.base.ISustainedData;
import mekanism.common.base.IUpgradeTile;
import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.network.PacketTileEntity.TileEntityMessage; import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.RecipeHandler;
@ -21,11 +25,11 @@ import mekanism.common.recipe.RecipeHandler.Recipe;
import mekanism.common.recipe.inputs.FluidInput; import mekanism.common.recipe.inputs.FluidInput;
import mekanism.common.recipe.machines.SeparatorRecipe; import mekanism.common.recipe.machines.SeparatorRecipe;
import mekanism.common.recipe.outputs.ChemicalPairOutput; import mekanism.common.recipe.outputs.ChemicalPairOutput;
import mekanism.common.tile.component.TileComponentUpgrade;
import mekanism.common.util.ChargeUtils; import mekanism.common.util.ChargeUtils;
import mekanism.common.util.FluidContainerUtils; import mekanism.common.util.FluidContainerUtils;
import mekanism.common.util.InventoryUtils; import mekanism.common.util.InventoryUtils;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -40,16 +44,13 @@ import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import cpw.mods.fml.common.Optional.Interface; import cpw.mods.fml.common.Optional.Interface;
import cpw.mods.fml.common.Optional.Method; import cpw.mods.fml.common.Optional.Method;
import io.netty.buffer.ByteBuf;
import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException; import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
@Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft") @Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft")
public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock implements IFluidHandler, IPeripheral, ITubeConnection, ISustainedData, IGasHandler public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock implements IFluidHandler, IPeripheral, ITubeConnection, ISustainedData, IGasHandler, IUpgradeTile
{ {
/** This separator's water slot. */ /** This separator's water slot. */
public FluidTank fluidTank = new FluidTank(24000); public FluidTank fluidTank = new FluidTank(24000);
@ -76,10 +77,12 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
public SeparatorRecipe cachedRecipe; public SeparatorRecipe cachedRecipe;
public TileComponentUpgrade upgradeComponent = new TileComponentUpgrade(this, 4);
public TileEntityElectrolyticSeparator() public TileEntityElectrolyticSeparator()
{ {
super("ElectrolyticSeparator", MachineType.ELECTROLYTIC_SEPARATOR.baseEnergy); super("ElectrolyticSeparator", MachineType.ELECTROLYTIC_SEPARATOR.baseEnergy);
inventory = new ItemStack[4]; inventory = new ItemStack[5];
} }
@Override @Override
@ -140,13 +143,17 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
if(canOperate(recipe) && getEnergy() >= recipe.extraEnergy) if(canOperate(recipe) && getEnergy() >= recipe.extraEnergy)
{ {
setActive(true); setActive(true);
operate(recipe);
setEnergy(getEnergy() - recipe.extraEnergy); int operations = operate(recipe);
setEnergy(getEnergy() - recipe.extraEnergy*operations);
} }
else { else {
setActive(false); setActive(false);
} }
int dumpAmount = 8*(int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED));
if(leftTank.getGas() != null) if(leftTank.getGas() != null)
{ {
if(!dumpLeft) if(!dumpLeft)
@ -164,7 +171,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
} }
} }
else { else {
leftTank.draw(8, true); leftTank.draw(dumpAmount, true);
if(worldObj.rand.nextInt(3) == 2) if(worldObj.rand.nextInt(3) == 2)
{ {
@ -190,7 +197,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
} }
} }
else { else {
rightTank.draw(8, true); rightTank.draw(dumpAmount, true);
if(worldObj.rand.nextInt(3) == 2) if(worldObj.rand.nextInt(3) == 2)
{ {
@ -202,13 +209,35 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
} }
} }
public int getUpgradedUsage(SeparatorRecipe recipe)
{
int possibleProcess = 0;
if(leftTank.getGasType() == recipe.recipeOutput.leftGas.getGas())
{
possibleProcess = leftTank.getNeeded()/recipe.recipeOutput.leftGas.amount;
possibleProcess = Math.min(rightTank.getNeeded()/recipe.recipeOutput.rightGas.amount, possibleProcess);
}
else {
possibleProcess = leftTank.getNeeded()/recipe.recipeOutput.rightGas.amount;
possibleProcess = Math.min(rightTank.getNeeded()/recipe.recipeOutput.leftGas.amount, possibleProcess);
}
possibleProcess = Math.min((int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED)), possibleProcess);
possibleProcess = Math.min((int)(getEnergy()/recipe.extraEnergy), possibleProcess);
return Math.min(fluidTank.getFluidAmount()/recipe.recipeInput.ingredient.amount, possibleProcess);
}
public SeparatorRecipe getRecipe() public SeparatorRecipe getRecipe()
{ {
FluidInput input = getInput(); FluidInput input = getInput();
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput())) if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
{ {
cachedRecipe = RecipeHandler.getElectrolyticSeparatorRecipe(getInput()); cachedRecipe = RecipeHandler.getElectrolyticSeparatorRecipe(getInput());
} }
return cachedRecipe; return cachedRecipe;
} }
@ -222,9 +251,13 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
return recipe != null && recipe.canOperate(fluidTank, leftTank, rightTank); return recipe != null && recipe.canOperate(fluidTank, leftTank, rightTank);
} }
public void operate(SeparatorRecipe recipe) public int operate(SeparatorRecipe recipe)
{ {
recipe.operate(fluidTank, leftTank, rightTank); int operations = getUpgradedUsage(recipe);
recipe.operate(fluidTank, leftTank, rightTank, operations);
return operations;
} }
public boolean canFill(ChemicalPairOutput gases) public boolean canFill(ChemicalPairOutput gases)
@ -581,7 +614,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
@Override @Override
public boolean canFill(ForgeDirection from, Fluid fluid) public boolean canFill(ForgeDirection from, Fluid fluid)
{ {
return RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.containsRecipe(fluid); return Recipe.ELECTROLYTIC_SEPARATOR.containsRecipe(fluid);
} }
@Override @Override
@ -593,7 +626,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
@Override @Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{ {
if(RecipeHandler.Recipe.ELECTROLYTIC_SEPARATOR.containsRecipe(resource.getFluid())) if(Recipe.ELECTROLYTIC_SEPARATOR.containsRecipe(resource.getFluid()))
{ {
return fluidTank.fill(resource, doFill); return fluidTank.fill(resource, doFill);
} }
@ -659,4 +692,22 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{ {
isActive = active; isActive = active;
} }
@Override
public TileComponentUpgrade getComponent()
{
return upgradeComponent;
}
@Override
public void recalculateUpgradables(Upgrade upgrade)
{
super.recalculateUpgradables(upgrade);
switch(upgrade)
{
case ENERGY:
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
}
}
} }