added chunk loaded check to path finder
This commit is contained in:
parent
100c40b15f
commit
6620dac6bd
2 changed files with 25 additions and 8 deletions
|
@ -60,7 +60,7 @@
|
||||||
<exclude name="**/*.xml"/>
|
<exclude name="**/*.xml"/>
|
||||||
</fileset>
|
</fileset>
|
||||||
|
|
||||||
<fileset dir="download/Dark-Library-master/resources">
|
<fileset dir="${dir.development}Dark-Library/resources">
|
||||||
<exclude name=".git/**"/>
|
<exclude name=".git/**"/>
|
||||||
<exclude name="**/*.java"/>
|
<exclude name="**/*.java"/>
|
||||||
<exclude name="**/*.xml"/>
|
<exclude name="**/*.xml"/>
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import universalelectricity.core.vector.Vector3;
|
import universalelectricity.core.vector.Vector3;
|
||||||
|
|
||||||
|
@ -15,13 +16,16 @@ import universalelectricity.core.vector.Vector3;
|
||||||
public class LiquidPathFinder
|
public class LiquidPathFinder
|
||||||
{
|
{
|
||||||
private World world; /* MC WORLD */
|
private World world; /* MC WORLD */
|
||||||
public List<Vector3> nodes = new ArrayList<Vector3>(); /* LOCATIONs THE PATH FINDER HAS GONE OVER */
|
public List<Vector3> nodes = new ArrayList<Vector3>(); /*
|
||||||
|
* LOCATIONs THE PATH FINDER HAS GONE
|
||||||
|
* OVER
|
||||||
|
*/
|
||||||
public List<Vector3> results = new ArrayList<Vector3>();/* LOCATIONS THAT ARE VALID RESULTS */
|
public List<Vector3> results = new ArrayList<Vector3>();/* LOCATIONS THAT ARE VALID RESULTS */
|
||||||
private boolean fill; /* ARE WE FILLING THE PATH OR DRAINING THE PATH */
|
private boolean fill; /* ARE WE FILLING THE PATH OR DRAINING THE PATH */
|
||||||
private ForgeDirection priority; /* BASED ON fill -- WHICH DIRECTION WILL THE PATH GO FIRST */
|
private ForgeDirection priority; /* BASED ON fill -- WHICH DIRECTION WILL THE PATH GO FIRST */
|
||||||
private int resultLimit = 2000;
|
private int resultLimit = 2000;
|
||||||
|
|
||||||
public LiquidPathFinder(final World world, final boolean fill, int resultLimit)
|
public LiquidPathFinder(final World world, final boolean fill, final int resultLimit)
|
||||||
{
|
{
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.fill = fill;
|
this.fill = fill;
|
||||||
|
@ -41,9 +45,22 @@ public class LiquidPathFinder
|
||||||
* @return True on success finding, false on failure.
|
* @return True on success finding, false on failure.
|
||||||
*/
|
*/
|
||||||
public boolean findNodes(Vector3 node)
|
public boolean findNodes(Vector3 node)
|
||||||
{
|
{
|
||||||
this.nodes.add(node);
|
Vector3 vec = node.clone();
|
||||||
if (this.fill && (node.getBlockID(world) == 0 || (FluidHelper.getLiquidFromBlockId(node.getBlockID(world)) != null && node.getBlockMetadata(world) != 0)))
|
|
||||||
|
Chunk chunk = this.world.getChunkFromBlockCoords(vec.intX(), vec.intZ());
|
||||||
|
|
||||||
|
if (!chunk.isChunkLoaded)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
this.nodes.add(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = node.getBlockID(world);
|
||||||
|
int meta = node.getBlockID(world);
|
||||||
|
if (this.fill && (id == 0 || (FluidHelper.getLiquidFromBlockId(id) != null && meta != 0)))
|
||||||
{
|
{
|
||||||
this.results.add(node);
|
this.results.add(node);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +74,7 @@ public class LiquidPathFinder
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 vec = node.clone().modifyPositionFromSide(this.priority);
|
vec = node.clone().modifyPositionFromSide(this.priority);
|
||||||
if (this.isValidNode(vec) & !this.nodes.contains(vec))
|
if (this.isValidNode(vec) & !this.nodes.contains(vec))
|
||||||
{
|
{
|
||||||
if (this.findNodes(vec))
|
if (this.findNodes(vec))
|
||||||
|
@ -99,7 +116,7 @@ public class LiquidPathFinder
|
||||||
|
|
||||||
public boolean isDone(Vector3 vec)
|
public boolean isDone(Vector3 vec)
|
||||||
{
|
{
|
||||||
if (this.results.size() >= this.resultLimit || this.nodes.size() >= 10000)
|
if (this.results.size() >= this.resultLimit || this.nodes.size() >= 4000)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue