Fixed new pathfinder

I've seen it drain so far but i need to test it more.
This commit is contained in:
Rseifert 2013-04-08 19:49:24 -04:00
parent 0d924dc3c8
commit ce9aad402f
2 changed files with 80 additions and 64 deletions

View file

@ -70,70 +70,74 @@ 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 && this.requestMap.size() > 0)
if (!this.worldObj.isRemote && this.canDrainSources() && this.ticks % 20 == 0)
{
this.currentWorldEdits = 0;
this.doCleanup();
/* ONLY FIND NEW SOURCES IF OUR CURRENT LIST RUNS DRY */
if (this.targetSources.size() < this.MAX_WORLD_EDITS_PER_PROCESS + 10)
if (this.requestMap.size() > 0)
{
this.getNextFluidBlock();
}
TileEntity pipe = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), this.getFacing().getOpposite());
if (pipe instanceof IFluidNetworkPart)
{
for (Entry<TileEntityConstructionPump, LiquidStack> request : requestMap.entrySet())
/* ONLY FIND NEW SOURCES IF OUR CURRENT LIST RUNS DRY */
if (this.targetSources.size() < this.MAX_WORLD_EDITS_PER_PROCESS + 10)
{
if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS)
this.getNextFluidBlock();
}
TileEntity pipe = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), this.getFacing().getOpposite());
if (pipe instanceof IFluidNetworkPart)
{
for (Entry<TileEntityConstructionPump, LiquidStack> request : requestMap.entrySet())
{
break;
}
if (((IFluidNetworkPart) pipe).getNetwork().isConnected(request.getKey()) && targetSources.size() > 0)
{
Iterator it = this.targetSources.iterator();
while (it.hasNext())
if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS)
{
Vector3 loc = (Vector3) it.next();
if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS)
break;
}
if (((IFluidNetworkPart) pipe).getNetwork().isConnected(request.getKey()) && targetSources.size() > 0)
{
Iterator it = this.targetSources.iterator();
while (it.hasNext())
{
break;
}
if (FluidHelper.isSourceBlock(this.worldObj, loc))
{
/* GET STACKS */
LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(this.worldObj));
LiquidStack requestStack = request.getValue();
if (stack != null && requestStack != null && (requestStack.isLiquidEqual(stack) || requestStack.itemID == -1))
Vector3 loc = (Vector3) it.next();
if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS)
{
if (request.getKey().fill(0, stack, false) > 0)
break;
}
if (FluidHelper.isSourceBlock(this.worldObj, loc))
{
/* GET STACKS */
LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(this.worldObj));
LiquidStack requestStack = request.getValue();
if (stack != null && requestStack != null && (requestStack.isLiquidEqual(stack) || requestStack.itemID == -1))
{
/* EDIT REQUEST IN MAP */
int requestAmmount = requestStack.amount - request.getKey().fill(0, stack, true);
if (requestAmmount <= 0)
if (request.getKey().fill(0, stack, false) > 0)
{
this.requestMap.remove(request);
}
else
{
request.setValue(FluidHelper.getStack(requestStack, requestAmmount));
}
/* ADD TO UPDATE QUE */
if (!this.updateQue.contains(loc))
{
this.updateQue.add(loc);
/* EDIT REQUEST IN MAP */
int requestAmmount = requestStack.amount - request.getKey().fill(0, stack, true);
if (requestAmmount <= 0)
{
this.requestMap.remove(request);
}
else
{
request.setValue(FluidHelper.getStack(requestStack, requestAmmount));
}
/* ADD TO UPDATE QUE */
if (!this.updateQue.contains(loc))
{
this.updateQue.add(loc);
}
/* REMOVE BLOCK */
loc.setBlock(this.worldObj, 0, 0, 2);
this.currentWorldEdits++;
it.remove();
}
/* REMOVE BLOCK */
loc.setBlock(this.worldObj, 0, 0, 2);
this.currentWorldEdits++;
it.remove();
}
}
}
@ -151,7 +155,7 @@ 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);
@ -161,7 +165,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
public void doCleanup()
{
/* CALL UPDATE ON EDITED BLOCKS */
if (this.ticks % 100 == 0 && updateQue.size() > 0)
if (this.ticks % 40 == 0 && updateQue.size() > 0)
{
Iterator pp = this.updateQue.iterator();
while (pp.hasNext())

View file

@ -5,6 +5,7 @@ import hydraulic.helpers.FluidHelper;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidStack;
@ -41,18 +42,28 @@ public class LiquidPathFinder
/**
* @return True on success finding, false on failure.
*/
public boolean findNodes(Vector3 currentNode)
public boolean findNodes(Vector3 node)
{
this.nodes.add(currentNode);
if (this.fill || FluidHelper.isSourceBlock(world, currentNode))
this.nodes.add(node);
Block block = Block.blocksList[node.getBlockID(world)];
if (block != null)
{
this.results.add(currentNode);
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);
}
}
if (this.isDone(currentNode))
if (this.isDone(node))
{
return false;
}
Vector3 vec = currentNode.modifyPositionFromSide(this.priority);
Vector3 vec = node.clone().modifyPositionFromSide(this.priority);
if (this.isValidNode(vec) & !this.nodes.contains(vec))
{
if (this.findNodes(vec))
@ -60,11 +71,12 @@ public class LiquidPathFinder
return true;
}
}
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if (direction != this.priority)
{
vec = currentNode.modifyPositionFromSide(direction);
vec = node.clone().modifyPositionFromSide(direction);
if (this.isValidNode(vec) & !this.nodes.contains(vec))
{
if (this.findNodes(vec))
@ -80,14 +92,14 @@ public class LiquidPathFinder
public boolean isValidNode(Vector3 pos)
{
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
if (this.fill)
Block block = Block.blocksList[pos.getBlockID(world)];
if (!this.fill)
{
return ((liquid != null || pos.getBlockID(world) == 0) && FluidHelper.getConnectedSources(world, pos) > 0);
return FluidHelper.getLiquidFromBlockId(pos.getBlockID(world)) != null;
}
else
{
return liquid != null;
return FluidHelper.getLiquidFromBlockId(pos.getBlockID(world)) != null || (block.isBlockReplaceable(world, pos.intX(), pos.intY(), pos.intZ()) && FluidHelper.getConnectedSources(world, pos) > 0);
}
}