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,54 +7,48 @@ 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 */
FluidTank getTank(); FluidTank getTank();
/** Information about the network's tank */ /** Information about the network's tank */
FluidTankInfo[] getTankInfo(); FluidTankInfo[] getTankInfo();
int getPressure();
} }

View file

@ -13,6 +13,8 @@ public interface IFluidPipe extends IFluidConnector, IPressureInput
* @return amount in pascals. * @return amount in pascals.
*/ */
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,143 +13,149 @@ 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()
{ {
/* /*
* Slight delay to allow visual effect to take place before draining the pipe's internal * Slight delay to allow visual effect to take place before draining the pipe's internal
* tank * tank
*/ */
FluidStack stack = this.getTank().getFluid().copy(); FluidStack stack = this.getTank().getFluid().copy();
int count = this.sideMap.size(); int count = this.sideMap.size();
Iterator<Entry<IFluidHandler, EnumSet<ForgeDirection>>> it = new HashMap<IFluidHandler, EnumSet<ForgeDirection>>(sideMap).entrySet().iterator(); Iterator<Entry<IFluidHandler, EnumSet<ForgeDirection>>> it = new HashMap<IFluidHandler, EnumSet<ForgeDirection>>(sideMap).entrySet().iterator();
while (it.hasNext()) while (it.hasNext())
{ {
Entry<IFluidHandler, EnumSet<ForgeDirection>> entry = it.next(); Entry<IFluidHandler, EnumSet<ForgeDirection>> entry = it.next();
int sideCount = entry.getValue().size(); int sideCount = entry.getValue().size();
for (ForgeDirection dir : entry.getValue()) for (ForgeDirection dir : entry.getValue())
{ {
int volPer = (stack.amount / count); int volPer = (stack.amount / count);
int volPerSide = (volPer / sideCount); int volPerSide = (volPer / sideCount);
IFluidHandler handler = entry.getKey(); IFluidHandler handler = entry.getKey();
/* /*
* Don't input to tanks from the sides where the pipe is extraction mode. This * Don't input to tanks from the sides where the pipe is extraction mode. This
* prevents feed-back loops. * prevents feed-back loops.
*/ */
if (connectionMap.get(handler).canFlow()) if (connectionMap.get(handler).canFlow())
{ {
stack.amount -= handler.fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, this.maxFlowRate)), true); stack.amount -= handler.fill(dir, FluidUtility.getStack(stack, Math.min(volPerSide, this.maxFlowRate)), true);
} }
if (sideCount > 1) if (sideCount > 1)
--sideCount; --sideCount;
if (volPer <= 0) if (volPer <= 0)
break; break;
} }
if (count > 1) if (count > 1)
count--; count--;
if (stack == null || stack.amount <= 0) if (stack == null || stack.amount <= 0)
{ {
stack = null; stack = null;
break; break;
} }
} }
this.getTank().setFluid(stack); this.getTank().setFluid(stack);
// TODO check for change before rebuilding // TODO check for change before rebuilding
this.reconstructTankInfo(); this.reconstructTankInfo();
} }
@Override @Override
public boolean canUpdate() public boolean canUpdate()
{ {
return getTank().getFluidAmount() > 0 && sideMap.size() > 0 && getConnectors().size() > 0; return getTank().getFluidAmount() > 0 && sideMap.size() > 0 && getConnectors().size() > 0;
} }
@Override @Override
public boolean continueUpdate() public boolean continueUpdate()
{ {
return canUpdate(); return canUpdate();
} }
@Override @Override
public void reconstruct() public void reconstruct()
{ {
this.sideMap.clear(); this.sideMap.clear();
this.maxFlowRate = Integer.MAX_VALUE; this.maxFlowRate = Integer.MAX_VALUE;
this.maxPressure = Integer.MAX_VALUE; this.maxPressure = Integer.MAX_VALUE;
super.reconstruct(); super.reconstruct();
} }
@Override @Override
public void reconstructConnector(IFluidConnector connector) public void reconstructConnector(IFluidConnector connector)
{ {
super.reconstructConnector(connector); super.reconstructConnector(connector);
if (connector instanceof IFluidPipe) if (connector instanceof IFluidPipe)
{ {
if (((IFluidPipe) connector).getMaxFlowRate() < this.maxFlowRate) if (((IFluidPipe) connector).getMaxFlowRate() < this.maxFlowRate)
this.maxFlowRate = ((IFluidPipe) connector).getMaxFlowRate(); this.maxFlowRate = ((IFluidPipe) connector).getMaxFlowRate();
if (((IFluidPipe) connector).getMaxPressure() < this.maxPressure) if (((IFluidPipe) connector).getMaxPressure() < this.maxPressure)
this.maxPressure = ((IFluidPipe) connector).getMaxPressure(); this.maxPressure = ((IFluidPipe) connector).getMaxPressure();
} }
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
if (connector.getConnections()[i] instanceof IFluidHandler && !(connector.getConnections()[i] instanceof IFluidPipe)) if (connector.getConnections()[i] instanceof IFluidHandler && !(connector.getConnections()[i] instanceof IFluidPipe))
{ {
EnumSet<ForgeDirection> set = this.sideMap.get(connector.getConnections()[i]); EnumSet<ForgeDirection> set = this.sideMap.get(connector.getConnections()[i]);
if (set == null) if (set == null)
{ {
set = EnumSet.noneOf(ForgeDirection.class); set = EnumSet.noneOf(ForgeDirection.class);
} }
set.add(ForgeDirection.getOrientation(i).getOpposite()); set.add(ForgeDirection.getOrientation(i).getOpposite());
sideMap.put((IFluidHandler) connector.getConnections()[i], set); sideMap.put((IFluidHandler) connector.getConnections()[i], set);
connectionMap.put((IFluidHandler) connector.getConnections()[i], connector); connectionMap.put((IFluidHandler) connector.getConnections()[i], connector);
} }
} }
} }
@Override @Override
public FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain) public FluidStack drain(IFluidConnector source, ForgeDirection from, FluidStack resource, boolean doDrain)
{ {
return null; return null;
} }
@Override @Override
public FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain) public FluidStack drain(IFluidConnector source, ForgeDirection from, int resource, boolean doDrain)
{ {
return null; return null;
} }
@Override @Override
public Class getConnectorClass() public Class getConnectorClass()
{ {
return IFluidPipe.class; return IFluidPipe.class;
} }
@Override @Override
public IFluidNetwork newInstance() public IFluidNetwork newInstance()
{ {
return new PipeNetwork(); return new PipeNetwork();
} }
@Override
public int getPressure()
{
return this.currentPressure;
}
} }

View file

@ -27,202 +27,210 @@ import cpw.mods.fml.relauncher.SideOnly;
public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IFluidPipe, IFluidNetwork> implements IFluidPipe, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects public class PartPipe extends PartFramedConnection<EnumPipeMaterial, IFluidPipe, IFluidNetwork> implements IFluidPipe, TSlottedPart, JNormalOcclusion, IHollowConnect, JIconHitEffects
{ {
protected FluidTank tank = new FluidTank(1 * FluidContainerRegistry.BUCKET_VOLUME); protected FluidTank tank = new FluidTank(1 * FluidContainerRegistry.BUCKET_VOLUME);
private boolean isExtracting = false; private boolean isExtracting = false;
public PartPipe() public PartPipe()
{ {
super(); super();
material = EnumPipeMaterial.COPPER; material = EnumPipeMaterial.COPPER;
} }
public PartPipe(int typeID) public PartPipe(int typeID)
{ {
material = EnumPipeMaterial.values()[typeID]; material = EnumPipeMaterial.values()[typeID];
} }
@Override @Override
public String getType() public String getType()
{ {
return "resonant_induction_pipe"; return "resonant_induction_pipe";
} }
@Override @Override
public void update() public void update()
{ {
if (!world().isRemote) if (!world().isRemote)
{ {
if (isExtracting && getNetwork().getTank().getFluidAmount() < getNetwork().getTank().getCapacity()) if (isExtracting && getNetwork().getTank().getFluidAmount() < getNetwork().getTank().getCapacity())
{ {
for (int i = 0; i < this.getConnections().length; i++) for (int i = 0; i < this.getConnections().length; i++)
{ {
Object obj = this.getConnections()[i]; Object obj = this.getConnections()[i];
if (obj instanceof IFluidHandler) if (obj instanceof IFluidHandler)
{ {
FluidStack drain = ((IFluidHandler) obj).drain(ForgeDirection.getOrientation(i).getOpposite(), getMaxFlowRate(), true); FluidStack drain = ((IFluidHandler) obj).drain(ForgeDirection.getOrientation(i).getOpposite(), getMaxFlowRate(), true);
fill(null, drain, true); fill(null, drain, true);
} }
} }
} }
} }
} }
@Override @Override
public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item) public boolean activate(EntityPlayer player, MovingObjectPosition part, ItemStack item)
{ {
if (BlockAdvanced.isUsableWrench(player, player.getCurrentEquippedItem(), x(), y(), z())) if (BlockAdvanced.isUsableWrench(player, player.getCurrentEquippedItem(), x(), y(), z()))
{ {
if (!world().isRemote) if (!world().isRemote)
{ {
isExtracting = !isExtracting; isExtracting = !isExtracting;
player.addChatMessage("Pipe extraction mode: " + isExtracting); player.addChatMessage("Pipe extraction mode: " + isExtracting);
BlockAdvanced.damageWrench(player, player.getCurrentEquippedItem(), x(), y(), z()); BlockAdvanced.damageWrench(player, player.getCurrentEquippedItem(), x(), y(), z());
} }
return true; return true;
} }
return super.activate(player, part, item); return super.activate(player, part, item);
} }
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass) public void renderDynamic(codechicken.lib.vec.Vector3 pos, float frame, int pass)
{ {
RenderPipe.INSTANCE.render(this, pos.x, pos.y, pos.z, frame); RenderPipe.INSTANCE.render(this, pos.x, pos.y, pos.z, frame);
} }
@Override @Override
public void setMaterial(int i) public void setMaterial(int i)
{ {
setMaterial(EnumPipeMaterial.values()[i]); setMaterial(EnumPipeMaterial.values()[i]);
} }
@Override @Override
protected ItemStack getItem() protected ItemStack getItem()
{ {
return new ItemStack(Mechanical.itemPipe); return new ItemStack(Mechanical.itemPipe);
} }
/** /** Fluid network methods. */
* Fluid network methods. @Override
*/ public IFluidNetwork getNetwork()
@Override {
public IFluidNetwork getNetwork() if (this.network == null)
{ {
if (this.network == null) this.network = new PipeNetwork();
{ this.network.addConnector(this);
this.network = new PipeNetwork(); }
this.network.addConnector(this); return this.network;
} }
return this.network;
}
@Override @Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
{ {
return getNetwork().fill(this, from, resource, doFill); return getNetwork().fill(this, from, resource, doFill);
} }
@Override @Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
{ {
return null; return null;
} }
@Override @Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{ {
return null; return null;
} }
@Override @Override
public boolean canFill(ForgeDirection from, Fluid fluid) public boolean canFill(ForgeDirection from, Fluid fluid)
{ {
return true; return true;
} }
@Override @Override
public boolean canDrain(ForgeDirection from, Fluid fluid) public boolean canDrain(ForgeDirection from, Fluid fluid)
{ {
return true; return true;
} }
@Override @Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) public FluidTankInfo[] getTankInfo(ForgeDirection from)
{ {
return this.getNetwork().getTankInfo(); return this.getNetwork().getTankInfo();
} }
@Override @Override
public void onFluidChanged() public void onFluidChanged()
{ {
} }
@Override @Override
public FluidTank getInternalTank() public FluidTank getInternalTank()
{ {
if (this.tank == null) if (this.tank == null)
{ {
this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME); this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
} }
return this.tank; return this.tank;
} }
@Override @Override
protected boolean canConnectTo(TileEntity tile) protected boolean canConnectTo(TileEntity tile)
{ {
return tile instanceof IFluidHandler; return tile instanceof IFluidHandler;
} }
@Override @Override
protected IFluidPipe getConnector(TileEntity tile) protected IFluidPipe getConnector(TileEntity tile)
{ {
return tile instanceof IFluidPipe ? (IFluidPipe) tile : null; return tile instanceof IFluidPipe ? (IFluidPipe) tile : null;
} }
@Override @Override
public int getPressureIn(ForgeDirection side) public int getPressureIn(ForgeDirection side)
{ {
return 0; return 0;
} }
@Override @Override
public void onWrongPressure(ForgeDirection side, int pressure) 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 @Override
public int getMaxFlowRate() public int getMaxPressure()
{ {
return FluidContainerRegistry.BUCKET_VOLUME; return 1000;
} }
@Override @Override
public void save(NBTTagCompound nbt) public int getMaxFlowRate()
{ {
super.save(nbt); return FluidContainerRegistry.BUCKET_VOLUME;
nbt.setBoolean("isExtracting", isExtracting); }
}
@Override @Override
public void load(NBTTagCompound nbt) public void save(NBTTagCompound nbt)
{ {
super.load(nbt); super.save(nbt);
isExtracting = nbt.getBoolean("isExtracting"); nbt.setBoolean("isExtracting", isExtracting);
} }
@Override @Override
public boolean canFlow() public void load(NBTTagCompound nbt)
{ {
return !isExtracting; super.load(nbt);
} isExtracting = nbt.getBoolean("isExtracting");
}
@Override
public boolean canFlow()
{
return !isExtracting;
}
} }

View file

@ -9,71 +9,76 @@ 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
public void distributeConnectors() public void distributeConnectors()
{ {
FluidStack fillStack = this.getTank().getFluid(); FluidStack fillStack = this.getTank().getFluid();
int lowestY = 255, highestY = 0; int lowestY = 255, highestY = 0;
if (fillStack == null || fillStack.getFluid().isGaseous()) if (fillStack == null || fillStack.getFluid().isGaseous())
{ {
super.distributeConnectors(); super.distributeConnectors();
} }
else if (this.getConnectors().size() > 0) else if (this.getConnectors().size() > 0)
{ {
fillStack = fillStack.copy(); fillStack = fillStack.copy();
for (IFluidConnector connector : this.getConnectors()) for (IFluidConnector connector : this.getConnectors())
{ {
connector.getInternalTank().setFluid(null); connector.getInternalTank().setFluid(null);
connector.onFluidChanged(); connector.onFluidChanged();
if (connector instanceof TileEntity && ((TileEntity) connector).yCoord < lowestY) if (connector instanceof TileEntity && ((TileEntity) connector).yCoord < lowestY)
{ {
lowestY = ((TileEntity) connector).yCoord; lowestY = ((TileEntity) connector).yCoord;
} }
if (connector instanceof TileEntity && ((TileEntity) connector).yCoord > highestY) if (connector instanceof TileEntity && ((TileEntity) connector).yCoord > highestY)
{ {
highestY = ((TileEntity) connector).yCoord; highestY = ((TileEntity) connector).yCoord;
} }
} }
// TODO Add path finder to prevent filling when tanks are only connected at the top // TODO Add path finder to prevent filling when tanks are only connected at the top
for (int y = lowestY; y <= highestY; y++) for (int y = lowestY; y <= highestY; y++)
{ {
Set<IFluidConnector> parts = new LinkedHashSet<IFluidConnector>(); Set<IFluidConnector> parts = new LinkedHashSet<IFluidConnector>();
for (IFluidConnector part : this.getConnectors()) for (IFluidConnector part : this.getConnectors())
{ {
if (part instanceof IFluidConnector && ((TileEntity) part).yCoord == y) if (part instanceof IFluidConnector && ((TileEntity) part).yCoord == y)
{ {
parts.add(part); parts.add(part);
} }
} }
if (!parts.isEmpty()) if (!parts.isEmpty())
{ {
this.fillTankSet(fillStack, parts); this.fillTankSet(fillStack, parts);
} }
if (fillStack == null || fillStack.amount <= 0) if (fillStack == null || fillStack.amount <= 0)
{ {
break; break;
} }
} }
} }
} }
@Override @Override
public IFluidNetwork newInstance() public IFluidNetwork newInstance()
{ {
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);
}
}