Fixed fluid system tentatively
This commit is contained in:
parent
b94e8aaf17
commit
33df875a9b
6 changed files with 109 additions and 69 deletions
|
@ -88,10 +88,10 @@ public class RenderGutter extends TileEntitySpecialRenderer implements ISimpleIt
|
|||
FluidTank tank = ((TileGutter) tileEntity).getInternalTank();
|
||||
double percentageFilled = (double) tank.getFluidAmount() / (double) tank.getCapacity();
|
||||
|
||||
double ySouthEast = FluidUtility.getAveragePercentageFilledForSides(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 ySouthWest = FluidUtility.getAveragePercentageFilledForSides(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 ySouthEast = FluidUtility.getAveragePercentageFilledForSides(TileGutter.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.EAST);
|
||||
double yNorthEast = FluidUtility.getAveragePercentageFilledForSides(TileGutter.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.EAST);
|
||||
double ySouthWest = FluidUtility.getAveragePercentageFilledForSides(TileGutter.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, 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);
|
||||
GL11.glPopMatrix();
|
||||
|
|
|
@ -67,10 +67,10 @@ public class RenderTank extends TileEntitySpecialRenderer implements ISimpleItem
|
|||
FluidTank tank = ((TileTank) tileEntity).getInternalTank();
|
||||
double percentageFilled = (double) tank.getFluidAmount() / (double) tank.getCapacity();
|
||||
|
||||
double ySouthEast = FluidUtility.getAveragePercentageFilledForSides(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 ySouthWest = FluidUtility.getAveragePercentageFilledForSides(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 ySouthEast = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.EAST);
|
||||
double yNorthEast = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.NORTH, ForgeDirection.EAST);
|
||||
double ySouthWest = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, 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);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -49,59 +49,64 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, PressureNode, IPr
|
|||
synchronized (connections)
|
||||
{
|
||||
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)
|
||||
{
|
||||
PressureNode check = ((IPressureNodeProvider) tile).getNode(PressureNode.class, dir.getOpposite());
|
||||
TileEntity tile = position().translate(dir).getTileEntity(world());
|
||||
|
||||
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);
|
||||
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. */
|
||||
if (previousConnections != currentConnections)
|
||||
{
|
||||
sendConnectionUpdate();
|
||||
/** Only send packet updates if visuallyConnected changed. */
|
||||
if (!world().isRemote && previousConnections != currentConnections)
|
||||
{
|
||||
sendConnectionUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{return
|
||||
super.canConnect(from, source);
|
||||
/*Object obj = tile instanceof TileMultipart ? ((TileMultipart) tile).partMap(ForgeDirection.UNKNOWN.ordinal()) : tile;
|
||||
|
||||
if (obj instanceof PartPipe)
|
||||
{
|
||||
if (this.getMaterial() == ((PartPipe) obj).getMaterial())
|
||||
{
|
||||
return getColor() == ((PartPipe) obj).getColor() || (getColor() == DEFAULT_COLOR || ((PartPipe) obj).getColor() == DEFAULT_COLOR);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return tile instanceof IFluidHandler;*/
|
||||
{
|
||||
return super.canConnect(from, source);
|
||||
/*
|
||||
* Object obj = tile instanceof TileMultipart ? ((TileMultipart)
|
||||
* tile).partMap(ForgeDirection.UNKNOWN.ordinal()) : tile;
|
||||
* if (obj instanceof PartPipe)
|
||||
* {
|
||||
* if (this.getMaterial() == ((PartPipe) obj).getMaterial())
|
||||
* {
|
||||
* return getColor() == ((PartPipe) obj).getColor() || (getColor() == DEFAULT_COLOR
|
||||
* || ((PartPipe) obj).getColor() == DEFAULT_COLOR);
|
||||
* }
|
||||
* return false;
|
||||
* }
|
||||
* return tile instanceof IFluidHandler;
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -232,12 +237,12 @@ public class PartPipe extends PartFramedNode<EnumPipeMaterial, PressureNode, IPr
|
|||
@Override
|
||||
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
|
||||
|
|
|
@ -16,7 +16,6 @@ import calclavia.lib.prefab.tile.IRotatable;
|
|||
|
||||
public class TilePump extends TileMechanical implements IPressureNodeProvider, IRotatable
|
||||
{
|
||||
private final long maximumPower = 100000;
|
||||
private final PressureNode pressureNode;
|
||||
|
||||
public TilePump()
|
||||
|
@ -30,19 +29,46 @@ public class TilePump extends TileMechanical implements IPressureNodeProvider, I
|
|||
{
|
||||
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())
|
||||
{
|
||||
return (int) -Math.max((((double) mechanicalNode.getPower() / (double) maximumPower) * 100), 2);
|
||||
return (int) -Math.max(Math.abs(mechanicalNode.getTorque() / 1000d), 2);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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);
|
||||
|
||||
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(), flowRate, false);
|
||||
FluidStack drain = ((IFluidHandler) tileIn).drain(getDirection(), pressureNode.getMaxFlowRate(), false);
|
||||
|
||||
if (drain != null)
|
||||
{
|
||||
|
|
|
@ -104,29 +104,33 @@ public class PressureNode extends Node<IPressureNodeProvider, TickingGrid, Objec
|
|||
if (pressureA >= pressureB)
|
||||
{
|
||||
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()));
|
||||
quantity = Math.min(Math.min(quantity, tankB.getCapacity() - amountB), amountA);
|
||||
|
||||
if (quantity > 0)
|
||||
if (tankB != null)
|
||||
{
|
||||
FluidStack drainStack = parent.drain(dir.getOpposite(), quantity, false);
|
||||
int amountB = tankB.getFluidAmount();
|
||||
|
||||
if (drainStack != null && drainStack.amount > 0)
|
||||
parent.drain(dir.getOpposite(), otherPipe.parent.fill(dir, drainStack, true), true);
|
||||
int quantity = Math.max(pressureA > pressureB ? (pressureA - pressureB) * getMaxFlowRate() : 0, Math.min((amountA - amountB) / 2, getMaxFlowRate()));
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -218,6 +218,12 @@ public abstract class PartFramedNode<M extends Enum, N extends Node, T extends I
|
|||
{
|
||||
node.reconstruct();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
node.reconstruct();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldSeparate()
|
||||
|
|
Loading…
Reference in a new issue