Finish base code for gas-based advanced machinery

This commit is contained in:
Aidan Brady 2014-01-16 20:35:05 -05:00
parent 4fb335b7d3
commit da6c0a2c90
11 changed files with 120 additions and 152 deletions

View file

@ -64,7 +64,7 @@ public class GuiAdvancedElectricMachine extends GuiMekanism
int displayInt; int displayInt;
displayInt = tileEntity.getScaledSecondaryEnergyLevel(12); displayInt = tileEntity.getScaledGasLevel(12);
drawTexturedModalRect(guiWidth + 61, guiHeight + 37 + 12 - displayInt, 176, 7 + 12 - displayInt, 5, displayInt); drawTexturedModalRect(guiWidth + 61, guiHeight + 37 + 12 - displayInt, 176, 7 + 12 - displayInt, 5, displayInt);
displayInt = tileEntity.getScaledProgress(24); displayInt = tileEntity.getScaledProgress(24);

View file

@ -60,7 +60,7 @@ public class GuiFactory extends GuiMekanism
if(xAxis >= 8 && xAxis <= 168 && yAxis >= 78 && yAxis <= 83) if(xAxis >= 8 && xAxis <= 168 && yAxis >= 78 && yAxis <= 83)
{ {
drawCreativeTabHoveringText(MekanismUtils.localize("gui.factory.secondaryEnergy") + ": " + tileEntity.secondaryEnergyStored, xAxis, yAxis); drawCreativeTabHoveringText(MekanismUtils.localize("gui.factory.secondaryEnergy") + ": " + tileEntity.gasTank.getStored(), xAxis, yAxis);
} }
super.drawGuiContainerForegroundLayer(mouseX, mouseY); super.drawGuiContainerForegroundLayer(mouseX, mouseY);
@ -131,7 +131,7 @@ public class GuiFactory extends GuiMekanism
recipeFuelY += 15; recipeFuelY += 15;
} }
displayInt = tileEntity.getScaledSecondaryEnergy(160); displayInt = tileEntity.getScaledGasLevel(160);
drawTexturedModalRect(guiWidth + 8, guiHeight + 78, 0, recipeFuelY, displayInt, 5); drawTexturedModalRect(guiWidth + 8, guiHeight + 78, 0, recipeFuelY, displayInt, 5);
} }
} }

View file

@ -1,5 +1,6 @@
package mekanism.common; package mekanism.common;
import mekanism.api.gas.GasStack;
import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.RecipeHandler;
import mekanism.common.recipe.RecipeHandler.Recipe; import mekanism.common.recipe.RecipeHandler.Recipe;
@ -43,6 +44,7 @@ public interface IFactory
private String sound; private String sound;
private ItemStack stack; private ItemStack stack;
private boolean usesFuel; private boolean usesFuel;
private TileEntityAdvancedElectricMachine cacheTile;
public ItemStack getCopiedOutput(ItemStack input, boolean stackDecrease) public ItemStack getCopiedOutput(ItemStack input, boolean stackDecrease)
{ {
@ -93,32 +95,37 @@ public interface IFactory
return null; return null;
} }
public int getFuelTicks(ItemStack itemstack) public GasStack getItemGas(ItemStack itemstack)
{ {
if(usesFuel) if(usesFuel)
{ {
MachineType type = MachineType.get(getStack().itemID, getStack().getItemDamage()); return getTile().getItemGas(itemstack);
TileEntityAdvancedElectricMachine machine = (TileEntityAdvancedElectricMachine)type.create();
return machine.getFuelTicks(itemstack);
} }
return 0; return null;
} }
public int getSecondaryEnergyPerTick() public int getSecondaryEnergyPerTick()
{ {
if(usesFuel) if(usesFuel)
{ {
MachineType type = MachineType.get(getStack().itemID, getStack().getItemDamage()); return getTile().SECONDARY_ENERGY_PER_TICK;
TileEntityAdvancedElectricMachine machine = (TileEntityAdvancedElectricMachine)type.create();
return machine.SECONDARY_ENERGY_PER_TICK;
} }
return 0; return 0;
} }
public TileEntityAdvancedElectricMachine getTile()
{
if(cacheTile == null)
{
MachineType type = MachineType.get(getStack().itemID, getStack().getItemDamage());
cacheTile = (TileEntityAdvancedElectricMachine)type.create();
}
return cacheTile;
}
public int getMaxSecondaryEnergy() public int getMaxSecondaryEnergy()
{ {
return 200; return 200;

View file

@ -97,7 +97,7 @@ public class ContainerAdvancedElectricMachine extends Container
} }
} }
} }
else if(tileEntity.getFuelTicks(slotStack) > 0) else if(tileEntity.getItemGas(slotStack) != null)
{ {
if(slotID != 1) if(slotID != 1)
{ {

View file

@ -163,7 +163,7 @@ public class ContainerFactory extends Container
} }
} }
} }
else if(RecipeType.values()[tileEntity.recipeType].getFuelTicks(slotStack) > 0) else if(RecipeType.values()[tileEntity.recipeType].getItemGas(slotStack) != null)
{ {
if(slotID > tileEntity.inventory.length-1) if(slotID > tileEntity.inventory.length-1)
{ {

View file

@ -3,8 +3,11 @@ package mekanism.common.tile;
import java.util.ArrayList; import java.util.ArrayList;
import mekanism.api.EnumColor; import mekanism.api.EnumColor;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack; import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank; import mekanism.api.gas.GasTank;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.SideData; import mekanism.common.SideData;
import mekanism.common.recipe.RecipeHandler; import mekanism.common.recipe.RecipeHandler;
@ -16,22 +19,19 @@ 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.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess; import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext; import dan200.computer.api.ILuaContext;
public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicMachine public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicMachine implements IGasHandler, ITubeConnection
{ {
/** How much secondary energy (fuel) this machine uses per tick. */ /** How much secondary energy (fuel) this machine uses per tick. */
public int SECONDARY_ENERGY_PER_TICK; public int SECONDARY_ENERGY_PER_TICK;
/** Maximum amount of secondary energy (fuel) this machine can hold. */ public int MAX_SECONDARY_ENERGY = 200;
public int MAX_SECONDARY_ENERGY;
/** How much secondary energy (fuel) is stored in this machine. */
public int secondaryEnergyStored = 0;
public GasTank gasTank; public GasTank gasTank;
@ -49,7 +49,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
* @param maxEnergy - maximum amount of energy this machine can hold. * @param maxEnergy - maximum amount of energy this machine can hold.
* @param maxSecondaryEnergy - maximum amount of secondary energy (fuel) this machine can hold. * @param maxSecondaryEnergy - maximum amount of secondary energy (fuel) this machine can hold.
*/ */
public TileEntityAdvancedElectricMachine(String soundPath, String name, ResourceLocation location, double perTick, int secondaryPerTick, int ticksRequired, double maxEnergy, int maxSecondaryEnergy) public TileEntityAdvancedElectricMachine(String soundPath, String name, ResourceLocation location, double perTick, int secondaryPerTick, int ticksRequired, double maxEnergy)
{ {
super(soundPath, name, location, perTick, ticksRequired, maxEnergy); super(soundPath, name, location, perTick, ticksRequired, maxEnergy);
@ -62,12 +62,11 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
sideConfig = new byte[] {2, 1, 0, 4, 5, 3}; sideConfig = new byte[] {2, 1, 0, 4, 5, 3};
gasTank = new GasTank(maxSecondaryEnergy); gasTank = new GasTank(MAX_SECONDARY_ENERGY);
inventory = new ItemStack[5]; inventory = new ItemStack[5];
SECONDARY_ENERGY_PER_TICK = secondaryPerTick; SECONDARY_ENERGY_PER_TICK = secondaryPerTick;
MAX_SECONDARY_ENERGY = maxSecondaryEnergy;
upgradeComponent = new TileComponentUpgrade(this, 4); upgradeComponent = new TileComponentUpgrade(this, 4);
ejectorComponent = new TileComponentEjector(this, sideOutputs.get(3)); ejectorComponent = new TileComponentEjector(this, sideOutputs.get(3));
@ -78,7 +77,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
* @param itemstack - itemstack to check with * @param itemstack - itemstack to check with
* @return fuel ticks * @return fuel ticks
*/ */
public abstract int getFuelTicks(ItemStack itemstack); public abstract GasStack getItemGas(ItemStack itemstack);
@Override @Override
public void onUpdate() public void onUpdate()
@ -91,13 +90,13 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
handleSecondaryFuel(); handleSecondaryFuel();
if(canOperate() && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK) && secondaryEnergyStored >= SECONDARY_ENERGY_PER_TICK) if(canOperate() && MekanismUtils.canFunction(this) && getEnergy() >= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK) && gasTank.getStored() >= SECONDARY_ENERGY_PER_TICK)
{ {
setActive(true); setActive(true);
operatingTicks++; operatingTicks++;
secondaryEnergyStored -= SECONDARY_ENERGY_PER_TICK; gasTank.draw(SECONDARY_ENERGY_PER_TICK, true);
electricityStored -= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK); electricityStored -= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK);
if(operatingTicks >= MekanismUtils.getTicks(getSpeedMultiplier(), TICKS_REQUIRED)) if(operatingTicks >= MekanismUtils.getTicks(getSpeedMultiplier(), TICKS_REQUIRED))
@ -127,19 +126,12 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
{ {
if(inventory[1] != null) if(inventory[1] != null)
{ {
int fuelTicks = getFuelTicks(inventory[1]); GasStack stack = getItemGas(inventory[1]);
int energyNeeded = MAX_SECONDARY_ENERGY - secondaryEnergyStored; int gasNeeded = gasTank.getNeeded();
if(fuelTicks > 0 && fuelTicks <= energyNeeded) if(stack != null && stack.amount <= gasNeeded)
{ {
if(fuelTicks <= energyNeeded) gasTank.receive(stack, true);
{
setSecondaryEnergy(secondaryEnergyStored + fuelTicks);
}
else if(fuelTicks > energyNeeded)
{
setSecondaryEnergy(secondaryEnergyStored + energyNeeded);
}
inventory[1].stackSize--; inventory[1].stackSize--;
@ -172,7 +164,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
} }
else if(slotID == 1) else if(slotID == 1)
{ {
return getFuelTicks(itemstack) > 0; return getItemGas(itemstack) != null;
} }
return false; return false;
@ -233,7 +225,6 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
public void handlePacketData(ByteArrayDataInput dataStream) public void handlePacketData(ByteArrayDataInput dataStream)
{ {
super.handlePacketData(dataStream); super.handlePacketData(dataStream);
secondaryEnergyStored = dataStream.readInt();
if(dataStream.readBoolean()) if(dataStream.readBoolean())
{ {
@ -249,8 +240,6 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
{ {
super.getNetworkedData(data); super.getNetworkedData(data);
data.add(secondaryEnergyStored);
if(gasTank.getGas() != null) if(gasTank.getGas() != null)
{ {
data.add(true); data.add(true);
@ -269,7 +258,6 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
{ {
super.readFromNBT(nbtTags); super.readFromNBT(nbtTags);
secondaryEnergyStored = nbtTags.getInteger("secondaryEnergyStored");
gasTank.read(nbtTags.getCompoundTag("gasTank")); gasTank.read(nbtTags.getCompoundTag("gasTank"));
} }
@ -278,27 +266,17 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
{ {
super.writeToNBT(nbtTags); super.writeToNBT(nbtTags);
nbtTags.setInteger("secondaryEnergyStored", secondaryEnergyStored);
nbtTags.setCompoundTag("gasTank", gasTank.write(new NBTTagCompound())); nbtTags.setCompoundTag("gasTank", gasTank.write(new NBTTagCompound()));
} }
/**
* Sets the secondary energy to a new amount
* @param energy - amount to store
*/
public void setSecondaryEnergy(int energy)
{
secondaryEnergyStored = Math.max(Math.min(energy, MAX_SECONDARY_ENERGY), 0);
}
/** /**
* Gets the scaled secondary energy level for the GUI. * Gets the scaled secondary energy level for the GUI.
* @param i - multiplier * @param i - multiplier
* @return scaled secondary energy * @return scaled secondary energy
*/ */
public int getScaledSecondaryEnergyLevel(int i) public int getScaledGasLevel(int i)
{ {
return secondaryEnergyStored*i / MAX_SECONDARY_ENERGY; return gasTank.getStored()*i / gasTank.getMaxGas();
} }
@Override @Override
@ -315,6 +293,36 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
return false; return false;
} }
@Override
public boolean canTubeConnect(ForgeDirection side)
{
return false;
}
@Override
public int receiveGas(ForgeDirection side, GasStack stack)
{
return 0;
}
@Override
public GasStack drawGas(ForgeDirection side, int amount)
{
return null;
}
@Override
public boolean canReceiveGas(ForgeDirection side, Gas type)
{
return false;
}
@Override
public boolean canDrawGas(ForgeDirection side, Gas type)
{
return false;
}
@Override @Override
public String[] getMethodNames() public String[] getMethodNames()
@ -330,7 +338,7 @@ public abstract class TileEntityAdvancedElectricMachine extends TileEntityBasicM
case 0: case 0:
return new Object[] {getEnergy()}; return new Object[] {getEnergy()};
case 1: case 1:
return new Object[] {secondaryEnergyStored}; return new Object[] {gasTank.getStored()};
case 2: case 2:
return new Object[] {operatingTicks}; return new Object[] {operatingTicks};
case 3: case 3:

View file

@ -21,7 +21,7 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr
{ {
public TileEntityChemicalInjectionChamber() public TileEntityChemicalInjectionChamber()
{ {
super("ChemicalInjectionChamber.ogg", "ChemicalInjectionChamber", new ResourceLocation("mekanism", "gui/GuiChemicalInjectionChamber.png"), Mekanism.chemicalInjectionChamberUsage, 1, 200, MachineType.CHEMICAL_INJECTION_CHAMBER.baseEnergy, 1200); super("ChemicalInjectionChamber.ogg", "ChemicalInjectionChamber", new ResourceLocation("mekanism", "gui/GuiChemicalInjectionChamber.png"), Mekanism.chemicalInjectionChamberUsage, 1, 200, MachineType.CHEMICAL_INJECTION_CHAMBER.baseEnergy);
} }
@Override @Override
@ -31,13 +31,13 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr
} }
@Override @Override
public int getFuelTicks(ItemStack itemstack) public GasStack getItemGas(ItemStack itemstack)
{ {
if(MekanismUtils.getOreDictName(itemstack).contains("dustSulfur")) return 5; if(MekanismUtils.getOreDictName(itemstack).contains("dustSulfur")) return new GasStack(GasRegistry.getGas("sulfuricAcid"), 2);
if(itemstack.itemID == Mekanism.GasTank.blockID && ((IGasItem)itemstack.getItem()).getGas(itemstack) != null && if(itemstack.itemID == Mekanism.GasTank.blockID && ((IGasItem)itemstack.getItem()).getGas(itemstack) != null &&
((IGasItem)itemstack.getItem()).getGas(itemstack).getGas() == GasRegistry.getGas("sulfuricAcid")) return 1; ((IGasItem)itemstack.getItem()).getGas(itemstack).getGas() == GasRegistry.getGas("sulfuricAcid")) return new GasStack(GasRegistry.getGas("sulfuricAcid"), 1);
return 0; return null;
} }
@Override @Override
@ -45,9 +45,7 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr
{ {
if(stack.getGas() == GasRegistry.getGas("sulfuricAcid")) if(stack.getGas() == GasRegistry.getGas("sulfuricAcid"))
{ {
int toUse = Math.min(MAX_SECONDARY_ENERGY-secondaryEnergyStored, stack.amount); return gasTank.receive(stack, true);
secondaryEnergyStored += toUse;
return toUse;
} }
return 0; return 0;
@ -62,10 +60,10 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr
@Override @Override
public void handleSecondaryFuel() public void handleSecondaryFuel()
{ {
if(inventory[1] != null && secondaryEnergyStored < MAX_SECONDARY_ENERGY && inventory[1].getItem() instanceof IGasItem) if(inventory[1] != null && gasTank.getNeeded() > 0 && inventory[1].getItem() instanceof IGasItem)
{ {
GasStack removed = GasTransmission.removeGas(inventory[1], GasRegistry.getGas("sulfuricAcid"), MAX_SECONDARY_ENERGY-secondaryEnergyStored); GasStack removed = GasTransmission.removeGas(inventory[1], GasRegistry.getGas("sulfuricAcid"), gasTank.getNeeded());
setSecondaryEnergy(secondaryEnergyStored + (removed != null ? removed.amount : 0)); gasTank.receive(removed, true);
return; return;
} }
@ -77,16 +75,4 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr
{ {
return true; return true;
} }
@Override
public GasStack drawGas(ForgeDirection side, int amount)
{
return null;
}
@Override
public boolean canDrawGas(ForgeDirection side, Gas type)
{
return false;
}
} }

View file

@ -2,6 +2,8 @@ package mekanism.common.tile;
import java.util.Map; import java.util.Map;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler.Recipe; import mekanism.common.recipe.RecipeHandler.Recipe;
@ -14,7 +16,7 @@ public class TileEntityCombiner extends TileEntityAdvancedElectricMachine
{ {
public TileEntityCombiner() public TileEntityCombiner()
{ {
super("Combiner.ogg", "Combiner", new ResourceLocation("mekanism", "gui/GuiCombiner.png"), Mekanism.combinerUsage, 1, 200, MachineType.COMBINER.baseEnergy, 200); super("Combiner.ogg", "Combiner", new ResourceLocation("mekanism", "gui/GuiCombiner.png"), Mekanism.combinerUsage, 1, 200, MachineType.COMBINER.baseEnergy);
} }
@Override @Override
@ -24,13 +26,13 @@ public class TileEntityCombiner extends TileEntityAdvancedElectricMachine
} }
@Override @Override
public int getFuelTicks(ItemStack itemstack) public GasStack getItemGas(ItemStack itemstack)
{ {
if(itemstack.getItem() instanceof ItemBlock && itemstack.itemID == Block.cobblestone.blockID) if(itemstack.getItem() instanceof ItemBlock && itemstack.itemID == Block.cobblestone.blockID)
{ {
return 200; return new GasStack(GasRegistry.getGas("liquidStone"), 200);
} }
return 0; return null;
} }
} }

View file

@ -88,8 +88,6 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
public boolean sorting; public boolean sorting;
public int secondaryEnergyStored;
/** This machine's current RedstoneControl type. */ /** This machine's current RedstoneControl type. */
public RedstoneControl controlType = RedstoneControl.DISABLED; public RedstoneControl controlType = RedstoneControl.DISABLED;
@ -191,8 +189,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
inventory[2] = null; inventory[2] = null;
inventory[3] = getMachineStack(); inventory[3] = getMachineStack();
recipeType = toSet.ordinal(); gasTank.setGas(null);
setSecondaryEnergy(0);
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType().blockID); worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType().blockID);
@ -209,12 +206,12 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
for(int process = 0; process < tier.processes; process++) for(int process = 0; process < tier.processes; process++)
{ {
if(MekanismUtils.canFunction(this) && canOperate(getInputSlot(process), getOutputSlot(process)) && getEnergy() >= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK) && secondaryEnergyStored >= getSecondaryEnergyPerTick()) if(MekanismUtils.canFunction(this) && canOperate(getInputSlot(process), getOutputSlot(process)) && getEnergy() >= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK) && gasTank.getStored() >= getSecondaryEnergyPerTick())
{ {
if((progress[process]+1) < MekanismUtils.getTicks(getSpeedMultiplier(), TICKS_REQUIRED)) if((progress[process]+1) < MekanismUtils.getTicks(getSpeedMultiplier(), TICKS_REQUIRED))
{ {
progress[process]++; progress[process]++;
secondaryEnergyStored -= getSecondaryEnergyPerTick(); gasTank.draw(getSecondaryEnergyPerTick(), true);
electricityStored -= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK); electricityStored -= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK);
} }
else if((progress[process]+1) >= MekanismUtils.getTicks(getSpeedMultiplier(), TICKS_REQUIRED)) else if((progress[process]+1) >= MekanismUtils.getTicks(getSpeedMultiplier(), TICKS_REQUIRED))
@ -222,7 +219,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
operate(getInputSlot(process), getOutputSlot(process)); operate(getInputSlot(process), getOutputSlot(process));
progress[process] = 0; progress[process] = 0;
secondaryEnergyStored -= getSecondaryEnergyPerTick(); gasTank.draw(getSecondaryEnergyPerTick(), true);
electricityStored -= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK); electricityStored -= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK);
} }
} }
@ -244,7 +241,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
} }
} }
if(MekanismUtils.canFunction(this) && hasOperation && getEnergy() >= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK) && secondaryEnergyStored >= getSecondaryEnergyPerTick()) if(MekanismUtils.canFunction(this) && hasOperation && getEnergy() >= MekanismUtils.getEnergyPerTick(getSpeedMultiplier(), getEnergyMultiplier(), ENERGY_PER_TICK) && gasTank.getStored() >= getSecondaryEnergyPerTick())
{ {
setActive(true); setActive(true);
} }
@ -349,14 +346,14 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
public void handleSecondaryFuel() public void handleSecondaryFuel()
{ {
if(inventory[4] != null && RecipeType.values()[recipeType].usesFuel() && secondaryEnergyStored < getMaxSecondaryEnergy()) if(inventory[4] != null && RecipeType.values()[recipeType].usesFuel() && gasTank.getStored() < getMaxSecondaryEnergy())
{ {
if(recipeType == RecipeType.PURIFYING.ordinal()) if(recipeType == RecipeType.PURIFYING.ordinal())
{ {
if(inventory[4].getItem() instanceof IGasItem) if(inventory[4].getItem() instanceof IGasItem)
{ {
GasStack removed = GasTransmission.removeGas(inventory[4], GasRegistry.getGas("oxygen"), getMaxSecondaryEnergy()-secondaryEnergyStored); GasStack removed = GasTransmission.removeGas(inventory[4], GasRegistry.getGas("oxygen"), gasTank.getNeeded());
setSecondaryEnergy(secondaryEnergyStored + (removed != null ? removed.amount : 0)); gasTank.receive(removed, true);
return; return;
} }
@ -365,26 +362,19 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
{ {
if(inventory[4].getItem() instanceof IGasItem) if(inventory[4].getItem() instanceof IGasItem)
{ {
GasStack removed = GasTransmission.removeGas(inventory[4], GasRegistry.getGas("sulfuricAcid"), getMaxSecondaryEnergy()-secondaryEnergyStored); GasStack removed = GasTransmission.removeGas(inventory[4], GasRegistry.getGas("sulfuricAcid"), gasTank.getNeeded());
setSecondaryEnergy(secondaryEnergyStored + (removed != null ? removed.amount : 0)); gasTank.receive(removed, true);
return; return;
} }
} }
int fuelTicks = RecipeType.values()[recipeType].getFuelTicks(inventory[4]); GasStack stack = RecipeType.values()[recipeType].getItemGas(inventory[4]);
int energyNeeded = getMaxSecondaryEnergy() - secondaryEnergyStored; int gasNeeded = gasTank.getNeeded();
if(fuelTicks > 0 && fuelTicks <= energyNeeded) if(stack != null && stack.amount <= gasNeeded)
{ {
if(fuelTicks <= energyNeeded) gasTank.receive(stack, true);
{
setSecondaryEnergy(secondaryEnergyStored + fuelTicks);
}
else if(fuelTicks > energyNeeded)
{
setSecondaryEnergy(secondaryEnergyStored + energyNeeded);
}
inventory[4].stackSize--; inventory[4].stackSize--;
@ -471,7 +461,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
} }
else if(slotID == 4) else if(slotID == 4)
{ {
return RecipeType.values()[recipeType].getFuelTicks(itemstack) > 0; return RecipeType.values()[recipeType].getItemGas(itemstack) != null;
} }
return false; return false;
@ -493,9 +483,9 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
return progress[process]*i / MekanismUtils.getTicks(getSpeedMultiplier(), TICKS_REQUIRED); return progress[process]*i / MekanismUtils.getTicks(getSpeedMultiplier(), TICKS_REQUIRED);
} }
public int getScaledSecondaryEnergy(int i) public int getScaledGasLevel(int i)
{ {
return secondaryEnergyStored*i / getMaxSecondaryEnergy(); return gasTank.getStored()*i / gasTank.getMaxGas();
} }
public int getScaledRecipeProgress(int i) public int getScaledRecipeProgress(int i)
@ -557,11 +547,6 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
ejectorComponent.onOutput(); ejectorComponent.onOutput();
} }
public void setSecondaryEnergy(int energy)
{
secondaryEnergyStored = Math.max(Math.min(energy, getMaxSecondaryEnergy()), 0);
}
@Override @Override
public void handlePacketData(ByteArrayDataInput dataStream) public void handlePacketData(ByteArrayDataInput dataStream)
{ {
@ -583,7 +568,6 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
recipeType = dataStream.readInt(); recipeType = dataStream.readInt();
recipeTicks = dataStream.readInt(); recipeTicks = dataStream.readInt();
controlType = RedstoneControl.values()[dataStream.readInt()]; controlType = RedstoneControl.values()[dataStream.readInt()];
secondaryEnergyStored = dataStream.readInt();
sorting = dataStream.readBoolean(); sorting = dataStream.readBoolean();
for(int i = 0; i < tier.processes; i++) for(int i = 0; i < tier.processes; i++)
@ -621,7 +605,6 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
recipeType = nbtTags.getInteger("recipeType"); recipeType = nbtTags.getInteger("recipeType");
recipeTicks = nbtTags.getInteger("recipeTicks"); recipeTicks = nbtTags.getInteger("recipeTicks");
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")]; controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
secondaryEnergyStored = nbtTags.getInteger("secondaryEnergyStored");
sorting = nbtTags.getBoolean("sorting"); sorting = nbtTags.getBoolean("sorting");
for(int i = 0; i < tier.processes; i++) for(int i = 0; i < tier.processes; i++)
@ -649,7 +632,6 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
nbtTags.setInteger("recipeType", recipeType); nbtTags.setInteger("recipeType", recipeType);
nbtTags.setInteger("recipeTicks", recipeTicks); nbtTags.setInteger("recipeTicks", recipeTicks);
nbtTags.setInteger("controlType", controlType.ordinal()); nbtTags.setInteger("controlType", controlType.ordinal());
nbtTags.setInteger("secondaryEnergyStored", secondaryEnergyStored);
nbtTags.setBoolean("sorting", sorting); nbtTags.setBoolean("sorting", sorting);
for(int i = 0; i < tier.processes; i++) for(int i = 0; i < tier.processes; i++)
@ -676,7 +658,6 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
data.add(recipeType); data.add(recipeType);
data.add(recipeTicks); data.add(recipeTicks);
data.add(controlType.ordinal()); data.add(controlType.ordinal());
data.add(secondaryEnergyStored);
data.add(sorting); data.add(sorting);
data.add(progress); data.add(progress);
data.add(sideConfig); data.add(sideConfig);
@ -924,9 +905,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
if(recipeType == RecipeType.PURIFYING.ordinal() && stack.getGas() == GasRegistry.getGas("oxygen") || if(recipeType == RecipeType.PURIFYING.ordinal() && stack.getGas() == GasRegistry.getGas("oxygen") ||
recipeType == RecipeType.INJECTING.ordinal() && stack.getGas() == GasRegistry.getGas("sulfuricAcid")) recipeType == RecipeType.INJECTING.ordinal() && stack.getGas() == GasRegistry.getGas("sulfuricAcid"))
{ {
int toUse = Math.min(getMaxSecondaryEnergy()-secondaryEnergyStored, stack.amount); return gasTank.receive(stack, true);
secondaryEnergyStored += toUse;
return toUse;
} }
return 0; return 0;

View file

@ -2,6 +2,8 @@ package mekanism.common.tile;
import java.util.Map; import java.util.Map;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.block.BlockMachine.MachineType; import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.recipe.RecipeHandler.Recipe; import mekanism.common.recipe.RecipeHandler.Recipe;
@ -13,7 +15,7 @@ public class TileEntityOsmiumCompressor extends TileEntityAdvancedElectricMachin
{ {
public TileEntityOsmiumCompressor() public TileEntityOsmiumCompressor()
{ {
super("Compressor.ogg", "OsmiumCompressor", new ResourceLocation("mekanism", "gui/GuiCompressor.png"), Mekanism.osmiumCompressorUsage, 1, 200, MachineType.OSMIUM_COMPRESSOR.baseEnergy, 200); super("Compressor.ogg", "OsmiumCompressor", new ResourceLocation("mekanism", "gui/GuiCompressor.png"), Mekanism.osmiumCompressorUsage, 1, 200, MachineType.OSMIUM_COMPRESSOR.baseEnergy);
} }
@Override @Override
@ -23,7 +25,7 @@ public class TileEntityOsmiumCompressor extends TileEntityAdvancedElectricMachin
} }
@Override @Override
public int getFuelTicks(ItemStack itemstack) public GasStack getItemGas(ItemStack itemstack)
{ {
int amount = 0; int amount = 0;
@ -31,8 +33,7 @@ public class TileEntityOsmiumCompressor extends TileEntityAdvancedElectricMachin
{ {
if(ore.isItemEqual(itemstack)) if(ore.isItemEqual(itemstack))
{ {
amount = 200; return new GasStack(GasRegistry.getGas("liquidOsmium"), 200);
break;
} }
} }
@ -40,11 +41,10 @@ public class TileEntityOsmiumCompressor extends TileEntityAdvancedElectricMachin
{ {
if(ore.isItemEqual(itemstack)) if(ore.isItemEqual(itemstack))
{ {
amount = 1800; return new GasStack(GasRegistry.getGas("liquidOsmium"), 1800);
break;
} }
} }
return amount; return null;
} }
} }

View file

@ -21,7 +21,7 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
{ {
public TileEntityPurificationChamber() public TileEntityPurificationChamber()
{ {
super("PurificationChamber.ogg", "PurificationChamber", new ResourceLocation("mekanism", "gui/GuiPurificationChamber.png"), Mekanism.purificationChamberUsage, 1, 200, MachineType.PURIFICATION_CHAMBER.baseEnergy, 1200); super("PurificationChamber.ogg", "PurificationChamber", new ResourceLocation("mekanism", "gui/GuiPurificationChamber.png"), Mekanism.purificationChamberUsage, 1, 200, MachineType.PURIFICATION_CHAMBER.baseEnergy);
} }
@Override @Override
@ -31,13 +31,13 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
} }
@Override @Override
public int getFuelTicks(ItemStack itemstack) public GasStack getItemGas(ItemStack itemstack)
{ {
if(itemstack.isItemEqual(new ItemStack(Item.flint))) return 300; if(itemstack.isItemEqual(new ItemStack(Item.flint))) return new GasStack(GasRegistry.getGas("oxygen"), 10);
if(itemstack.itemID == Mekanism.GasTank.blockID && ((IGasItem)itemstack.getItem()).getGas(itemstack) != null && if(itemstack.itemID == Mekanism.GasTank.blockID && ((IGasItem)itemstack.getItem()).getGas(itemstack) != null &&
((IGasItem)itemstack.getItem()).getGas(itemstack).getGas() == GasRegistry.getGas("oxygen")) return 1; ((IGasItem)itemstack.getItem()).getGas(itemstack).getGas() == GasRegistry.getGas("oxygen")) return new GasStack(GasRegistry.getGas("oxygen"), 1);
return 0; return null;
} }
@Override @Override
@ -45,9 +45,7 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
{ {
if(stack.getGas() == GasRegistry.getGas("oxygen")) if(stack.getGas() == GasRegistry.getGas("oxygen"))
{ {
int toUse = Math.min(MAX_SECONDARY_ENERGY-secondaryEnergyStored, stack.amount); return gasTank.receive(stack, true);
secondaryEnergyStored += toUse;
return toUse;
} }
return 0; return 0;
@ -62,10 +60,10 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
@Override @Override
public void handleSecondaryFuel() public void handleSecondaryFuel()
{ {
if(inventory[1] != null && secondaryEnergyStored < MAX_SECONDARY_ENERGY && inventory[1].getItem() instanceof IGasItem) if(inventory[1] != null && gasTank.getNeeded() > 0 && inventory[1].getItem() instanceof IGasItem)
{ {
GasStack removed = GasTransmission.removeGas(inventory[1], GasRegistry.getGas("oxygen"), MAX_SECONDARY_ENERGY-secondaryEnergyStored); GasStack removed = GasTransmission.removeGas(inventory[1], GasRegistry.getGas("oxygen"), gasTank.getNeeded());
setSecondaryEnergy(secondaryEnergyStored + (removed != null ? removed.amount : 0)); gasTank.receive(removed, true);
return; return;
} }
@ -77,16 +75,4 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
{ {
return true; return true;
} }
@Override
public GasStack drawGas(ForgeDirection side, int amount)
{
return null;
}
@Override
public boolean canDrawGas(ForgeDirection side, Gas type)
{
return false;
}
} }