diff --git a/src/main/java/mekanism/api/MekanismConfig.java b/src/main/java/mekanism/api/MekanismConfig.java index 2c6799a28..8e3952626 100644 --- a/src/main/java/mekanism/api/MekanismConfig.java +++ b/src/main/java/mekanism/api/MekanismConfig.java @@ -80,6 +80,7 @@ public class MekanismConfig public static double fluidicPlenisherUsage; public static double laserUsage; public static double salinationPlantWaterUsage; + public static double gasCentrifugeUsage; } public static class generators diff --git a/src/main/java/mekanism/client/ClientProxy.java b/src/main/java/mekanism/client/ClientProxy.java index c4a201532..1f1de9295 100644 --- a/src/main/java/mekanism/client/ClientProxy.java +++ b/src/main/java/mekanism/client/ClientProxy.java @@ -137,6 +137,7 @@ import mekanism.common.tile.TileEntityEnrichmentChamber; import mekanism.common.tile.TileEntityEntangledBlock; import mekanism.common.tile.TileEntityFactory; import mekanism.common.tile.TileEntityFluidicPlenisher; +import mekanism.common.tile.TileEntityGasCentrifuge; import mekanism.common.tile.TileEntityGasTank; import mekanism.common.tile.TileEntityLaser; import mekanism.common.tile.TileEntityLaserAmplifier; @@ -311,6 +312,7 @@ public class ClientProxy extends CommonProxy ClientRegistry.registerTileEntity(TileEntityLaserAmplifier.class, "LaserAmplifier", new RenderLaserAmplifier()); ClientRegistry.registerTileEntity(TileEntityLaserTractorBeam.class, "LaserTractorBeam", new RenderLaserTractorBeam()); GameRegistry.registerTileEntity(TileEntityAmbientAccumulator.class, "AmbientAccumulator"); + GameRegistry.registerTileEntity(TileEntityGasCentrifuge.class, "GasCentrifuge"); } @Override diff --git a/src/main/java/mekanism/common/CommonProxy.java b/src/main/java/mekanism/common/CommonProxy.java index fc2daa890..42e87c5c0 100644 --- a/src/main/java/mekanism/common/CommonProxy.java +++ b/src/main/java/mekanism/common/CommonProxy.java @@ -72,6 +72,7 @@ import mekanism.common.tile.TileEntityEnergyCube; import mekanism.common.tile.TileEntityEnrichmentChamber; import mekanism.common.tile.TileEntityFactory; import mekanism.common.tile.TileEntityFluidicPlenisher; +import mekanism.common.tile.TileEntityGasCentrifuge; import mekanism.common.tile.TileEntityGasTank; import mekanism.common.tile.TileEntityLaser; import mekanism.common.tile.TileEntityLaserAmplifier; @@ -155,6 +156,7 @@ public class CommonProxy GameRegistry.registerTileEntity(TileEntityLaserAmplifier.class, "LaserAmplifier"); GameRegistry.registerTileEntity(TileEntityLaserTractorBeam.class, "LaserTractorBeam"); GameRegistry.registerTileEntity(TileEntityAmbientAccumulator.class, "AmbientAccumulator"); + GameRegistry.registerTileEntity(TileEntityGasCentrifuge.class, "GasCentrifuge"); } /** @@ -268,6 +270,7 @@ public class CommonProxy usage.fluidicPlenisherUsage = Mekanism.configuration.get("usage", "FluidicPlenisherUsage", 100D).getDouble(100D); usage.laserUsage = Mekanism.configuration.get("usage", "LaserUsage", 5000D).getDouble(5000D); usage.salinationPlantWaterUsage = Mekanism.configuration.get("usage", "SalinationPlantSpeed", 40.0, "Millibuckets of water turned into brine by the plant per tick", 1.0, 9000.0).getDouble(); + usage.gasCentrifugeUsage = Mekanism.configuration.get("usage", "GasCentrifugeUsage", 100D).getDouble(100D); if(Mekanism.configuration.hasChanged()) { diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index 275e71ce6..67290da21 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -744,6 +744,9 @@ public class Mekanism 60 ); + RecipeHandler.addCentrifugeRecipe(new GasStack(GasRegistry.getGas("hydrogen"), 10), new GasStack(GasRegistry.getGas("deuterium"), 1)); + RecipeHandler.addCentrifugeRecipe(new GasStack(GasRegistry.getGas("deuterium"), 10), new GasStack(GasRegistry.getGas("tritium"), 1)); + //Infuse objects InfuseRegistry.registerInfuseObject(new ItemStack(MekanismItems.BioFuel), new InfuseObject(InfuseRegistry.get("BIO"), 5)); InfuseRegistry.registerInfuseObject(new ItemStack(Items.coal, 1, 0), new InfuseObject(InfuseRegistry.get("CARBON"), 10)); diff --git a/src/main/java/mekanism/common/block/BlockMachine.java b/src/main/java/mekanism/common/block/BlockMachine.java index 28c8fbf4e..f85041690 100644 --- a/src/main/java/mekanism/common/block/BlockMachine.java +++ b/src/main/java/mekanism/common/block/BlockMachine.java @@ -53,6 +53,7 @@ import mekanism.common.tile.TileEntityEnrichmentChamber; import mekanism.common.tile.TileEntityEntangledBlock; import mekanism.common.tile.TileEntityFactory; import mekanism.common.tile.TileEntityFluidicPlenisher; +import mekanism.common.tile.TileEntityGasCentrifuge; import mekanism.common.tile.TileEntityLaser; import mekanism.common.tile.TileEntityLaserAmplifier; import mekanism.common.tile.TileEntityLaserTractorBeam; @@ -205,6 +206,7 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer case MACHINE_BLOCK_3: icons[0][0] = register.registerIcon("mekanism:AmbientAccumulator"); icons[1][0] = register.registerIcon("mekanism:SteelCasing"); + icons[2][0] = register.registerIcon("mekanism:GasCentrifuge"); break; } @@ -1055,7 +1057,8 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer LASER_AMPLIFIER(MachineBlock.MACHINE_BLOCK_2, 14, "LaserAmplifier", 44, TileEntityLaserAmplifier.class, false, true, false), LASER_TRACTOR_BEAM(MachineBlock.MACHINE_BLOCK_2, 15, "LaserTractorBeam", 45, TileEntityLaserTractorBeam.class, false, true, false), AMBIENT_ACCUMULATOR(MachineBlock.MACHINE_BLOCK_3, 0, "AmbientAccumulator", 46, TileEntityAmbientAccumulator.class, true, false, false), - ENTANGLED_BLOCK(MachineBlock.MACHINE_BLOCK_3, 1, "EntangledBlock", 47, TileEntityEntangledBlock.class, true, false, false); + ENTANGLED_BLOCK(MachineBlock.MACHINE_BLOCK_3, 1, "EntangledBlock", 47, TileEntityEntangledBlock.class, true, false, false), + GAS_CENTRIFUGE(MachineBlock.MACHINE_BLOCK_3, 2, "GasCentrifuge", 48, TileEntityGasCentrifuge.class, true, false, false); public MachineBlock typeBlock; public int meta; @@ -1186,6 +1189,8 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IPer return 0; case ENTANGLED_BLOCK: return 0; + case GAS_CENTRIFUGE: + return 100; default: return 0; } diff --git a/src/main/java/mekanism/common/network/PacketConfigSync.java b/src/main/java/mekanism/common/network/PacketConfigSync.java index 5a34ff9aa..47a981169 100644 --- a/src/main/java/mekanism/common/network/PacketConfigSync.java +++ b/src/main/java/mekanism/common/network/PacketConfigSync.java @@ -73,6 +73,7 @@ public class PacketConfigSync implements IMessageHandler recipes = Recipe.GAS_CENTRIFUGE.get(); + + GasCentrifugeRecipe recipe = recipes.get(input); + return recipe == null ? null : recipe.copy(); + } + + return null; + } + /** * Gets the ChanceMachineRecipe of the ItemStackInput in the parameters, using the map in the parameters. * @param input - ItemStackInput @@ -499,7 +518,8 @@ public final class RecipeHandler CHEMICAL_WASHER(new HashMap()), CHEMICAL_CRYSTALLIZER(new HashMap()), PRESSURIZED_REACTION_CHAMBER(new HashMap()), - AMBIENT_ACCUMULATOR(new HashMap()); + AMBIENT_ACCUMULATOR(new HashMap()), + GAS_CENTRIFUGE(new HashMap()); private HashMap recipes; diff --git a/src/main/java/mekanism/common/recipe/machines/GasCentrifugeRecipe.java b/src/main/java/mekanism/common/recipe/machines/GasCentrifugeRecipe.java new file mode 100644 index 000000000..bd6576e61 --- /dev/null +++ b/src/main/java/mekanism/common/recipe/machines/GasCentrifugeRecipe.java @@ -0,0 +1,39 @@ +package mekanism.common.recipe.machines; + +import mekanism.api.gas.GasStack; +import mekanism.api.gas.GasTank; +import mekanism.common.recipe.inputs.GasInput; +import mekanism.common.recipe.outputs.GasOutput; + +public class GasCentrifugeRecipe extends MachineRecipe +{ + public GasCentrifugeRecipe(GasStack input, GasStack output) + { + super(new GasInput(input), new GasOutput(output)); + } + + public GasCentrifugeRecipe(GasInput input, GasOutput output) + { + super(input, output); + } + + @Override + public GasCentrifugeRecipe copy() + { + return new GasCentrifugeRecipe(getInput(), getOutput()); + } + + public boolean canOperate(GasTank inputTank, GasTank outputTank) + { + return getInput().useGas(inputTank, false) && getOutput().applyOutputs(outputTank, false); + } + + public void operate(GasTank inputTank, GasTank outputTank) + { + if(getInput().useGas(inputTank, true)) + { + getOutput().applyOutputs(outputTank, true); + } + } + +} diff --git a/src/main/java/mekanism/common/tile/TileEntityGasCentrifuge.java b/src/main/java/mekanism/common/tile/TileEntityGasCentrifuge.java new file mode 100644 index 000000000..237e04682 --- /dev/null +++ b/src/main/java/mekanism/common/tile/TileEntityGasCentrifuge.java @@ -0,0 +1,230 @@ +package mekanism.common.tile; + +import java.util.ArrayList; + +import mekanism.api.Coord4D; +import mekanism.api.MekanismConfig.usage; +import mekanism.api.Range4D; +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasStack; +import mekanism.api.gas.GasTank; +import mekanism.api.gas.GasTransmission; +import mekanism.api.gas.IGasHandler; +import mekanism.api.gas.ITubeConnection; +import mekanism.common.Mekanism; +import mekanism.common.base.IRedstoneControl.RedstoneControl; +import mekanism.common.block.BlockMachine.MachineType; +import mekanism.common.network.PacketTileEntity.TileEntityMessage; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.inputs.GasInput; +import mekanism.common.recipe.machines.GasCentrifugeRecipe; +import mekanism.common.util.ChargeUtils; +import mekanism.common.util.MekanismUtils; + +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileEntityGasCentrifuge extends TileEntityNoisyElectricBlock implements IGasHandler, ITubeConnection +{ + public GasTank inputTank = new GasTank(MAX_GAS); + public GasTank outputTank = new GasTank(MAX_GAS); + + public static final int MAX_GAS = 10000; + + public int updateDelay; + + public int gasOutput = 16; + + public boolean isActive; + + public boolean clientActive; + + public double prevEnergy; + + public double energyUsage = usage.gasCentrifugeUsage; + + public GasCentrifugeRecipe cachedRecipe; + + public RedstoneControl controlType = RedstoneControl.DISABLED; + + public TileEntityGasCentrifuge() + { + super("machine.centrifuge", "GasCentrifuge", MachineType.GAS_CENTRIFUGE.baseEnergy); + inventory = new ItemStack[3]; + } + + @Override + public void onUpdate() + { + if(worldObj.isRemote && updateDelay > 0) + { + updateDelay--; + + if(updateDelay == 0 && clientActive != isActive) + { + isActive = clientActive; + MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord); + } + } + + if(!worldObj.isRemote) + { + GasCentrifugeRecipe recipe = getRecipe(); + if(updateDelay > 0) + { + updateDelay--; + + if(updateDelay == 0 && clientActive != isActive) + { + Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this))); + } + } + + ChargeUtils.discharge(1, this); + + if(inventory[2] != null && inputTank.getGas() != null) + { + inputTank.draw(GasTransmission.addGas(inventory[2], inputTank.getGas()), true); + } + + if(canOperate(recipe) && getEnergy() >= energyUsage && MekanismUtils.canFunction(this)) + { + setActive(true); + setEnergy(getEnergy() - energyUsage); + + operate(recipe); + markDirty(); + } + else { + if(prevEnergy >= getEnergy()) + { + setActive(false); + } + } + + prevEnergy = getEnergy(); + + if(outputTank.getGas() != null) + { + GasStack toSend = new GasStack(outputTank.getGas().getGas(), Math.min(outputTank.getStored(), gasOutput)); + + for(ForgeDirection side : new ForgeDirection[]{ForgeDirection.NORTH, ForgeDirection.SOUTH, ForgeDirection.WEST, ForgeDirection.EAST}) + { + TileEntity tileEntity = Coord4D.get(this).getFromSide(side).getTileEntity(worldObj); + + if(tileEntity instanceof IGasHandler) + { + if(((IGasHandler)tileEntity).canReceiveGas(side.getOpposite(), outputTank.getGas().getGas())) + { + outputTank.draw(((IGasHandler)tileEntity).receiveGas(side.getOpposite(), toSend, true), true); + break; + } + } + } + } + } + } + + public GasCentrifugeRecipe getRecipe() + { + GasInput input = getInput(); + if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput())) + { + cachedRecipe = RecipeHandler.getCentrifugeRecipe(getInput()); + } + return cachedRecipe; + } + + public GasInput getInput() + { + return new GasInput(inputTank.getGas()); + } + + public boolean canOperate(GasCentrifugeRecipe recipe) + { + return recipe != null && recipe.canOperate(inputTank, outputTank); + } + + public void operate(GasCentrifugeRecipe recipe) + { + recipe.operate(inputTank, outputTank); + } + + @Override + public void setActive(boolean active) + { + isActive = active; + + if(clientActive != active && updateDelay == 0) + { + Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this))); + + updateDelay = 10; + clientActive = active; + } + } + + @Override + public boolean getActive() + { + return isActive; + } + + @Override + public boolean renderUpdate() + { + return false; + } + + @Override + public boolean lightUpdate() + { + return false; + } + + public GasTank getTank(ForgeDirection side) + { + return side == ForgeDirection.UP ? inputTank : outputTank; + } + + @Override + public int receiveGas(ForgeDirection side, GasStack stack, boolean doTransfer) + { + if(canReceiveGas(side, stack != null ? stack.getGas() : null)) + { + return getTank(side).receive(stack, doTransfer); + } + + return 0; + } + + @Override + public GasStack drawGas(ForgeDirection side, int amount, boolean doTransfer) + { + if(canDrawGas(side, null)) + { + return getTank(side).draw(amount, doTransfer); + } + + return null; + } + + @Override + public boolean canDrawGas(ForgeDirection side, Gas type) + { + return getTank(side) == outputTank ? getTank(side).canDraw(type) : false; + } + + @Override + public boolean canReceiveGas(ForgeDirection side, Gas type) + { + return getTank(side) != null && getTank(side) != outputTank ? getTank(side).canReceive(type) : false; + } + + @Override + public boolean canTubeConnect(ForgeDirection side) + { + return side != ForgeDirection.DOWN; + } +}