Added A* Path finder for Fill Area

This should? Fix the issue with the drain trying to fill outside of the
possible path bounds. What is is doing is finding a bath from the drain
to the next Y level change. If it fails to find a path the yFillStart
doesn't increase to the next level.
This commit is contained in:
Rseifert 2013-04-07 22:11:46 -04:00
parent a5281b9a12
commit 0211f961c1
2 changed files with 69 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import fluidmech.common.FluidMech;
import fluidmech.common.pump.path.PathfinderCheckerFindFillable;
import fluidmech.common.pump.path.PathfinderCheckerLiquid;
import fluidmech.common.pump.path.PathfinderFindHighestSource;
import fluidmech.common.pump.path.PathfinderFindPathThrewWater;
import hydraulic.api.IDrain;
import hydraulic.fluidnetwork.IFluidNetworkPart;
import hydraulic.helpers.FluidHelper;
@ -293,11 +294,16 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
}
}
}
/* IF NO FILL TARGETS WERE FOUND ON THIS LEVEL INCREASE YFILLSTART */
if (fillable == 0)
{
this.yFillStart++;
PathfinderFindPathThrewWater aPath = new PathfinderFindPathThrewWater(this.worldObj, new Vector3(xCoord, yCoord, zCoord));
aPath.init(new Vector3(this.xCoord + this.getFacing().offsetX, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ));
if (aPath.results.size() > 0)
{
this.yFillStart++;
}
}
}
return drained;

View file

@ -0,0 +1,61 @@
package fluidmech.common.pump.path;
import hydraulic.helpers.FluidHelper;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.path.IPathCallBack;
import universalelectricity.core.path.Pathfinder;
import universalelectricity.core.path.PathfinderAStar;
import universalelectricity.core.vector.Vector3;
/**
* Check if a conductor connects with another.
*
* @author Calclavia
*
*/
public class PathfinderFindPathThrewWater extends PathfinderAStar
{
public PathfinderFindPathThrewWater(final World world, final Vector3 goal)
{
super(new IPathCallBack()
{
@Override
public Set<Vector3> getConnectedNodes(Pathfinder finder, Vector3 currentNode)
{
Set<Vector3> neighbors = new HashSet<Vector3>();
for (int i = 0; i < 6; i++)
{
ForgeDirection direction = ForgeDirection.getOrientation(i);
Vector3 position = currentNode.clone().modifyPositionFromSide(direction);
if (FluidHelper.getLiquidFromBlockId(position.getBlockID(world)) != null || (position.getBlockID(world) == 0 && FluidHelper.getConnectedSources(world, position) > 0))
{
neighbors.add(position);
}
}
return neighbors;
}
@Override
public boolean onSearch(Pathfinder finder, Vector3 node)
{
if (node == goal)
{
finder.results.add(node);
return true;
}
return false;
}
}, goal);
}
}