Start work on updating the electrolytic separator. It can output both gases now! Should support recipes as well.

This commit is contained in:
Ben Spiers 2014-01-02 04:02:00 +00:00
parent c8d765bde0
commit ea96a7d747
6 changed files with 268 additions and 151 deletions

View file

@ -50,7 +50,7 @@ public class ChemicalInput
* Swaps the right gas and left gas of this input. * Swaps the right gas and left gas of this input.
* @return a swapped ChemicalInput * @return a swapped ChemicalInput
*/ */
private ChemicalInput swap() public ChemicalInput swap()
{ {
return new ChemicalInput(rightGas, leftGas); return new ChemicalInput(rightGas, leftGas);
} }
@ -93,4 +93,9 @@ public class ChemicalInput
return input.leftGas.amount >= leftGas.amount && input.rightGas.amount >= rightGas.amount; return input.leftGas.amount >= leftGas.amount && input.rightGas.amount >= rightGas.amount;
} }
public ChemicalInput copy()
{
return new ChemicalInput(leftGas.copy(), rightGas.copy());
}
} }

View file

@ -111,6 +111,8 @@ import net.minecraftforge.common.Configuration;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.ChunkEvent;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapelessOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe;
import rebelkeithy.mods.metallurgy.api.IOreInfo; import rebelkeithy.mods.metallurgy.api.IOreInfo;
@ -633,6 +635,9 @@ public class Mekanism
RecipeHandler.addChemicalInfuserRecipe(new ChemicalInput(new GasStack(GasRegistry.getGas("oxygen"), 1), new GasStack(GasRegistry.getGas("sulfurDioxideGas"), 2)), new GasStack(GasRegistry.getGas("sulfurTrioxideGas"), 2)); RecipeHandler.addChemicalInfuserRecipe(new ChemicalInput(new GasStack(GasRegistry.getGas("oxygen"), 1), new GasStack(GasRegistry.getGas("sulfurDioxideGas"), 2)), new GasStack(GasRegistry.getGas("sulfurTrioxideGas"), 2));
RecipeHandler.addChemicalInfuserRecipe(new ChemicalInput(new GasStack(GasRegistry.getGas("sulfurTrioxideGas"), 1), new GasStack(GasRegistry.getGas("water"), 1)), new GasStack(GasRegistry.getGas("sulfuricAcid"), 1)); RecipeHandler.addChemicalInfuserRecipe(new ChemicalInput(new GasStack(GasRegistry.getGas("sulfurTrioxideGas"), 1), new GasStack(GasRegistry.getGas("water"), 1)), new GasStack(GasRegistry.getGas("sulfuricAcid"), 1));
//Electrolytic Separator Recipes
RecipeHandler.addElectrolyticSeparatorRecipe(FluidRegistry.getFluidStack("water", 2), new ChemicalInput(new GasStack(GasRegistry.getGas("hydrogen"), 2), new GasStack(GasRegistry.getGas("oxygen"), 1)));
//Infuse objects //Infuse objects
InfuseRegistry.registerInfuseObject(new ItemStack(Item.coal, 1, 0), new InfuseObject(InfuseRegistry.get("CARBON"), 10)); InfuseRegistry.registerInfuseObject(new ItemStack(Item.coal, 1, 0), new InfuseObject(InfuseRegistry.get("CARBON"), 10));
InfuseRegistry.registerInfuseObject(new ItemStack(Item.coal, 1, 1), new InfuseObject(InfuseRegistry.get("CARBON"), 20)); InfuseRegistry.registerInfuseObject(new ItemStack(Item.coal, 1, 1), new InfuseObject(InfuseRegistry.get("CARBON"), 20));

View file

@ -10,6 +10,9 @@ import mekanism.api.infuse.InfusionInput;
import mekanism.api.infuse.InfusionOutput; import mekanism.api.infuse.InfusionOutput;
import mekanism.common.util.StackUtils; import mekanism.common.util.StackUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
/** /**
* Class used to handle machine recipes. This is used for both adding recipes and checking outputs. * Class used to handle machine recipes. This is used for both adding recipes and checking outputs.
@ -113,6 +116,16 @@ public final class RecipeHandler
Recipe.CHEMICAL_INJECTION_CHAMBER.put(input, output); Recipe.CHEMICAL_INJECTION_CHAMBER.put(input, output);
} }
/**
* Add an Electrolytic Separator recipe.
* @param fluid - FluidStack to electrolyze
* @param products - Pair of gases to produce when the fluid is electrolyzed
*/
public static void addElectrolyticSeparatorRecipe(FluidStack fluid, ChemicalInput products)
{
Recipe.ELECTROLYTIC_SEPARATOR.put(fluid, products);
}
/** /**
* Gets the InfusionOutput of the InfusionInput in the parameters. * Gets the InfusionOutput of the InfusionInput in the parameters.
* @param infusion - input Infusion * @param infusion - input Infusion
@ -266,6 +279,34 @@ public final class RecipeHandler
return false; return false;
} }
/**
* Get the result of electrolysing a given fluid
* @param fluidTank - the FluidTank to electrolyse fluid from
*/
public static ChemicalInput getElectrolyticSeparatorOutput(FluidTank fluidTank, boolean doRemove)
{
FluidStack fluid = fluidTank.getFluid();
if(fluid != null)
{
HashMap<FluidStack, ChemicalInput> recipes = Recipe.ELECTROLYTIC_SEPARATOR.get();
for(Map.Entry<FluidStack, ChemicalInput> entry : recipes.entrySet())
{
FluidStack key = (FluidStack)entry.getKey();
if(fluid.containsFluid(key))
{
fluidTank.drain(key.amount, doRemove);
return entry.getValue().copy();
}
}
}
return null;
}
public static enum Recipe public static enum Recipe
{ {
ENRICHMENT_CHAMBER(new HashMap<ItemStack, ItemStack>()), ENRICHMENT_CHAMBER(new HashMap<ItemStack, ItemStack>()),
@ -276,7 +317,8 @@ public final class RecipeHandler
METALLURGIC_INFUSER(new HashMap<InfusionInput, InfusionOutput>()), METALLURGIC_INFUSER(new HashMap<InfusionInput, InfusionOutput>()),
CHEMICAL_INFUSER(new HashMap<ChemicalInput, GasStack>()), CHEMICAL_INFUSER(new HashMap<ChemicalInput, GasStack>()),
CHEMICAL_OXIDIZER(new HashMap<ItemStack, GasStack>()), CHEMICAL_OXIDIZER(new HashMap<ItemStack, GasStack>()),
CHEMICAL_INJECTION_CHAMBER(new HashMap<ItemStack, ItemStack>()); CHEMICAL_INJECTION_CHAMBER(new HashMap<ItemStack, ItemStack>()),
ELECTROLYTIC_SEPARATOR(new HashMap<FluidStack, ChemicalInput>());
private HashMap recipes; private HashMap recipes;

View file

@ -1,13 +1,6 @@
package mekanism.generators.client.gui; package mekanism.generators.client.gui;
import java.util.ArrayList;
import mekanism.api.Coord4D;
import mekanism.api.gas.Gas; import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.util.MekanismUtils; import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType; import mekanism.common.util.MekanismUtils.ResourceType;
import mekanism.generators.common.inventory.container.ContainerElectrolyticSeparator; import mekanism.generators.common.inventory.container.ContainerElectrolyticSeparator;
@ -42,7 +35,7 @@ public class GuiElectrolyticSeparator extends GuiContainer
if(xAxis > 160 && xAxis < 169 && yAxis > 73 && yAxis < 82) if(xAxis > 160 && xAxis < 169 && yAxis > 73 && yAxis < 82)
{ {
Gas gasToSet = null; Gas gasToSet = null;
/*
if(tileEntity.outputType == GasRegistry.getGas("hydrogen")) if(tileEntity.outputType == GasRegistry.getGas("hydrogen"))
{ {
gasToSet = GasRegistry.getGas("oxygen"); gasToSet = GasRegistry.getGas("oxygen");
@ -62,11 +55,12 @@ public class GuiElectrolyticSeparator extends GuiContainer
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Coord4D.get(tileEntity), data)); PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Coord4D.get(tileEntity), data));
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F); mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
*/
} }
else if(xAxis > 8 && xAxis < 17 && yAxis > 73 && yAxis < 82) else if(xAxis > 8 && xAxis < 17 && yAxis > 73 && yAxis < 82)
{ {
Gas gasToSet = null; Gas gasToSet = null;
/*
if(tileEntity.dumpType == null) if(tileEntity.dumpType == null)
{ {
gasToSet = GasRegistry.getGas("oxygen"); gasToSet = GasRegistry.getGas("oxygen");
@ -86,6 +80,7 @@ public class GuiElectrolyticSeparator extends GuiContainer
PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Coord4D.get(tileEntity), data)); PacketHandler.sendPacket(Transmission.SERVER, new PacketTileEntity().setParams(Coord4D.get(tileEntity), data));
mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F); mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
*/
} }
} }
@ -114,21 +109,21 @@ public class GuiElectrolyticSeparator extends GuiContainer
int guiHeight = (height - ySize) / 2; int guiHeight = (height - ySize) / 2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize); drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
int outputDisplay = tileEntity.outputType == GasRegistry.getGas("oxygen") ? 82 : (tileEntity.outputType == GasRegistry.getGas("hydrogen") ? 90 : 98); int outputDisplay = 1;//tileEntity.outputType == GasRegistry.getGas("oxygen") ? 82 : (tileEntity.outputType == GasRegistry.getGas("hydrogen") ? 90 : 98);
drawTexturedModalRect(guiWidth + 160, guiHeight + 73, 176, outputDisplay, 8, 8); drawTexturedModalRect(guiWidth + 160, guiHeight + 73, 176, outputDisplay, 8, 8);
int dumpDisplay = tileEntity.dumpType == GasRegistry.getGas("oxygen") ? 82 : (tileEntity.dumpType == GasRegistry.getGas("hydrogen") ? 90 : 98); int dumpDisplay = 1;//tileEntity.dumpType == GasRegistry.getGas("oxygen") ? 82 : (tileEntity.dumpType == GasRegistry.getGas("hydrogen") ? 90 : 98);
drawTexturedModalRect(guiWidth + 8, guiHeight + 73, 176, dumpDisplay, 8, 8); drawTexturedModalRect(guiWidth + 8, guiHeight + 73, 176, dumpDisplay, 8, 8);
int displayInt; int displayInt;
displayInt = tileEntity.getScaledWaterLevel(52); displayInt = tileEntity.getScaledFluidLevel(52);
drawTexturedModalRect(guiWidth + 7, guiHeight + 17 + 52 - displayInt, 176 + 4, 52 - displayInt, 4, displayInt); drawTexturedModalRect(guiWidth + 7, guiHeight + 17 + 52 - displayInt, 176 + 4, 52 - displayInt, 4, displayInt);
displayInt = tileEntity.getScaledHydrogenLevel(30); displayInt = tileEntity.getLeftScaledLevel(30);
drawTexturedModalRect(guiWidth + 65, guiHeight + 17 + 30 - displayInt, 176, 52 + 30 - displayInt, 4, displayInt); drawTexturedModalRect(guiWidth + 65, guiHeight + 17 + 30 - displayInt, 176, 52 + 30 - displayInt, 4, displayInt);
displayInt = tileEntity.getScaledOxygenLevel(30); displayInt = tileEntity.getRightScaledLevel(30);
drawTexturedModalRect(guiWidth + 107, guiHeight + 17 + 30 - displayInt, 176 + 4, 52 + 30 - displayInt, 4, displayInt); drawTexturedModalRect(guiWidth + 107, guiHeight + 17 + 30 - displayInt, 176 + 4, 52 + 30 - displayInt, 4, displayInt);
displayInt = tileEntity.getScaledEnergyLevel(52); displayInt = tileEntity.getScaledEnergyLevel(52);

View file

@ -28,8 +28,7 @@ public class RenderElectrolyticSeparator extends TileEntitySpecialRenderer
{ {
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F); GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, tileEntity.outputType == GasRegistry.getGas("hydrogen") ? "ElectrolyticSeparatorHydrogen.png" : bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "ElectrolyticSeparatorNone.png"));
(tileEntity.outputType == GasRegistry.getGas("oxygen") ? "ElectrolyticSeparatorOxygen.png" : "ElectrolyticSeparatorNone.png")));
switch(tileEntity.facing) switch(tileEntity.facing)
{ {

View file

@ -1,19 +1,15 @@
package mekanism.generators.common.tileentity; package mekanism.generators.common.tileentity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random;
import mekanism.api.ChemicalInput;
import mekanism.api.Coord4D; import mekanism.api.Coord4D;
import mekanism.api.gas.Gas; import mekanism.api.gas.*;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.ISustainedTank; import mekanism.common.ISustainedTank;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler; import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission; import mekanism.common.PacketHandler.Transmission;
import mekanism.common.RecipeHandler;
import mekanism.common.network.PacketTileEntity; import mekanism.common.network.PacketTileEntity;
import mekanism.common.tileentity.TileEntityElectricBlock; import mekanism.common.tileentity.TileEntityElectricBlock;
import mekanism.common.util.ChargeUtils; import mekanism.common.util.ChargeUtils;
@ -38,35 +34,33 @@ import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext; import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral; import dan200.computer.api.IPeripheral;
public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock implements IFluidHandler, IPeripheral, ITubeConnection, ISustainedTank public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock implements IFluidHandler, IPeripheral, ITubeConnection, ISustainedTank, IGasHandler
{ {
/** This separator's water slot. */ /** This separator's water slot. */
public FluidTank waterTank = new FluidTank(24000); public FluidTank fluidTank = new FluidTank(24000);
/** The maximum amount of gas this block can store. */ /** The maximum amount of gas this block can store. */
public int MAX_GAS = 2400; public int MAX_GAS = 2400;
/** The amount of oxygen this block is storing. */ /** The amount of oxygen this block is storing. */
public int oxygenStored; public GasTank leftTank = new GasTank(MAX_GAS);
/** The amount of hydrogen this block is storing. */ /** The amount of hydrogen this block is storing. */
public int hydrogenStored; public GasTank rightTank = new GasTank(MAX_GAS);
/** How fast this block can output gas. */ /** How fast this block can output gas. */
public int output = 16; public int output = 16;
/** The type of gas this block is outputting. */ /** The type of gas this block is outputting. */
public Gas outputType; public boolean dumpLeft = false;
/** Type type of gas this block is dumping. */ /** Type type of gas this block is dumping. */
public Gas dumpType; public boolean dumpRight = false;
public TileEntityElectrolyticSeparator() public TileEntityElectrolyticSeparator()
{ {
super("ElectrolyticSeparator", GeneratorType.ELECTROLYTIC_SEPARATOR.maxEnergy); super("ElectrolyticSeparator", GeneratorType.ELECTROLYTIC_SEPARATOR.maxEnergy);
inventory = new ItemStack[4]; inventory = new ItemStack[4];
outputType = GasRegistry.getGas("oxygen");
dumpType = null;
} }
@Override @Override
@ -78,15 +72,15 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{ {
ChargeUtils.discharge(3, this); ChargeUtils.discharge(3, this);
if(inventory[0] != null) /*if(inventory[0] != null)
{ {
FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]); FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);
if(fluid != null && fluid.getFluid() == FluidRegistry.WATER) if(fluid != null && fluid.getFluid() == FluidRegistry.WATER)
{ {
if(waterTank.getFluid() == null || waterTank.getFluid().amount+fluid.amount <= waterTank.getCapacity()) if(fluidTank.getFluid() == null || fluidTank.getFluid().amount+fluid.amount <= fluidTank.getCapacity())
{ {
waterTank.fill(fluid, true); fluidTank.fill(fluid, true);
if(inventory[0].getItem().hasContainerItem()) if(inventory[0].getItem().hasContainerItem())
{ {
@ -102,52 +96,49 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
} }
} }
} }
} }*/
if(!worldObj.isRemote) if(!worldObj.isRemote)
{ {
if(inventory[1] != null && hydrogenStored > 0) if(inventory[1] != null && leftTank.getStored() > 0)
{ {
hydrogenStored -= GasTransmission.addGas(inventory[1], new GasStack(GasRegistry.getGas("hydrogen"), hydrogenStored)); leftTank.draw(GasTransmission.addGas(inventory[1], leftTank.getGas()), true);
MekanismUtils.saveChunk(this); MekanismUtils.saveChunk(this);
} }
if(inventory[2] != null && oxygenStored > 0) if(inventory[2] != null && rightTank.getStored() > 0)
{ {
hydrogenStored -= GasTransmission.addGas(inventory[2], new GasStack(GasRegistry.getGas("oxygen"), oxygenStored)); rightTank.draw(GasTransmission.addGas(inventory[2], rightTank.getGas()), true);
MekanismUtils.saveChunk(this); MekanismUtils.saveChunk(this);
} }
} }
if(oxygenStored < MAX_GAS && hydrogenStored < MAX_GAS && waterTank.getFluid() != null && waterTank.getFluid().amount-2 >= 0 && getEnergy()-100 > 0) if(canOperate())
{ {
waterTank.drain(2, true); fillTanks(RecipeHandler.getElectrolyticSeparatorOutput(fluidTank, true));
setEnergy(getEnergy() - MekanismGenerators.electrolyticSeparatorUsage); setEnergy(getEnergy() - MekanismGenerators.electrolyticSeparatorUsage);
setStored(GasRegistry.getGas("oxygen"), oxygenStored + 1);
setStored(GasRegistry.getGas("hydrogen"), hydrogenStored + 2);
} }
if(outputType != null && getStored(outputType) > 0) if(leftTank.getGas() != null)
{ {
GasStack toSend = new GasStack(outputType, Math.min(getStored(outputType), output)); if(!dumpLeft)
setStored(outputType, getStored(outputType) - GasTransmission.emitGasToNetwork(toSend, this, ForgeDirection.getOrientation(facing))); {
GasStack toSend = new GasStack(leftTank.getGas().getGas(), Math.min(leftTank.getStored(), output));
leftTank.draw(GasTransmission.emitGasToNetwork(toSend, this, MekanismUtils.getLeft(facing)), true);
TileEntity tileEntity = Coord4D.get(this).getFromSide(ForgeDirection.getOrientation(facing)).getTileEntity(worldObj); TileEntity tileEntity = Coord4D.get(this).getFromSide(MekanismUtils.getLeft(facing)).getTileEntity(worldObj);
if(tileEntity instanceof IGasHandler) if(tileEntity instanceof IGasHandler)
{ {
if(((IGasHandler)tileEntity).canReceiveGas(ForgeDirection.getOrientation(facing).getOpposite(), outputType)) if(((IGasHandler)tileEntity).canReceiveGas(ForgeDirection.getOrientation(facing).getOpposite(), leftTank.getGas().getGas()))
{ {
int added = ((IGasHandler)tileEntity).receiveGas(ForgeDirection.getOrientation(facing).getOpposite(), new GasStack(outputType, Math.min(getStored(outputType), output))); leftTank.draw(((IGasHandler)tileEntity).receiveGas(ForgeDirection.getOrientation(facing).getOpposite(), toSend), true);
setStored(outputType, getStored(outputType) - added);
} }
} }
} }
else
if(dumpType != null && getStored(dumpType) > 0)
{ {
setStored(dumpType, (getStored(dumpType) - 8)); leftTank.draw(8, true);
if(worldObj.rand.nextInt(3) == 2) if(worldObj.rand.nextInt(3) == 2)
{ {
@ -155,34 +146,70 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
} }
} }
} }
if(rightTank.getGas() != null)
{
if(!dumpRight)
{
GasStack toSend = new GasStack(rightTank.getGas().getGas(), Math.min(rightTank.getStored(), output));
rightTank.draw(GasTransmission.emitGasToNetwork(toSend, this, MekanismUtils.getRight(facing)), true);
TileEntity tileEntity = Coord4D.get(this).getFromSide(MekanismUtils.getRight(facing)).getTileEntity(worldObj);
if(tileEntity instanceof IGasHandler)
{
if(((IGasHandler)tileEntity).canReceiveGas(ForgeDirection.getOrientation(facing).getOpposite(), rightTank.getGas().getGas()))
{
rightTank.draw(((IGasHandler)tileEntity).receiveGas(ForgeDirection.getOrientation(facing).getOpposite(), toSend), true);
}
}
}
else
{
rightTank.draw(8, true);
if(worldObj.rand.nextInt(3) == 2)
{
PacketHandler.sendPacket(Transmission.CLIENTS_RANGE, new PacketTileEntity().setParams(Coord4D.get(this), getParticlePacket(new ArrayList())), Coord4D.get(this), 40D);
}
}
} }
public int getStored(Gas gas)
{
if(gas == GasRegistry.getGas("oxygen"))
{
return oxygenStored;
} }
else if(gas == GasRegistry.getGas("hydrogen"))
{
return hydrogenStored;
} }
return 0; public boolean canOperate()
{
return canFillWithSwap(RecipeHandler.getElectrolyticSeparatorOutput(fluidTank, false)) && getEnergy() >= MekanismGenerators.electrolyticSeparatorUsage;
} }
public void setStored(Gas type, int amount) public boolean canFillWithSwap(ChemicalInput gases)
{ {
if(type == GasRegistry.getGas("hydrogen")) if(gases == null)
{ return false;
hydrogenStored = Math.max(Math.min(amount, MAX_GAS), 0); return canFill(gases) || canFill(gases.swap());
}
else if(type == GasRegistry.getGas("oxygen"))
{
oxygenStored = Math.max(Math.min(amount, MAX_GAS), 0);
} }
MekanismUtils.saveChunk(this); public boolean canFill(ChemicalInput gases)
{
return (leftTank.canReceive(gases.leftGas.getGas()) && leftTank.getNeeded() >= gases.leftGas.amount
&& rightTank.canReceive(gases.rightGas.getGas()) && rightTank.getNeeded() >= gases.rightGas.amount);
}
public void fillTanks(ChemicalInput gases)
{
if(gases == null) return;
if(canFill(gases))
{
leftTank.receive(gases.leftGas, true);
rightTank.receive(gases.rightGas, true);
}
else if(canFill(gases.swap()))
{
leftTank.receive(gases.rightGas, true);
rightTank.receive(gases.leftGas, true);
}
} }
public void spawnParticle() public void spawnParticle()
@ -267,9 +294,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
* @param i - multiplier * @param i - multiplier
* @return * @return
*/ */
public int getScaledHydrogenLevel(int i) public int getLeftScaledLevel(int i)
{ {
return hydrogenStored*i / MAX_GAS; return leftTank.getStored()*i / MAX_GAS;
} }
/** /**
@ -277,9 +304,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
* @param i - multiplier * @param i - multiplier
* @return * @return
*/ */
public int getScaledOxygenLevel(int i) public int getRightScaledLevel(int i)
{ {
return oxygenStored*i / MAX_GAS; return rightTank.getStored()*i / MAX_GAS;
} }
/** /**
@ -287,9 +314,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
* @param i - multiplier * @param i - multiplier
* @return * @return
*/ */
public int getScaledWaterLevel(int i) public int getScaledFluidLevel(int i)
{ {
return waterTank.getFluid() != null ? waterTank.getFluid().amount*i / waterTank.getCapacity() : 0; return fluidTank.getFluid() != null ? fluidTank.getFluid().amount*i / fluidTank.getCapacity() : 0;
} }
/** /**
@ -311,11 +338,11 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
if(type == 0) if(type == 0)
{ {
outputType = GasRegistry.getGas(dataStream.readInt()); dumpLeft = dataStream.readBoolean();
} }
else if(type == 1) else if(type == 1)
{ {
dumpType = GasRegistry.getGas(dataStream.readInt()); dumpRight = dataStream.readBoolean();
} }
return; return;
@ -327,20 +354,32 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
if(type == 0) if(type == 0)
{ {
int amount = dataStream.readInt(); if(dataStream.readBoolean())
if(amount != 0)
{ {
waterTank.setFluid(new FluidStack(FluidRegistry.WATER, amount)); fluidTank.setFluid(new FluidStack(FluidRegistry.getFluid(dataStream.readInt()), dataStream.readInt()));
} }
else { else {
waterTank.setFluid(null); fluidTank.setFluid(null);
} }
oxygenStored = dataStream.readInt(); if(dataStream.readBoolean())
hydrogenStored = dataStream.readInt(); {
outputType = GasRegistry.getGas(dataStream.readInt()); leftTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
dumpType = GasRegistry.getGas(dataStream.readInt()); }
else {
leftTank.setGas(null);
}
if(dataStream.readBoolean())
{
rightTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
}
else {
rightTank.setGas(null);
}
dumpLeft = dataStream.readBoolean();
dumpRight = dataStream.readBoolean();
} }
else if(type == 1) else if(type == 1)
{ {
@ -354,18 +393,39 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
super.getNetworkedData(data); super.getNetworkedData(data);
data.add(0); data.add(0);
if(waterTank.getFluid() != null)
if(fluidTank.getFluid() != null)
{ {
data.add(waterTank.getFluid().amount); data.add(true);
data.add(fluidTank.getFluid().getFluid().getID());
data.add(fluidTank.getFluidAmount());
} }
else { else {
data.add(0); data.add(false);
} }
data.add(oxygenStored); if(leftTank.getGas() != null)
data.add(hydrogenStored); {
data.add(GasRegistry.getGasID(outputType)); data.add(true);
data.add(GasRegistry.getGasID(dumpType)); data.add(leftTank.getGas().getGas().getID());
data.add(leftTank.getStored());
}
else {
data.add(false);
}
if(rightTank.getGas() != null)
{
data.add(true);
data.add(rightTank.getGas().getGas().getID());
data.add(rightTank.getStored());
}
else {
data.add(false);
}
data.add(dumpLeft);
data.add(dumpRight);
return data; return data;
} }
@ -382,18 +442,16 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{ {
super.readFromNBT(nbtTags); super.readFromNBT(nbtTags);
hydrogenStored = nbtTags.getInteger("hydrogenStored"); if(nbtTags.hasKey("fluidTank"))
oxygenStored = nbtTags.getInteger("oxygenStored");
if(nbtTags.hasKey("waterTank"))
{ {
waterTank.readFromNBT(nbtTags.getCompoundTag("waterTank")); fluidTank.readFromNBT(nbtTags.getCompoundTag("fluidTank"));
} }
try { leftTank.read(nbtTags.getCompoundTag("leftTank"));
outputType = Gas.readFromNBT(nbtTags.getCompoundTag("outputType")); rightTank.read(nbtTags.getCompoundTag("rightTank"));
dumpType = Gas.readFromNBT(nbtTags.getCompoundTag("dumpType"));
} catch(Exception e) {} //TODO remove next major release dumpLeft = nbtTags.getBoolean("dumpLeft");
dumpRight = nbtTags.getBoolean("dumpRight");
} }
@Override @Override
@ -401,23 +459,16 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{ {
super.writeToNBT(nbtTags); super.writeToNBT(nbtTags);
nbtTags.setInteger("hydrogenStored", hydrogenStored); if(fluidTank.getFluid() != null)
nbtTags.setInteger("oxygenStored", oxygenStored);
if(waterTank.getFluid() != null)
{ {
nbtTags.setTag("waterTank", waterTank.writeToNBT(new NBTTagCompound())); nbtTags.setTag("fluidTank", fluidTank.writeToNBT(new NBTTagCompound()));
} }
if(outputType != null) nbtTags.setCompoundTag("leftTank", leftTank.write(new NBTTagCompound()));
{ nbtTags.setCompoundTag("rightTank", rightTank.write(new NBTTagCompound()));
nbtTags.setCompoundTag("outputType", outputType.write(new NBTTagCompound()));
}
if(dumpType != null) nbtTags.setBoolean("dumpLeft", dumpLeft);
{ nbtTags.setBoolean("dumpRight", dumpRight);
nbtTags.setCompoundTag("dumpType", dumpType.write(new NBTTagCompound()));
}
} }
@Override @Override
@ -446,17 +497,17 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
case 3: case 3:
return new Object[] {(MAX_ELECTRICITY-electricityStored)}; return new Object[] {(MAX_ELECTRICITY-electricityStored)};
case 4: case 4:
return new Object[] {waterTank.getFluid() != null ? waterTank.getFluid().amount : 0}; return new Object[] {fluidTank.getFluid() != null ? fluidTank.getFluid().amount : 0};
case 5: case 5:
return new Object[] {waterTank.getFluid() != null ? (waterTank.getCapacity()-waterTank.getFluid().amount) : 0}; return new Object[] {fluidTank.getFluid() != null ? (fluidTank.getCapacity()- fluidTank.getFluid().amount) : 0};
case 6: case 6:
return new Object[] {hydrogenStored}; return new Object[] {leftTank.getStored()};
case 7: case 7:
return new Object[] {MAX_GAS-hydrogenStored}; return new Object[] {leftTank.getNeeded()};
case 8: case 8:
return new Object[] {oxygenStored}; return new Object[] {rightTank.getStored()};
case 9: case 9:
return new Object[] {MAX_GAS-oxygenStored}; return new Object[] {rightTank.getNeeded()};
default: default:
System.err.println("[Mekanism] Attempted to call unknown method with computer ID " + computer.getID()); System.err.println("[Mekanism] Attempted to call unknown method with computer ID " + computer.getID());
return new Object[] {"Unknown command."}; return new Object[] {"Unknown command."};
@ -478,19 +529,19 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
@Override @Override
public boolean canTubeConnect(ForgeDirection side) public boolean canTubeConnect(ForgeDirection side)
{ {
return side == ForgeDirection.getOrientation(facing); return side == MekanismUtils.getLeft(facing) || side == MekanismUtils.getRight(facing);
} }
@Override @Override
public void setFluidStack(FluidStack fluidStack, Object... data) public void setFluidStack(FluidStack fluidStack, Object... data)
{ {
waterTank.setFluid(fluidStack); fluidTank.setFluid(fluidStack);
} }
@Override @Override
public FluidStack getFluidStack(Object... data) public FluidStack getFluidStack(Object... data)
{ {
return waterTank.getFluid(); return fluidTank.getFluid();
} }
@Override @Override
@ -522,7 +573,7 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{ {
if(resource.getFluid() == FluidRegistry.WATER) if(resource.getFluid() == FluidRegistry.WATER)
{ {
return waterTank.fill(resource, doFill); return fluidTank.fill(resource, doFill);
} }
return 0; return 0;
@ -537,6 +588,26 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
@Override @Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) public FluidTankInfo[] getTankInfo(ForgeDirection from)
{ {
return new FluidTankInfo[] {waterTank.getInfo()}; return new FluidTankInfo[] {fluidTank.getInfo()};
}
@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;
} }
} }