Fixed fluid system tentatively

This commit is contained in:
Calclavia 2014-03-08 13:44:21 -08:00
parent b94e8aaf17
commit 33df875a9b
6 changed files with 109 additions and 69 deletions

View file

@ -88,10 +88,10 @@ public class RenderGutter extends TileEntitySpecialRenderer implements ISimpleIt
FluidTank tank = ((TileGutter) tileEntity).getInternalTank(); FluidTank tank = ((TileGutter) tileEntity).getInternalTank();
double percentageFilled = (double) tank.getFluidAmount() / (double) tank.getCapacity(); double percentageFilled = (double) tank.getFluidAmount() / (double) tank.getCapacity();
double ySouthEast = FluidUtility.getAveragePercentageFilledForSides(percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.EAST); double ySouthEast = FluidUtility.getAveragePercentageFilledForSides(TileGutter.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.EAST);
double yNorthEast = FluidUtility.getAveragePercentageFilledForSides(percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.EAST); double yNorthEast = FluidUtility.getAveragePercentageFilledForSides(TileGutter.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.EAST);
double ySouthWest = FluidUtility.getAveragePercentageFilledForSides(percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.WEST); double ySouthWest = FluidUtility.getAveragePercentageFilledForSides(TileGutter.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.WEST);
double yNorthWest = FluidUtility.getAveragePercentageFilledForSides(percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.WEST); double yNorthWest = FluidUtility.getAveragePercentageFilledForSides(TileGutter.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.WEST);
FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest); FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest);
GL11.glPopMatrix(); GL11.glPopMatrix();

View file

@ -67,10 +67,10 @@ public class RenderTank extends TileEntitySpecialRenderer implements ISimpleItem
FluidTank tank = ((TileTank) tileEntity).getInternalTank(); FluidTank tank = ((TileTank) tileEntity).getInternalTank();
double percentageFilled = (double) tank.getFluidAmount() / (double) tank.getCapacity(); double percentageFilled = (double) tank.getFluidAmount() / (double) tank.getCapacity();
double ySouthEast = FluidUtility.getAveragePercentageFilledForSides(percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.EAST); double ySouthEast = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.EAST);
double yNorthEast = FluidUtility.getAveragePercentageFilledForSides(percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.EAST); double yNorthEast = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.EAST);
double ySouthWest = FluidUtility.getAveragePercentageFilledForSides(percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.WEST); double ySouthWest = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.WEST);
double yNorthWest = FluidUtility.getAveragePercentageFilledForSides(percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.WEST); double yNorthWest = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.WEST);
FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest); FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest);
} }
else else

View file

@ -49,59 +49,64 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, PressureNode, IPr
synchronized (connections) synchronized (connections)
{ {
connections.clear(); connections.clear();
byte previousConnections = getAllCurrentConnections();
currentConnections = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) if (world() != null)
{ {
TileEntity tile = position().translate(dir).getTileEntity(world()); byte previousConnections = getAllCurrentConnections();
currentConnections = 0;
if (tile instanceof IFluidHandler) for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{ {
if (tile instanceof IPressureNodeProvider) TileEntity tile = position().translate(dir).getTileEntity(world());
{
PressureNode check = ((IPressureNodeProvider) tile).getNode(PressureNode.class, dir.getOpposite());
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this)) if (tile instanceof IFluidHandler)
{
if (tile instanceof IPressureNodeProvider)
{
PressureNode check = ((IPressureNodeProvider) tile).getNode(PressureNode.class, dir.getOpposite());
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite(), this))
{
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
connections.put(check, dir);
}
}
else
{ {
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true); currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
connections.put(check, dir); connections.put(tile, dir);
} }
} }
else
{
currentConnections = WorldUtility.setEnableSide(currentConnections, dir, true);
connections.put(tile, dir);
}
} }
}
/** Only send packet updates if visuallyConnected changed. */ /** Only send packet updates if visuallyConnected changed. */
if (previousConnections != currentConnections) if (!world().isRemote && previousConnections != currentConnections)
{ {
sendConnectionUpdate(); sendConnectionUpdate();
}
} }
} }
} }
@Override @Override
public boolean canConnect(ForgeDirection from, Object source) public boolean canConnect(ForgeDirection from, Object source)
{return {
super.canConnect(from, source); return super.canConnect(from, source);
/*Object obj = tile instanceof TileMultipart ? ((TileMultipart) tile).partMap(ForgeDirection.UNKNOWN.ordinal()) : tile; /*
* Object obj = tile instanceof TileMultipart ? ((TileMultipart)
if (obj instanceof PartPipe) * tile).partMap(ForgeDirection.UNKNOWN.ordinal()) : tile;
{ * if (obj instanceof PartPipe)
if (this.getMaterial() == ((PartPipe) obj).getMaterial()) * {
{ * if (this.getMaterial() == ((PartPipe) obj).getMaterial())
return getColor() == ((PartPipe) obj).getColor() || (getColor() == DEFAULT_COLOR || ((PartPipe) obj).getColor() == DEFAULT_COLOR); * {
} * return getColor() == ((PartPipe) obj).getColor() || (getColor() == DEFAULT_COLOR
* || ((PartPipe) obj).getColor() == DEFAULT_COLOR);
return false; * }
} * return false;
* }
return tile instanceof IFluidHandler;*/ * return tile instanceof IFluidHandler;
*/
} }
@Override @Override
@ -232,12 +237,12 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, PressureNode, IPr
@Override @Override
public FluidTank getPressureTank() public FluidTank getPressureTank()
{ {
if (this.tank == null) if (tank == null)
{ {
this.tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME); tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME);
} }
return this.tank; return tank;
} }
@Override @Override

View file

@ -16,7 +16,6 @@ import calclavia.lib.prefab.tile.IRotatable;
public class TilePump extends TileMechanical implements IPressureNodeProvider, IRotatable public class TilePump extends TileMechanical implements IPressureNodeProvider, IRotatable
{ {
private final long maximumPower = 100000;
private final PressureNode pressureNode; private final PressureNode pressureNode;
public TilePump() public TilePump()
@ -30,19 +29,46 @@ public class TilePump extends TileMechanical implements IPressureNodeProvider, I
{ {
if (dir == getDirection()) if (dir == getDirection())
{ {
return (int) Math.max((((double) mechanicalNode.getPower() / (double) maximumPower) * 100), 2); return (int) Math.max(Math.abs(mechanicalNode.getTorque() / 1000d), 2);
} }
else if (dir == getDirection().getOpposite()) else if (dir == getDirection().getOpposite())
{ {
return (int) -Math.max((((double) mechanicalNode.getPower() / (double) maximumPower) * 100), 2); return (int) -Math.max(Math.abs(mechanicalNode.getTorque() / 1000d), 2);
} }
} }
return 0; return 0;
} }
@Override
public int getMaxFlowRate()
{
return (int) Math.abs(mechanicalNode.getAngularVelocity() * 20);
}
@Override
public boolean canConnect(ForgeDirection from, Object source)
{
return super.canConnect(from, source) && (from == getDirection() || from == getDirection().getOpposite());
}
}; };
} }
@Override
public void initiate()
{
pressureNode.reconstruct();
super.initiate();
}
@Override
public void invalidate()
{
super.invalidate();
pressureNode.deconstruct();
}
@Override @Override
public void updateEntity() public void updateEntity()
{ {
@ -55,10 +81,9 @@ public class TilePump extends TileMechanical implements IPressureNodeProvider, I
*/ */
TileEntity tileIn = new Vector3(this).translate(getDirection().getOpposite()).getTileEntity(this.worldObj); TileEntity tileIn = new Vector3(this).translate(getDirection().getOpposite()).getTileEntity(this.worldObj);
if (tileIn instanceof IFluidHandler && !(tileIn instanceof IPressureNodeProvider)) if (tileIn instanceof IFluidHandler)
{ {
int flowRate = (int) (((double) mechanicalNode.getPower() / (double) maximumPower) * 500); FluidStack drain = ((IFluidHandler) tileIn).drain(getDirection(), pressureNode.getMaxFlowRate(), false);
FluidStack drain = ((IFluidHandler) tileIn).drain(getDirection(), flowRate, false);
if (drain != null) if (drain != null)
{ {

View file

@ -104,29 +104,33 @@ public class PressureNode extends Node<IPressureNodeProvider, TickingGrid, Objec
if (pressureA >= pressureB) if (pressureA >= pressureB)
{ {
FluidTank tankA = parent.getPressureTank(); FluidTank tankA = parent.getPressureTank();
FluidStack fluidA = tankA.getFluid();
if (tankA != null && fluidA != null) if (tankA != null)
{ {
int amountA = fluidA.amount; FluidStack fluidA = tankA.getFluid();
if (amountA > 0) if (fluidA != null)
{ {
FluidTank tankB = otherPipe.parent.getPressureTank(); int amountA = fluidA.amount;
if (tankB != null) if (amountA > 0)
{ {
int amountB = tankB.getFluidAmount(); FluidTank tankB = otherPipe.parent.getPressureTank();
int quantity = Math.max(pressureA > pressureB ? (pressureA - pressureB) * getMaxFlowRate() : 0, Math.min((amountA - amountB) / 2, getMaxFlowRate())); if (tankB != null)
quantity = Math.min(Math.min(quantity, tankB.getCapacity() - amountB), amountA);
if (quantity > 0)
{ {
FluidStack drainStack = parent.drain(dir.getOpposite(), quantity, false); int amountB = tankB.getFluidAmount();
if (drainStack != null && drainStack.amount > 0) int quantity = Math.max(pressureA > pressureB ? (pressureA - pressureB) * getMaxFlowRate() : 0, Math.min((amountA - amountB) / 2, getMaxFlowRate()));
parent.drain(dir.getOpposite(), otherPipe.parent.fill(dir, drainStack, true), true); quantity = Math.min(Math.min(quantity, tankB.getCapacity() - amountB), amountA);
if (quantity > 0)
{
FluidStack drainStack = parent.drain(dir.getOpposite(), quantity, false);
if (drainStack != null && drainStack.amount > 0)
parent.drain(dir.getOpposite(), otherPipe.parent.fill(dir, drainStack, true), true);
}
} }
} }
} }
@ -166,7 +170,7 @@ public class PressureNode extends Node<IPressureNodeProvider, TickingGrid, Objec
} }
} }
protected int getMaxFlowRate() public int getMaxFlowRate()
{ {
return 10; return 10;
} }

View file

@ -218,6 +218,12 @@ public abstract class PartFramedNode<M extends Enum, N extends Node, T extends I
{ {
node.reconstruct(); node.reconstruct();
} }
@Override
public void onNeighborChanged()
{
node.reconstruct();
}
@Override @Override
public void onWorldSeparate() public void onWorldSeparate()