From 67a4f21dec53df4c74ea953babed1eee7adc56c7 Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Tue, 28 Jan 2014 17:11:46 -0500 Subject: [PATCH] Started on fluid motor, and hydraulic pressure --- .../api/fluid/IFluidNetwork.java | 76 ++-- .../api/fluid/IFluidPipe.java | 2 + .../mechanical/fluid/network/PipeNetwork.java | 238 ++++++------ .../mechanical/fluid/pipe/PartPipe.java | 344 +++++++++--------- .../mechanical/fluid/tank/TankNetwork.java | 117 +++--- .../mechanical/motor/BlockFluidMotor.java | 83 +++++ .../mechanical/motor/TileFluidMotor.java | 103 ++++++ 7 files changed, 582 insertions(+), 381 deletions(-) create mode 100644 src/main/java/resonantinduction/mechanical/motor/BlockFluidMotor.java create mode 100644 src/main/java/resonantinduction/mechanical/motor/TileFluidMotor.java diff --git a/src/main/java/resonantinduction/api/fluid/IFluidNetwork.java b/src/main/java/resonantinduction/api/fluid/IFluidNetwork.java index c2bdf459..7036381f 100644 --- a/src/main/java/resonantinduction/api/fluid/IFluidNetwork.java +++ b/src/main/java/resonantinduction/api/fluid/IFluidNetwork.java @@ -7,54 +7,48 @@ import net.minecraftforge.fluids.FluidTankInfo; import net.minecraftforge.fluids.IFluidHandler; import universalelectricity.api.net.INodeNetwork; -/** - * Interface version of the fluid network. +/** Interface version of the fluid network. * - * @author DarkGuardsman - */ + * @author DarkGuardsman */ public interface IFluidNetwork extends INodeNetwork { - /** Called to build the network when something changes such as addition of a pipe */ - @Override - void reconstruct(); + /** Called to build the network when something changes such as addition of a pipe */ + @Override + void reconstruct(); - /** - * Called to add fluid into the network - * - * @param source - part that is receiving the fluid for the network - * @param from - direction of this connection - * @param resource - fluid stack that is being filled into the network - * @param doFill - true causes the action to be taken, false simulates the action - * @return amount of fluid filled into the network - */ - int fill(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doFill); + /** Called to add fluid into the network + * + * @param source - part that is receiving the fluid for the network + * @param from - direction of this connection + * @param resource - fluid stack that is being filled into the network + * @param doFill - true causes the action to be taken, false simulates the action + * @return amount of fluid filled into the network */ + int fill(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doFill); - /** - * Called to remove fluid from a network, not supported by all networks - * - * @param source - part that is receiving the fluid for the network - * @param from - direction of this connection - * @param resource - fluid stack that is being filled into the network - * @param doDrain - true causes the action to be taken, false simulates the action - * @return FluidStack that contains the fluid drained from the network - */ - FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain); + /** Called to remove fluid from a network, not supported by all networks + * + * @param source - part that is receiving the fluid for the network + * @param from - direction of this connection + * @param resource - fluid stack that is being filled into the network + * @param doDrain - true causes the action to be taken, false simulates the action + * @return FluidStack that contains the fluid drained from the network */ + FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain); - /** - * Called to remove fluid from a network, not supported by all networks - * - * @param source - part that is receiving the fluid for the network - * @param from - direction of this connection - * @param resource - fluid stack that is being filled into the network - * @param doDrain - true causes the action to be taken, false simulates the action - * @return FluidStack that contains the fluid drained from the network - */ - FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain); + /** Called to remove fluid from a network, not supported by all networks + * + * @param source - part that is receiving the fluid for the network + * @param from - direction of this connection + * @param resource - fluid stack that is being filled into the network + * @param doDrain - true causes the action to be taken, false simulates the action + * @return FluidStack that contains the fluid drained from the network */ + FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain); - /** Fluid tank that represents the entire network */ - FluidTank getTank(); + /** Fluid tank that represents the entire network */ + FluidTank getTank(); - /** Information about the network's tank */ - FluidTankInfo[] getTankInfo(); + /** Information about the network's tank */ + FluidTankInfo[] getTankInfo(); + + int getPressure(); } diff --git a/src/main/java/resonantinduction/api/fluid/IFluidPipe.java b/src/main/java/resonantinduction/api/fluid/IFluidPipe.java index 3d8f98b2..054c2e4f 100644 --- a/src/main/java/resonantinduction/api/fluid/IFluidPipe.java +++ b/src/main/java/resonantinduction/api/fluid/IFluidPipe.java @@ -13,6 +13,8 @@ public interface IFluidPipe extends IFluidConnector, IPressureInput * @return amount in pascals. */ int getMaxPressure(); + + int getPressure(); /** * Max flow rate of fluid this pipe can support diff --git a/src/main/java/resonantinduction/mechanical/fluid/network/PipeNetwork.java b/src/main/java/resonantinduction/mechanical/fluid/network/PipeNetwork.java index 3ae20ffd..7380a3fd 100644 --- a/src/main/java/resonantinduction/mechanical/fluid/network/PipeNetwork.java +++ b/src/main/java/resonantinduction/mechanical/fluid/network/PipeNetwork.java @@ -13,143 +13,149 @@ import resonantinduction.api.fluid.IFluidNetwork; import resonantinduction.api.fluid.IFluidPipe; import calclavia.lib.utility.FluidUtility; -/** - * The network for pipe fluid transfer. getNodes() is NOT used. +/** The network for pipe fluid transfer. getNodes() is NOT used. * - * @author DarkGuardsman - */ + * @author DarkGuardsman */ public class PipeNetwork extends FluidNetwork { - public HashMap> sideMap = new HashMap>(); - public HashMap connectionMap = new HashMap(); - public int maxFlowRate = 0; - public int maxPressure = 0; + public HashMap> sideMap = new HashMap>(); + public HashMap connectionMap = new HashMap(); + public int maxFlowRate = 0; + public int maxPressure = 0; + public int currentPressure = 0; + public int currentFlowRate = 0; - @Override - public void update() - { - /* - * Slight delay to allow visual effect to take place before draining the pipe's internal - * tank - */ - FluidStack stack = this.getTank().getFluid().copy(); - int count = this.sideMap.size(); + @Override + public void update() + { + /* + * Slight delay to allow visual effect to take place before draining the pipe's internal + * tank + */ + FluidStack stack = this.getTank().getFluid().copy(); + int count = this.sideMap.size(); - Iterator>> it = new HashMap>(sideMap).entrySet().iterator(); + Iterator>> it = new HashMap>(sideMap).entrySet().iterator(); - while (it.hasNext()) - { - Entry> entry = it.next(); - int sideCount = entry.getValue().size(); + while (it.hasNext()) + { + Entry> entry = it.next(); + int sideCount = entry.getValue().size(); - for (ForgeDirection dir : entry.getValue()) - { - int volPer = (stack.amount / count); - int volPerSide = (volPer / sideCount); - IFluidHandler handler = entry.getKey(); + for (ForgeDirection dir : entry.getValue()) + { + int volPer = (stack.amount / count); + int volPerSide = (volPer / sideCount); + IFluidHandler handler = entry.getKey(); - /* - * Don't input to tanks from the sides where the pipe is extraction mode. This - * prevents feed-back loops. - */ - if (connectionMap.get(handler).canFlow()) - { - stack.amount -= handler.fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, this.maxFlowRate)), true); - } + /* + * Don't input to tanks from the sides where the pipe is extraction mode. This + * prevents feed-back loops. + */ + if (connectionMap.get(handler).canFlow()) + { + stack.amount -= handler.fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, this.maxFlowRate)), true); + } - if (sideCount > 1) - --sideCount; - if (volPer <= 0) - break; - } + if (sideCount > 1) + --sideCount; + if (volPer <= 0) + break; + } - if (count > 1) - count--; + if (count > 1) + count--; - if (stack == null || stack.amount <= 0) - { - stack = null; - break; - } - } + if (stack == null || stack.amount <= 0) + { + stack = null; + break; + } + } - this.getTank().setFluid(stack); - // TODO check for change before rebuilding - this.reconstructTankInfo(); - } + this.getTank().setFluid(stack); + // TODO check for change before rebuilding + this.reconstructTankInfo(); + } - @Override - public boolean canUpdate() - { - return getTank().getFluidAmount() > 0 && sideMap.size() > 0 && getConnectors().size() > 0; - } + @Override + public boolean canUpdate() + { + return getTank().getFluidAmount() > 0 && sideMap.size() > 0 && getConnectors().size() > 0; + } - @Override - public boolean continueUpdate() - { - return canUpdate(); - } + @Override + public boolean continueUpdate() + { + return canUpdate(); + } - @Override - public void reconstruct() - { - this.sideMap.clear(); - this.maxFlowRate = Integer.MAX_VALUE; - this.maxPressure = Integer.MAX_VALUE; - super.reconstruct(); - } + @Override + public void reconstruct() + { + this.sideMap.clear(); + this.maxFlowRate = Integer.MAX_VALUE; + this.maxPressure = Integer.MAX_VALUE; + super.reconstruct(); + } - @Override - public void reconstructConnector(IFluidConnector connector) - { - super.reconstructConnector(connector); + @Override + public void reconstructConnector(IFluidConnector connector) + { + super.reconstructConnector(connector); - if (connector instanceof IFluidPipe) - { - if (((IFluidPipe) connector).getMaxFlowRate() < this.maxFlowRate) - this.maxFlowRate = ((IFluidPipe) connector).getMaxFlowRate(); + if (connector instanceof IFluidPipe) + { + if (((IFluidPipe) connector).getMaxFlowRate() < this.maxFlowRate) + this.maxFlowRate = ((IFluidPipe) connector).getMaxFlowRate(); - if (((IFluidPipe) connector).getMaxPressure() < this.maxPressure) - this.maxPressure = ((IFluidPipe) connector).getMaxPressure(); - } - for (int i = 0; i < 6; i++) - { - if (connector.getConnections()[i] instanceof IFluidHandler && !(connector.getConnections()[i] instanceof IFluidPipe)) - { - EnumSet set = this.sideMap.get(connector.getConnections()[i]); - if (set == null) - { - set = EnumSet.noneOf(ForgeDirection.class); - } + if (((IFluidPipe) connector).getMaxPressure() < this.maxPressure) + this.maxPressure = ((IFluidPipe) connector).getMaxPressure(); + } + for (int i = 0; i < 6; i++) + { + if (connector.getConnections()[i] instanceof IFluidHandler && !(connector.getConnections()[i] instanceof IFluidPipe)) + { + EnumSet set = this.sideMap.get(connector.getConnections()[i]); + if (set == null) + { + set = EnumSet.noneOf(ForgeDirection.class); + } - set.add(ForgeDirection.getOrientation(i).getOpposite()); - sideMap.put((IFluidHandler) connector.getConnections()[i], set); - connectionMap.put((IFluidHandler) connector.getConnections()[i], connector); - } - } - } + set.add(ForgeDirection.getOrientation(i).getOpposite()); + sideMap.put((IFluidHandler) connector.getConnections()[i], set); + connectionMap.put((IFluidHandler) connector.getConnections()[i], connector); + } + } + } - @Override - public FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain) - { - return null; - } + @Override + public FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain) + { + return null; + } - @Override - public FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain) - { - return null; - } + @Override + public FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain) + { + return null; + } - @Override - public Class getConnectorClass() - { - return IFluidPipe.class; - } + @Override + public Class getConnectorClass() + { + return IFluidPipe.class; + } - @Override - public IFluidNetwork newInstance() - { - return new PipeNetwork(); - } + @Override + public IFluidNetwork newInstance() + { + return new PipeNetwork(); + } + + @Override + public int getPressure() + { + return this.currentPressure; + } } diff --git a/src/main/java/resonantinduction/mechanical/fluid/pipe/PartPipe.java b/src/main/java/resonantinduction/mechanical/fluid/pipe/PartPipe.java index b6577a56..0cb94023 100644 --- a/src/main/java/resonantinduction/mechanical/fluid/pipe/PartPipe.java +++ b/src/main/java/resonantinduction/mechanical/fluid/pipe/PartPipe.java @@ -27,202 +27,210 @@ import cpw.mods.fml.relauncher.SideOnly; public class PartPipe extends PartFramedConnection implements IFluidPipe, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects { - protected FluidTank tank = new FluidTank(1 * FluidContainerRegistry.BUCKET_VOLUME); - private boolean isExtracting = false; + protected FluidTank tank = new FluidTank(1 * FluidContainerRegistry.BUCKET_VOLUME); + private boolean isExtracting = false; - public PartPipe() - { - super(); - material = EnumPipeMaterial.COPPER; - } + public PartPipe() + { + super(); + material = EnumPipeMaterial.COPPER; + } - public PartPipe(int typeID) - { - material = EnumPipeMaterial.values()[typeID]; - } + public PartPipe(int typeID) + { + material = EnumPipeMaterial.values()[typeID]; + } - @Override - public String getType() - { - return "resonant_induction_pipe"; - } + @Override + public String getType() + { + return "resonant_induction_pipe"; + } - @Override - public void update() - { - if (!world().isRemote) - { - if (isExtracting && getNetwork().getTank().getFluidAmount() < getNetwork().getTank().getCapacity()) - { - for (int i = 0; i < this.getConnections().length; i++) - { - Object obj = this.getConnections()[i]; + @Override + public void update() + { + if (!world().isRemote) + { + if (isExtracting && getNetwork().getTank().getFluidAmount() < getNetwork().getTank().getCapacity()) + { + for (int i = 0; i < this.getConnections().length; i++) + { + Object obj = this.getConnections()[i]; - if (obj instanceof IFluidHandler) - { - FluidStack drain = ((IFluidHandler) obj).drain(ForgeDirection.getOrientation(i).getOpposite(), getMaxFlowRate(), true); - fill(null, drain, true); - } - } - } - } - } + if (obj instanceof IFluidHandler) + { + FluidStack drain = ((IFluidHandler) obj).drain(ForgeDirection.getOrientation(i).getOpposite(), getMaxFlowRate(), true); + fill(null, drain, true); + } + } + } + } + } - @Override - public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) - { - if (BlockAdvanced.isUsableWrench(player, player.getCurrentEquippedItem(), x(), y(), z())) - { - if (!world().isRemote) - { - isExtracting = !isExtracting; - player.addChatMessage("Pipe extraction mode: " + isExtracting); - BlockAdvanced.damageWrench(player, player.getCurrentEquippedItem(), x(), y(), z()); - } - return true; - } + @Override + public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) + { + if (BlockAdvanced.isUsableWrench(player, player.getCurrentEquippedItem(), x(), y(), z())) + { + if (!world().isRemote) + { + isExtracting = !isExtracting; + player.addChatMessage("Pipe extraction mode: " + isExtracting); + BlockAdvanced.damageWrench(player, player.getCurrentEquippedItem(), x(), y(), z()); + } + return true; + } - return super.activate(player, part, item); - } + return super.activate(player, part, item); + } - @Override - @SideOnly(Side.CLIENT) - public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass) - { - RenderPipe.INSTANCE.render(this, pos.x, pos.y, pos.z, frame); - } + @Override + @SideOnly(Side.CLIENT) + public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass) + { + RenderPipe.INSTANCE.render(this, pos.x, pos.y, pos.z, frame); + } - @Override - public void setMaterial(int i) - { - setMaterial(EnumPipeMaterial.values()[i]); - } + @Override + public void setMaterial(int i) + { + setMaterial(EnumPipeMaterial.values()[i]); + } - @Override - protected ItemStack getItem() - { - return new ItemStack(Mechanical.itemPipe); - } + @Override + protected ItemStack getItem() + { + return new ItemStack(Mechanical.itemPipe); + } - /** - * Fluid network methods. - */ - @Override - public IFluidNetwork getNetwork() - { - if (this.network == null) - { - this.network = new PipeNetwork(); - this.network.addConnector(this); - } - return this.network; - } + /** Fluid network methods. */ + @Override + public IFluidNetwork getNetwork() + { + if (this.network == null) + { + this.network = new PipeNetwork(); + this.network.addConnector(this); + } + return this.network; + } - @Override - public int fill(ForgeDirection from, FluidStack resource, boolean doFill) - { - return getNetwork().fill(this, from, resource, doFill); - } + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) + { + return getNetwork().fill(this, from, resource, doFill); + } - @Override - public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) - { - return null; - } + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) + { + return null; + } - @Override - public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) - { - return null; - } + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { + return null; + } - @Override - public boolean canFill(ForgeDirection from, Fluid fluid) - { - return true; - } + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) + { + return true; + } - @Override - public boolean canDrain(ForgeDirection from, Fluid fluid) - { - return true; - } + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) + { + return true; + } - @Override - public FluidTankInfo[] getTankInfo(ForgeDirection from) - { - return this.getNetwork().getTankInfo(); - } + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) + { + return this.getNetwork().getTankInfo(); + } - @Override - public void onFluidChanged() - { - } + @Override + public void onFluidChanged() + { + } - @Override - public FluidTank getInternalTank() - { - if (this.tank == null) - { - this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME); - } - return this.tank; - } + @Override + public FluidTank getInternalTank() + { + if (this.tank == null) + { + this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME); + } + return this.tank; + } - @Override - protected boolean canConnectTo(TileEntity tile) - { - return tile instanceof IFluidHandler; - } + @Override + protected boolean canConnectTo(TileEntity tile) + { + return tile instanceof IFluidHandler; + } - @Override - protected IFluidPipe getConnector(TileEntity tile) - { - return tile instanceof IFluidPipe ? (IFluidPipe) tile : null; - } + @Override + protected IFluidPipe getConnector(TileEntity tile) + { + return tile instanceof IFluidPipe ? (IFluidPipe) tile : null; + } - @Override - public int getPressureIn(ForgeDirection side) - { - return 0; - } + @Override + public int getPressureIn(ForgeDirection side) + { + return 0; + } - @Override - public void onWrongPressure(ForgeDirection side, int pressure) - { + @Override + public int getPressure() + { + if(this.getNetwork() != null) + { + return this.getNetwork().getPressure(); + } + return 0; + } - } + @Override + public void onWrongPressure(ForgeDirection side, int pressure) + { - @Override - public int getMaxPressure() - { - return 1000; - } + } - @Override - public int getMaxFlowRate() - { - return FluidContainerRegistry.BUCKET_VOLUME; - } + @Override + public int getMaxPressure() + { + return 1000; + } - @Override - public void save(NBTTagCompound nbt) - { - super.save(nbt); - nbt.setBoolean("isExtracting", isExtracting); - } + @Override + public int getMaxFlowRate() + { + return FluidContainerRegistry.BUCKET_VOLUME; + } - @Override - public void load(NBTTagCompound nbt) - { - super.load(nbt); - isExtracting = nbt.getBoolean("isExtracting"); - } + @Override + public void save(NBTTagCompound nbt) + { + super.save(nbt); + nbt.setBoolean("isExtracting", isExtracting); + } - @Override - public boolean canFlow() - { - return !isExtracting; - } + @Override + public void load(NBTTagCompound nbt) + { + super.load(nbt); + isExtracting = nbt.getBoolean("isExtracting"); + } + + @Override + public boolean canFlow() + { + return !isExtracting; + } } \ No newline at end of file diff --git a/src/main/java/resonantinduction/mechanical/fluid/tank/TankNetwork.java b/src/main/java/resonantinduction/mechanical/fluid/tank/TankNetwork.java index 41ceaa26..47191b69 100644 --- a/src/main/java/resonantinduction/mechanical/fluid/tank/TankNetwork.java +++ b/src/main/java/resonantinduction/mechanical/fluid/tank/TankNetwork.java @@ -9,71 +9,76 @@ import resonantinduction.api.fluid.IFluidConnector; import resonantinduction.api.fluid.IFluidNetwork; import resonantinduction.mechanical.fluid.network.FluidNetwork; -/** - * Network that handles connected tanks +/** Network that handles connected tanks * - * @author DarkGuardsman - */ + * @author DarkGuardsman */ public class TankNetwork extends FluidNetwork { - @Override - public void distributeConnectors() - { - FluidStack fillStack = this.getTank().getFluid(); - int lowestY = 255, highestY = 0; + @Override + public void distributeConnectors() + { + FluidStack fillStack = this.getTank().getFluid(); + int lowestY = 255, highestY = 0; - if (fillStack == null || fillStack.getFluid().isGaseous()) - { - super.distributeConnectors(); - } - else if (this.getConnectors().size() > 0) - { - fillStack = fillStack.copy(); + if (fillStack == null || fillStack.getFluid().isGaseous()) + { + super.distributeConnectors(); + } + else if (this.getConnectors().size() > 0) + { + fillStack = fillStack.copy(); - for (IFluidConnector connector : this.getConnectors()) - { - connector.getInternalTank().setFluid(null); - connector.onFluidChanged(); + for (IFluidConnector connector : this.getConnectors()) + { + connector.getInternalTank().setFluid(null); + connector.onFluidChanged(); - if (connector instanceof TileEntity && ((TileEntity) connector).yCoord < lowestY) - { - lowestY = ((TileEntity) connector).yCoord; - } - if (connector instanceof TileEntity && ((TileEntity) connector).yCoord > highestY) - { - highestY = ((TileEntity) connector).yCoord; - } - } + if (connector instanceof TileEntity && ((TileEntity) connector).yCoord < lowestY) + { + lowestY = ((TileEntity) connector).yCoord; + } + if (connector instanceof TileEntity && ((TileEntity) connector).yCoord > highestY) + { + highestY = ((TileEntity) connector).yCoord; + } + } - // TODO Add path finder to prevent filling when tanks are only connected at the top - for (int y = lowestY; y <= highestY; y++) - { - Set parts = new LinkedHashSet(); + // TODO Add path finder to prevent filling when tanks are only connected at the top + for (int y = lowestY; y <= highestY; y++) + { + Set parts = new LinkedHashSet(); - for (IFluidConnector part : this.getConnectors()) - { - if (part instanceof IFluidConnector && ((TileEntity) part).yCoord == y) - { - parts.add(part); - } - } - if (!parts.isEmpty()) - { - this.fillTankSet(fillStack, parts); - } + for (IFluidConnector part : this.getConnectors()) + { + if (part instanceof IFluidConnector && ((TileEntity) part).yCoord == y) + { + parts.add(part); + } + } + if (!parts.isEmpty()) + { + this.fillTankSet(fillStack, parts); + } - if (fillStack == null || fillStack.amount <= 0) - { - break; - } - } - } - } + if (fillStack == null || fillStack.amount <= 0) + { + break; + } + } + } + } - @Override - public IFluidNetwork newInstance() - { - return new TankNetwork(); - } + @Override + public IFluidNetwork newInstance() + { + return new TankNetwork(); + } + + @Override + public int getPressure() + { + //TODO implement a compression system that would cause a tank to build up pressure greater than normal ATM + return 0; + } } diff --git a/src/main/java/resonantinduction/mechanical/motor/BlockFluidMotor.java b/src/main/java/resonantinduction/mechanical/motor/BlockFluidMotor.java new file mode 100644 index 00000000..af88f752 --- /dev/null +++ b/src/main/java/resonantinduction/mechanical/motor/BlockFluidMotor.java @@ -0,0 +1,83 @@ +package resonantinduction.mechanical.motor; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import resonantinduction.core.Reference; +import resonantinduction.core.prefab.block.BlockRIRotatable; +import resonantinduction.core.render.RIBlockRenderingHandler; +import resonantinduction.electrical.generator.TileGenerator; + +public class BlockFluidMotor extends BlockRIRotatable +{ + public BlockFluidMotor() + { + super("FluidMotor"); + setTextureName(Reference.PREFIX + "material_steel"); + rotationMask = Byte.parseByte("111111", 2); + } + + @Override + public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileGenerator) + { + if (!world.isRemote) + { + ((TileGenerator) tileEntity).isInversed = !((TileGenerator) tileEntity).isInversed; + entityPlayer.addChatMessage("Generator now producing " + (((TileGenerator) tileEntity).isInversed ? "mechanical" : "electrical") + " energy."); + } + + return true; + } + + return false; + } + + @Override + public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileGenerator) + { + if (!world.isRemote) + { + entityPlayer.addChatMessage("Generator torque ratio: " + ((TileGenerator) tileEntity).toggleRatio()); + } + + return true; + } + return false; + } + + @Override + public TileEntity createNewTileEntity(World world) + { + return new TileGenerator(); + } + + @Override + public boolean isOpaqueCube() + { + return false; + } + + @Override + public boolean renderAsNormalBlock() + { + return false; + } + + @SideOnly(Side.CLIENT) + @Override + public int getRenderType() + { + return RIBlockRenderingHandler.ID; + } + +} diff --git a/src/main/java/resonantinduction/mechanical/motor/TileFluidMotor.java b/src/main/java/resonantinduction/mechanical/motor/TileFluidMotor.java new file mode 100644 index 00000000..446e7682 --- /dev/null +++ b/src/main/java/resonantinduction/mechanical/motor/TileFluidMotor.java @@ -0,0 +1,103 @@ +package resonantinduction.mechanical.motor; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; +import resonantinduction.api.fluid.IFluidPipe; +import universalelectricity.api.vector.Vector3; +import calclavia.lib.prefab.tile.IRotatable; +import calclavia.lib.prefab.tile.TileAdvanced; + +public class TileFluidMotor extends TileAdvanced implements IFluidHandler, IRotatable +{ + ForgeDirection facing = ForgeDirection.UNKNOWN; + boolean input = true; + final int maxFlow = 1000; + int volFilled = 0; + int averageVol = 0; + + @Override + public void updateEntity() + { + super.updateEntity(); + } + + @Override + public int fill(ForgeDirection from, FluidStack resource, boolean doFill) + { + if (from == getDirection().getOpposite()) + { + TileEntity tileOut = new Vector3(this).translate(from.getOpposite()).getTileEntity(this.worldObj); + TileEntity tileIn = new Vector3(this).translate(from).getTileEntity(this.worldObj); + if (tileIn instanceof IFluidPipe && tileOut instanceof IFluidPipe) + { + if (((IFluidPipe) tileIn).getPressure() <= ((IFluidPipe) tileOut).getPressure()) + { + return 0; + } + } + if (tileOut instanceof IFluidHandler && !(tileOut instanceof TileFluidMotor)) + { + //TODO pass fluid on to the other side of the motor and get average flow rate + } + } + return 0; + } + + @Override + public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) + { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean canFill(ForgeDirection from, Fluid fluid) + { + return !input && from == this.getDirection().getOpposite(); + } + + @Override + public boolean canDrain(ForgeDirection from, Fluid fluid) + { + // TODO Auto-generated method stub + return false; + } + + @Override + public FluidTankInfo[] getTankInfo(ForgeDirection from) + { + if (from == getDirection().getOpposite()) + { + TileEntity tile = new Vector3(this).translate(from.getOpposite()).getTileEntity(this.worldObj); + if (tile instanceof IFluidHandler && !(tile instanceof TileFluidMotor)) + { + return ((IFluidHandler) tile).getTankInfo(from); + } + } + return new FluidTankInfo[1]; + } + + @Override + public ForgeDirection getDirection() + { + return ForgeDirection.getOrientation(this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); + } + + @Override + public void setDirection(ForgeDirection direction) + { + this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), 3); + } + +}