From afb718af8a2a196b4f35a8fcfb13b21b6a437027 Mon Sep 17 00:00:00 2001 From: Robert S Date: Sat, 27 Sep 2014 14:58:24 -0400 Subject: [PATCH] Converted pump to scala, and externalized PumpNode as its own class --- .../mechanical/fluid/transport/PumpNode.scala | 34 ++++ .../mechanical/fluid/transport/TilePump.java | 157 ------------------ .../mechanical/fluid/transport/TilePump.scala | 102 ++++++++++++ 3 files changed, 136 insertions(+), 157 deletions(-) create mode 100644 src/main/scala/resonantinduction/mechanical/fluid/transport/PumpNode.scala delete mode 100644 src/main/scala/resonantinduction/mechanical/fluid/transport/TilePump.java create mode 100644 src/main/scala/resonantinduction/mechanical/fluid/transport/TilePump.scala diff --git a/src/main/scala/resonantinduction/mechanical/fluid/transport/PumpNode.scala b/src/main/scala/resonantinduction/mechanical/fluid/transport/PumpNode.scala new file mode 100644 index 000000000..bff1d2799 --- /dev/null +++ b/src/main/scala/resonantinduction/mechanical/fluid/transport/PumpNode.scala @@ -0,0 +1,34 @@ +package resonantinduction.mechanical.fluid.transport + +import net.minecraftforge.common.util.ForgeDirection +import resonantinduction.core.prefab.node.NodePressure +import universalelectricity.api.core.grid.INodeProvider + +/** + * Created by robert on 9/27/2014. + */ +class PumpNode(parent: INodeProvider) extends NodePressure(parent) +{ + def pump : TilePump = getParent.asInstanceOf[TilePump] + + override def getPressure(dir: ForgeDirection): Int = + { + if (pump.mechanicalNode.getPower > 0) + { + if (dir == pump.getDirection) + { + return Math.max(Math.abs(pump.mechanicalNode.getForce(ForgeDirection.UNKNOWN) / 8000d), 2).asInstanceOf[Int] + } + else if (dir == pump.getDirection.getOpposite) + { + return -Math.max(Math.abs(pump.mechanicalNode.getForce(ForgeDirection.UNKNOWN) / 8000d), 2).asInstanceOf[Int] + } + } + return 0 + } + + override def canConnect(from: ForgeDirection, source: AnyRef): Boolean = + { + return super.canConnect(from, source) && (from == pump.getDirection || from == pump.getDirection.getOpposite) + } +} diff --git a/src/main/scala/resonantinduction/mechanical/fluid/transport/TilePump.java b/src/main/scala/resonantinduction/mechanical/fluid/transport/TilePump.java deleted file mode 100644 index abd0a3b8c..000000000 --- a/src/main/scala/resonantinduction/mechanical/fluid/transport/TilePump.java +++ /dev/null @@ -1,157 +0,0 @@ -package resonantinduction.mechanical.fluid.transport; - -import net.minecraft.block.material.Material; -import resonantinduction.core.prefab.node.NodePressure; -import resonantinduction.mechanical.mech.TileMechanical; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidHandler; -import resonant.api.IRotatable; -import universalelectricity.api.core.grid.INode; -import universalelectricity.core.transform.vector.Vector3; - -public class TilePump extends TileMechanical implements IRotatable, IFluidHandler -{ - private final NodePressure pressureNode; - - public TilePump() - { - super(Material.iron); - - normalRender(false); - isOpaqueCube(false); - customItemRender(true); - setTextureName("material_steel"); - pressureNode = new NodePressure(this) - { - @Override - public int getPressure(ForgeDirection dir) - { - if (mechanicalNode.getPower() > 0) - { - if (dir == getDirection()) - { - return (int) Math.max(Math.abs(mechanicalNode.getForce(ForgeDirection.UNKNOWN) / 8000d), 2); - } - else if (dir == getDirection().getOpposite()) - { - return (int) -Math.max(Math.abs(mechanicalNode.getForce(ForgeDirection.UNKNOWN) / 8000d), 2); - } - } - - return 0; - } - - @Override - public boolean canConnect(ForgeDirection from, Object source) - { - return super.canConnect(from, source) && (from == getDirection() || from == getDirection().getOpposite()); - } - - }; - } - - @Override - public void start() - { - pressureNode.reconstruct(); - super.start(); - } - - @Override - public void invalidate() - { - super.invalidate(); - pressureNode.deconstruct(); - } - - @Override - public void update() - { - super.update(); - - if (!worldObj.isRemote && mechanicalNode.getPower() > 0) - { - /** - * Try to suck fluid in - */ - TileEntity tileIn = new Vector3(this).add(getDirection().getOpposite()).getTileEntity(this.worldObj); - - if (tileIn instanceof IFluidHandler) - { - FluidStack drain = ((IFluidHandler) tileIn).drain(getDirection(), pressureNode.getCapacity(), false); - - if (drain != null) - { - ((IFluidHandler) tileIn).drain(getDirection(), fill(getDirection().getOpposite(), drain, true), true); - } - } - } - } - - @Override - public int fill(ForgeDirection from, FluidStack resource, boolean doFill) - { - if (from == getDirection().getOpposite()) - { - TileEntity tileOut = new Vector3(this).add(from.getOpposite()).getTileEntity(this.worldObj); - - if (tileOut instanceof IFluidHandler) - return ((IFluidHandler) tileOut).fill(from, resource, doFill); - } - - return 0; - } - - @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 boolean canFill(ForgeDirection from, Fluid fluid) - { - return from == this.getDirection().getOpposite(); - } - - @Override - public boolean canDrain(ForgeDirection from, Fluid fluid) - { - return from == this.getDirection(); - } - - @Override - public FluidTankInfo[] getTankInfo(ForgeDirection from) - { - return null; - } - - @Override - public INode getNode(Class nodeType, ForgeDirection from) - { - if (nodeType.isAssignableFrom(pressureNode.getClass())) - return pressureNode; - - return super.getNode(nodeType, from); - } - - @Override - public ForgeDirection getDirection() { - return null; - } - - @Override - public void setDirection(ForgeDirection direction) { - - } -} diff --git a/src/main/scala/resonantinduction/mechanical/fluid/transport/TilePump.scala b/src/main/scala/resonantinduction/mechanical/fluid/transport/TilePump.scala new file mode 100644 index 000000000..47c7916ac --- /dev/null +++ b/src/main/scala/resonantinduction/mechanical/fluid/transport/TilePump.scala @@ -0,0 +1,102 @@ +package resonantinduction.mechanical.fluid.transport + +import net.minecraft.block.material.Material +import net.minecraft.tileentity.TileEntity +import net.minecraftforge.common.util.ForgeDirection +import net.minecraftforge.fluids.{Fluid, FluidStack, FluidTankInfo, IFluidHandler} +import resonant.api.IRotatable +import resonantinduction.mechanical.mech.TileMechanical +import universalelectricity.api.core.grid.INode +import universalelectricity.core.transform.vector.Vector3 + +class TilePump extends TileMechanical(Material.iron) with IRotatable with IFluidHandler +{ + var pressureNode : PumpNode = null + + //Constructor + normalRender(false) + isOpaqueCube(false) + customItemRender(true) + setTextureName("material_steel") + pressureNode = new PumpNode(this) + + + override def start + { + pressureNode.reconstruct + super.start + } + + override def invalidate + { + super.invalidate + pressureNode.deconstruct + } + + override def update + { + super.update + if (!worldObj.isRemote && mechanicalNode.getPower > 0) + { + val tileIn: TileEntity = new Vector3(this).add(getDirection.getOpposite).getTileEntity(this.worldObj) + if (tileIn.isInstanceOf[IFluidHandler]) + { + val drain: FluidStack = (tileIn.asInstanceOf[IFluidHandler]).drain(getDirection, pressureNode.getCapacity, false) + if (drain != null) + { + (tileIn.asInstanceOf[IFluidHandler]).drain(getDirection, fill(getDirection.getOpposite, drain, true), true) + } + } + } + } + + def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int = + { + if (from eq getDirection.getOpposite) + { + val tileOut: TileEntity = new Vector3(this).add(from.getOpposite).getTileEntity(this.worldObj) + if (tileOut.isInstanceOf[IFluidHandler]) return (tileOut.asInstanceOf[IFluidHandler]).fill(from, resource, doFill) + } + return 0 + } + + def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack = + { + return null + } + + def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack = + { + return null + } + + def canFill(from: ForgeDirection, fluid: Fluid): Boolean = + { + return from eq this.getDirection.getOpposite + } + + def canDrain(from: ForgeDirection, fluid: Fluid): Boolean = + { + return from eq this.getDirection + } + + def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] = + { + return null + } + + override def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode = + { + if (nodeType.isAssignableFrom(pressureNode.getClass)) return pressureNode + return super.getNode(nodeType, from) + } + + override def getDirection: ForgeDirection = + { + return null + } + + override def setDirection(direction: ForgeDirection) + { + } +} \ No newline at end of file