Fixed grate fill algorithm
This commit is contained in:
parent
d91fdcf8fe
commit
733220edef
3 changed files with 18 additions and 38 deletions
|
@ -39,7 +39,7 @@ public class LiquidPathFinder
|
||||||
private int resultRun = resultLimit;
|
private int resultRun = resultLimit;
|
||||||
private int runs = 0;
|
private int runs = 0;
|
||||||
/** Start location of the pathfinder used for range calculations */
|
/** Start location of the pathfinder used for range calculations */
|
||||||
private Vector3 Start;
|
private Vector3 start;
|
||||||
/** Range to limit the search to */
|
/** Range to limit the search to */
|
||||||
private double range;
|
private double range;
|
||||||
/** List of forgeDirection to use that are shuffled to prevent strait lines */
|
/** List of forgeDirection to use that are shuffled to prevent strait lines */
|
||||||
|
@ -145,7 +145,7 @@ public class LiquidPathFinder
|
||||||
{
|
{
|
||||||
this.runs++;
|
this.runs++;
|
||||||
Vector3 vec = origin.clone().translate(direction);
|
Vector3 vec = origin.clone().translate(direction);
|
||||||
double distance = vec.toVector2().distance(this.Start.toVector2());
|
double distance = vec.toVector2().distance(this.start.toVector2());
|
||||||
|
|
||||||
if (distance <= this.range && isValidNode(vec))
|
if (distance <= this.range && isValidNode(vec))
|
||||||
{
|
{
|
||||||
|
@ -220,7 +220,7 @@ public class LiquidPathFinder
|
||||||
/** Called to execute the pathfinding operation. */
|
/** Called to execute the pathfinding operation. */
|
||||||
public LiquidPathFinder start(final Vector3 startNode, int runCount, final boolean fill)
|
public LiquidPathFinder start(final Vector3 startNode, int runCount, final boolean fill)
|
||||||
{
|
{
|
||||||
this.Start = startNode;
|
this.start = startNode;
|
||||||
this.fill = fill;
|
this.fill = fill;
|
||||||
this.runs = 0;
|
this.runs = 0;
|
||||||
this.resultsFound = 0;
|
this.resultsFound = 0;
|
||||||
|
@ -228,7 +228,7 @@ public class LiquidPathFinder
|
||||||
this.find(ForgeDirection.UNKNOWN, startNode);
|
this.find(ForgeDirection.UNKNOWN, startNode);
|
||||||
|
|
||||||
this.refresh();
|
this.refresh();
|
||||||
this.sortBlockList(Start, results, fill);
|
this.sortBlockList(start, results, fill);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,36 +294,19 @@ public class LiquidPathFinder
|
||||||
// The highest and furthest fluid block for drain. Closest fluid block for fill.
|
// The highest and furthest fluid block for drain. Closest fluid block for fill.
|
||||||
Vector3 bestFluid = null;
|
Vector3 bestFluid = null;
|
||||||
|
|
||||||
for (Vector3 checkPos : set)
|
if (fill)
|
||||||
{
|
{
|
||||||
if (bestFluid == null)
|
bestFluid = start;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (Vector3 checkPos : set)
|
||||||
{
|
{
|
||||||
bestFluid = checkPos;
|
if (bestFluid == null)
|
||||||
}
|
|
||||||
|
|
||||||
if (fill)
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* We're filling, so we want the closest lowest block first.
|
|
||||||
*/
|
|
||||||
if (prioritizeHighest)
|
|
||||||
{
|
|
||||||
if (checkPos.y < bestFluid.y)
|
|
||||||
{
|
|
||||||
bestFluid = checkPos;
|
|
||||||
}
|
|
||||||
else if (checkPos.y == bestFluid.y && start.distance(checkPos) < start.distance(bestFluid))
|
|
||||||
{
|
|
||||||
bestFluid = checkPos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (start.distance(checkPos) < start.distance(bestFluid))
|
|
||||||
{
|
{
|
||||||
bestFluid = checkPos;
|
bestFluid = checkPos;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* We're draining, so we want the highest furthest block first.
|
* We're draining, so we want the highest furthest block first.
|
||||||
*/
|
*/
|
||||||
|
@ -346,17 +329,17 @@ public class LiquidPathFinder
|
||||||
}
|
}
|
||||||
|
|
||||||
final Vector3 optimalFluid = bestFluid;
|
final Vector3 optimalFluid = bestFluid;
|
||||||
|
|
||||||
Collections.sort(sortedResults, new Comparator<Vector3>()
|
Collections.sort(sortedResults, new Comparator<Vector3>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public int compare(Vector3 vecA, Vector3 vecB)
|
public int compare(Vector3 vecA, Vector3 vecB)
|
||||||
{
|
{
|
||||||
return Double.compare(vecA.distance(optimalFluid), vecB.distance(optimalFluid));
|
if (vecA.equals(vecB))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return vecA.distance(optimalFluid) < vecB.distance(optimalFluid) ? -1 : 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Collections.reverse(sortedResults);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -132,7 +132,8 @@ public class TileGrate extends TileAdvanced implements IFluidHandler, IDrain
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sort results out into two groups and clear the rest out of the result list */
|
/* Sort results out into two groups and clear the rest out of the result list */
|
||||||
Iterator<Vector3> it = this.getFillFinder().refresh().results.iterator();
|
Iterator<Vector3> it = getFillList().iterator();
|
||||||
|
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
Vector3 vec = it.next();
|
Vector3 vec = it.next();
|
||||||
|
|
|
@ -131,10 +131,6 @@ public class TilePump extends TileMachine implements IReadOut, ITileConnector, I
|
||||||
}
|
}
|
||||||
return;// TODO check why return is here
|
return;// TODO check why return is here
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
drainList = ((IDrain) drain).getDrainList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drainList == null)
|
if (drainList == null)
|
||||||
|
|
Loading…
Reference in a new issue