Started on fluid motor, and hydraulic pressure

This commit is contained in:
DarkGuardsman 2014-01-28 17:11:46 -05:00
parent a15ed12159
commit 67a4f21dec
7 changed files with 582 additions and 381 deletions

View file

@ -7,48 +7,40 @@ import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler; import net.minecraftforge.fluids.IFluidHandler;
import universalelectricity.api.net.INodeNetwork; 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<IFluidNetwork, IFluidConnector, IFluidHandler> public interface IFluidNetwork extends INodeNetwork<IFluidNetwork, IFluidConnector, IFluidHandler>
{ {
/** Called to build the network when something changes such as addition of a pipe */ /** Called to build the network when something changes such as addition of a pipe */
@Override @Override
void reconstruct(); void reconstruct();
/** /** Called to add fluid into the network
* Called to add fluid into the network
* *
* @param source - part that is receiving the fluid for the network * @param source - part that is receiving the fluid for the network
* @param from - direction of this connection * @param from - direction of this connection
* @param resource - fluid stack that is being filled into the network * @param resource - fluid stack that is being filled into the network
* @param doFill - true causes the action to be taken, false simulates the action * @param doFill - true causes the action to be taken, false simulates the action
* @return amount of fluid filled into the network * @return amount of fluid filled into the network */
*/
int fill(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doFill); int fill(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doFill);
/** /** Called to remove fluid from a network, not supported by all networks
* Called to remove fluid from a network, not supported by all networks
* *
* @param source - part that is receiving the fluid for the network * @param source - part that is receiving the fluid for the network
* @param from - direction of this connection * @param from - direction of this connection
* @param resource - fluid stack that is being filled into the network * @param resource - fluid stack that is being filled into the network
* @param doDrain - true causes the action to be taken, false simulates the action * @param doDrain - true causes the action to be taken, false simulates the action
* @return FluidStack that contains the fluid drained from the network * @return FluidStack that contains the fluid drained from the network */
*/
FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain); FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain);
/** /** Called to remove fluid from a network, not supported by all networks
* Called to remove fluid from a network, not supported by all networks
* *
* @param source - part that is receiving the fluid for the network * @param source - part that is receiving the fluid for the network
* @param from - direction of this connection * @param from - direction of this connection
* @param resource - fluid stack that is being filled into the network * @param resource - fluid stack that is being filled into the network
* @param doDrain - true causes the action to be taken, false simulates the action * @param doDrain - true causes the action to be taken, false simulates the action
* @return FluidStack that contains the fluid drained from the network * @return FluidStack that contains the fluid drained from the network */
*/
FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain); FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain);
/** Fluid tank that represents the entire network */ /** Fluid tank that represents the entire network */
@ -57,4 +49,6 @@ public interface IFluidNetwork extends INodeNetwork<IFluidNetwork, IFluidConnect
/** Information about the network's tank */ /** Information about the network's tank */
FluidTankInfo[] getTankInfo(); FluidTankInfo[] getTankInfo();
int getPressure();
} }

View file

@ -14,6 +14,8 @@ public interface IFluidPipe extends IFluidConnector, IPressureInput
*/ */
int getMaxPressure(); int getMaxPressure();
int getPressure();
/** /**
* Max flow rate of fluid this pipe can support * Max flow rate of fluid this pipe can support
* *

View file

@ -13,17 +13,17 @@ import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.api.fluid.IFluidPipe; import resonantinduction.api.fluid.IFluidPipe;
import calclavia.lib.utility.FluidUtility; 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 class PipeNetwork extends FluidNetwork
{ {
public HashMap<IFluidHandler, EnumSet<ForgeDirection>> sideMap = new HashMap<IFluidHandler, EnumSet<ForgeDirection>>(); public HashMap<IFluidHandler, EnumSet<ForgeDirection>> sideMap = new HashMap<IFluidHandler, EnumSet<ForgeDirection>>();
public HashMap<IFluidHandler, IFluidConnector> connectionMap = new HashMap<IFluidHandler, IFluidConnector>(); public HashMap<IFluidHandler, IFluidConnector> connectionMap = new HashMap<IFluidHandler, IFluidConnector>();
public int maxFlowRate = 0; public int maxFlowRate = 0;
public int maxPressure = 0; public int maxPressure = 0;
public int currentPressure = 0;
public int currentFlowRate = 0;
@Override @Override
public void update() public void update()
@ -152,4 +152,10 @@ public class PipeNetwork extends FluidNetwork
{ {
return new PipeNetwork(); return new PipeNetwork();
} }
@Override
public int getPressure()
{
return this.currentPressure;
}
} }

View file

@ -104,9 +104,7 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IFluidPipe,
return new ItemStack(Mechanical.itemPipe); return new ItemStack(Mechanical.itemPipe);
} }
/** /** Fluid network methods. */
* Fluid network methods.
*/
@Override @Override
public IFluidNetwork getNetwork() public IFluidNetwork getNetwork()
{ {
@ -187,6 +185,16 @@ public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IFluidPipe,
return 0; return 0;
} }
@Override
public int getPressure()
{
if(this.getNetwork() != null)
{
return this.getNetwork().getPressure();
}
return 0;
}
@Override @Override
public void onWrongPressure(ForgeDirection side, int pressure) public void onWrongPressure(ForgeDirection side, int pressure)
{ {

View file

@ -9,11 +9,9 @@ import resonantinduction.api.fluid.IFluidConnector;
import resonantinduction.api.fluid.IFluidNetwork; import resonantinduction.api.fluid.IFluidNetwork;
import resonantinduction.mechanical.fluid.network.FluidNetwork; 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 public class TankNetwork extends FluidNetwork
{ {
@Override @Override
@ -76,4 +74,11 @@ public class TankNetwork extends FluidNetwork
return new TankNetwork(); 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;
}
} }

View file

@ -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;
}
}

View file

@ -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);
}
}