From f773af8ff702d1a1ab139458d73d6af0bd243fdb Mon Sep 17 00:00:00 2001 From: DarkGuardsman Date: Fri, 26 Jul 2013 20:52:11 -0400 Subject: [PATCH] Worked on pathfinder --- .../fluid/common/pump/LiquidPathFinder.java | 59 +++++++++++-------- .../fluid/common/pump/TileEntityDrain.java | 8 +-- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/minecraft/dark/fluid/common/pump/LiquidPathFinder.java b/src/minecraft/dark/fluid/common/pump/LiquidPathFinder.java index 13c231a9..8aa4a7a2 100644 --- a/src/minecraft/dark/fluid/common/pump/LiquidPathFinder.java +++ b/src/minecraft/dark/fluid/common/pump/LiquidPathFinder.java @@ -15,19 +15,24 @@ import dark.core.helpers.FluidHelper; /** A simpler pathfinder based on Calclavia's PathFinder from UE api */ public class LiquidPathFinder { - private World world; /* MC WORLD */ - public List nodes = new ArrayList(); /* - * LOCATIONs THE PATH FINDER HAS GONE - * OVER - */ - public List results = new ArrayList();/* LOCATIONS THAT ARE VALID RESULTS */ - private boolean fill = false; /* ARE WE FILLING THE PATH OR DRAINING THE PATH */ - private ForgeDirection priority; /* BASED ON fill -- WHICH DIRECTION WILL THE PATH GO FIRST */ + /** Curent world this pathfinder will operate in */ + private World world; + /** List of all nodes traveled by the path finder */ + public List nodes = new ArrayList(); + /** List of all nodes that match the search parms */ + public List results = new ArrayList(); + /** Are we looking for liquid fillable blocks */ + private boolean fill = false; + /** priority search direction either up or down only */ + private ForgeDirection priority; + /** Limit on the searched nodes per run */ private int resultLimit = 2000; + /** Start location of the pathfinder used for range calculations */ private Vector2 Start; + /** Range to limit the search to */ private double range; - private Random random = new Random(); - List bn = new ArrayList(); + /** List of forgeDirection to use that are shuffled to prevent strait lines */ + List shuffledDirections = new ArrayList(); public LiquidPathFinder(final World world, final int resultLimit, final double range) { @@ -43,13 +48,15 @@ public class LiquidPathFinder } this.resultLimit = resultLimit; this.reset(); - bn.add(ForgeDirection.EAST); - bn.add(ForgeDirection.WEST); - bn.add(ForgeDirection.NORTH); - bn.add(ForgeDirection.SOUTH); + shuffledDirections.add(ForgeDirection.EAST); + shuffledDirections.add(ForgeDirection.WEST); + shuffledDirections.add(ForgeDirection.NORTH); + shuffledDirections.add(ForgeDirection.SOUTH); } - /** @return True on success finding, false on failure. */ + /** Searches for nodes attached to the given node + * + * @return True on success finding, false on failure. */ public boolean findNodes(Vector3 node) { if (node == null) @@ -67,8 +74,7 @@ public class LiquidPathFinder return true; } - int id = node.getBlockID(world); - if (this.fill && (id == 0 || (FluidHelper.isFillable(world, node)))) + if (this.fill && FluidHelper.isFillable(world, node)) { this.results.add(node); } @@ -77,7 +83,7 @@ public class LiquidPathFinder this.results.add(node); } - if (this.isDone(node)) + if (this.isDone(node.clone())) { return false; } @@ -87,10 +93,10 @@ public class LiquidPathFinder return true; } - Collections.shuffle(bn); - Collections.shuffle(bn); + Collections.shuffle(shuffledDirections); + Collections.shuffle(shuffledDirections); - for (ForgeDirection direction : bn) + for (ForgeDirection direction : shuffledDirections) { if (find(direction, vec)) { @@ -111,9 +117,12 @@ public class LiquidPathFinder return false; } - public boolean find(ForgeDirection direction, Vector3 vec) + /** Find all node attached to the origin mode in the given direction + * + * Note: Calls findNode if the next code is valid */ + public boolean find(ForgeDirection direction, Vector3 origin) { - vec = vec.clone().modifyPositionFromSide(direction); + Vector3 vec = origin.clone().modifyPositionFromSide(direction); double distance = vec.toVector2().distanceTo(this.Start); if (distance <= this.range && this.isValidNode(vec) & !this.nodes.contains(vec)) { @@ -125,11 +134,13 @@ public class LiquidPathFinder return false; } + /** Checks to see if this node is valid to path find threw */ public boolean isValidNode(Vector3 pos) { - return FluidHelper.drainBlock(world, pos, false) != null; + return FluidHelper.drainBlock(world, pos, false) != null || FluidHelper.isFillable(world, pos); } + /** Checks to see if we are done pathfinding */ public boolean isDone(Vector3 vec) { if (this.results.size() >= this.resultLimit || this.nodes.size() >= 4000) diff --git a/src/minecraft/dark/fluid/common/pump/TileEntityDrain.java b/src/minecraft/dark/fluid/common/pump/TileEntityDrain.java index 253ffc30..f77371e5 100644 --- a/src/minecraft/dark/fluid/common/pump/TileEntityDrain.java +++ b/src/minecraft/dark/fluid/common/pump/TileEntityDrain.java @@ -74,11 +74,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand int meta = 0; if (worldObj != null) { - meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); - if (meta > 5) - { - meta -= 6; - } + meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord) % 6; } return ForgeDirection.getOrientation(meta); } @@ -224,8 +220,6 @@ public class TileEntityDrain extends TileEntityFluidDevice implements IFluidHand } - - @Override public int fillArea(FluidStack resource, boolean doFill) {