More work on pump and drain

can't recall all the work i've done since last commit. However, i've
test and improve the path finder and how its used by the drain. It now
works 100% but need more improvement. Especial the draining part as
source will keep refilling if not drained right
This commit is contained in:
Rseifert 2013-04-08 22:47:25 -04:00
parent e8586b9e81
commit 479177d662
3 changed files with 53 additions and 19 deletions

View file

@ -1,5 +1,7 @@
package fluidmech.common.pump;
import hydraulic.fluidnetwork.HydraulicNetworkHelper;
import java.util.List;
import net.minecraft.block.Block;
@ -114,6 +116,11 @@ public class BlockConstructionPump extends BlockAdvanced
if (!world.isRemote)
{
world.setBlockMetadataWithNotify(x, y, z, side, 3);
TileEntity entity = world.getBlockTileEntity(x, y, z);
if(entity instanceof TileEntityConstructionPump)
{
HydraulicNetworkHelper.invalidate(entity);
}
return true;
}
return this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);

View file

@ -70,12 +70,12 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
public void updateEntity()
{
/* MAIN LOGIC PATH FOR DRAINING BODIES OF LIQUID */
if (!this.worldObj.isRemote && this.canDrainSources() && this.ticks % 20 == 0)
if (!this.worldObj.isRemote && this.ticks % 20 == 0)
{
this.currentWorldEdits = 0;
this.doCleanup();
if (this.requestMap.size() > 0)
if (this.canDrainSources() && this.requestMap.size() > 0)
{
/* ONLY FIND NEW SOURCES IF OUR CURRENT LIST RUNS DRY */
if (this.targetSources.size() < this.MAX_WORLD_EDITS_PER_PROCESS + 10)
@ -88,7 +88,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
{
break;
}
Iterator it = this.targetSources.iterator();
while (it.hasNext())
{
@ -147,7 +147,8 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
{
LiquidPathFinder pathFinder = new LiquidPathFinder(this.worldObj, false, this.MAX_WORLD_EDITS_PER_PROCESS * 2);
pathFinder.init(new Vector3(this.xCoord + this.getFacing().offsetX, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ));
System.out.println("Nodes:" + pathFinder.nodes.size() + "Results:" + pathFinder.results.size());
// System.out.println("Nodes:" + pathFinder.nodes.size() + "Results:" +
// pathFinder.results.size());
for (Vector3 vec : pathFinder.results)
{
this.addVectorToQue(vec);
@ -157,13 +158,13 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
public void doCleanup()
{
/* CALL UPDATE ON EDITED BLOCKS */
if (this.ticks % 40 == 0 && updateQue.size() > 0)
if (this.ticks % 100 == 0 && updateQue.size() > 0)
{
Iterator pp = this.updateQue.iterator();
while (pp.hasNext())
{
Vector3 vec = (Vector3) pp.next();
worldObj.markBlockForUpdate(vec.intX(), vec.intY(), vec.intZ());
worldObj.notifyBlocksOfNeighborChange(vec.intX(), vec.intY(), vec.intZ(), vec.getBlockID(this.worldObj));
pp.remove();
}
}
@ -241,7 +242,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
/* FIND ALL VALID BLOCKS ON LEVEL OR BELLOW */
LiquidPathFinder pathFinder = new LiquidPathFinder(this.worldObj, true, this.MAX_WORLD_EDITS_PER_PROCESS * 2);
pathFinder.init(new Vector3(this.xCoord + this.getFacing().offsetX, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ));
System.out.println("Nodes:" + pathFinder.nodes.size() + "Results:" + pathFinder.results.size());
/* START FILLING IN OR CHECKING IF CAN FILL AREA */
int fillable = 0;
for (Vector3 loc : pathFinder.results)
@ -295,6 +296,32 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
return drained;
}
/**
* Sorter used by the fill method to maker sure its filling the lowest blocks closest to the
* drain first
*/
public static void SortListClosestToOrLowest(ArrayList<Vector3> list, Vector3 target)
{
if (list.size() > 1) // check if the number of orders is larger than 1
{
for (int x = 0; x < list.size(); x++) // bubble sort outer loop
{
Vector3 vec = list.get(x);
double distance = Vector3.distance(vec, target);
for (int i = 0; i < list.size(); i++)
{
Vector3 pos = list.get(x);
if (Vector3.distance(pos, target) < distance)
{
list.set(x, pos);
list.set(i, vec);
}
}
}
}
}
@Override
public boolean canPipeConnect(TileEntity entity, ForgeDirection dir)
{

View file

@ -45,17 +45,13 @@ public class LiquidPathFinder
public boolean findNodes(Vector3 node)
{
this.nodes.add(node);
Block block = Block.blocksList[node.getBlockID(world)];
if (block != null)
if (this.fill && (node.getBlockID(world) == 0 || (FluidHelper.getLiquidFromBlockId(node.getBlockID(world)) != null && node.getBlockMetadata(world) != 0)))
{
if (this.fill && block.isBlockReplaceable(world, node.intX(), node.intY(), node.intZ()))
{
this.results.add(node);
}
else if (!this.fill && FluidHelper.isSourceBlock(world, node))
{
this.results.add(node);
}
this.results.add(node);
}
else if (!this.fill && FluidHelper.isSourceBlock(world, node))
{
this.results.add(node);
}
if (this.isDone(node))
@ -92,14 +88,14 @@ public class LiquidPathFinder
public boolean isValidNode(Vector3 pos)
{
Block block = Block.blocksList[pos.getBlockID(world)];
int blockID = pos.getBlockID(world);
if (!this.fill)
{
return FluidHelper.getLiquidFromBlockId(pos.getBlockID(world)) != null;
}
else
{
return FluidHelper.getLiquidFromBlockId(pos.getBlockID(world)) != null || (block.isBlockReplaceable(world, pos.intX(), pos.intY(), pos.intZ()) && FluidHelper.getConnectedSources(world, pos) > 0);
return FluidHelper.getLiquidFromBlockId(pos.getBlockID(world)) != null || (blockID == 0 && FluidHelper.getConnectedSources(world, pos) > 0);
}
}
@ -118,6 +114,10 @@ public class LiquidPathFinder
public LiquidPathFinder init(Vector3 startNode)
{
this.findNodes(startNode);
if (this.fill && this.isValidNode(startNode))
{
}
return this;
}