Fixed request list cleanup in drain

cleanup was not removing unconnected pumps correctly. Now if there is no
pipe network connection to the pump it will be removed.
This commit is contained in:
Rseifert 2013-04-08 20:23:53 -04:00
parent ce9aad402f
commit e8586b9e81

View file

@ -74,7 +74,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
{
this.currentWorldEdits = 0;
this.doCleanup();
if (this.requestMap.size() > 0)
{
/* ONLY FIND NEW SOURCES IF OUR CURRENT LIST RUNS DRY */
@ -82,63 +82,55 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
{
this.getNextFluidBlock();
}
TileEntity pipe = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), this.getFacing().getOpposite());
if (pipe instanceof IFluidNetworkPart)
for (Entry<TileEntityConstructionPump, LiquidStack> request : requestMap.entrySet())
{
for (Entry<TileEntityConstructionPump, LiquidStack> request : requestMap.entrySet())
if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS)
{
break;
}
Iterator it = this.targetSources.iterator();
while (it.hasNext())
{
Vector3 loc = (Vector3) it.next();
if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS)
{
break;
}
if (((IFluidNetworkPart) pipe).getNetwork().isConnected(request.getKey()) && targetSources.size() > 0)
if (FluidHelper.isSourceBlock(this.worldObj, loc))
{
Iterator it = this.targetSources.iterator();
while (it.hasNext())
/* 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)
{
/* 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();
}
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();
}
}
}
@ -177,6 +169,8 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
}
/* CLEANUP REQUEST MAP AND REMOVE INVALID TILES */
Iterator requests = this.requestMap.entrySet().iterator();
TileEntity pipe = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), this.getFacing().getOpposite());
while (requests.hasNext())
{
Entry<TileEntityConstructionPump, LiquidStack> entry = (Entry<TileEntityConstructionPump, LiquidStack>) requests.next();
@ -189,6 +183,10 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
{
requests.remove();
}
else if (pipe instanceof IFluidNetworkPart && !((IFluidNetworkPart) pipe).getNetwork().isConnected(entry.getKey()))
{
requests.remove();
}
}
/* CLEANUP TARGET LIST AND REMOVE INVALID SOURCES */
Iterator mn = this.targetSources.iterator();