Drain fill area mostly done
A ton of testing is need for this to confirm that it works. However, for now its done enough to place in a release.
This commit is contained in:
parent
3063368d31
commit
5d8af57115
2 changed files with 72 additions and 23 deletions
|
@ -34,6 +34,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
|
||||||
/* MAX BLOCKS DRAINED PER 1/2 SECOND */
|
/* MAX BLOCKS DRAINED PER 1/2 SECOND */
|
||||||
public static int MAX_DRAIN_PER_PROCESS = 30;
|
public static int MAX_DRAIN_PER_PROCESS = 30;
|
||||||
private int currentDrains = 0;
|
private int currentDrains = 0;
|
||||||
|
int yFillStart = 0;
|
||||||
/* LIST OF PUMPS AND THERE REQUESTS FOR THIS DRAIN */
|
/* LIST OF PUMPS AND THERE REQUESTS FOR THIS DRAIN */
|
||||||
private HashMap<TileEntityConstructionPump, LiquidStack> requestMap = new HashMap<TileEntityConstructionPump, LiquidStack>();
|
private HashMap<TileEntityConstructionPump, LiquidStack> requestMap = new HashMap<TileEntityConstructionPump, LiquidStack>();
|
||||||
|
|
||||||
|
@ -155,10 +156,12 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}// END OF DRAIN
|
// END OF DRAIN
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO time to have fun finding a place for this block to exist
|
// TODO time to have fun finding a place for this block to exist
|
||||||
|
//this.fillArea(LiquidDictionary.getLiquid("Water", LiquidContainerRegistry.BUCKET_VOLUME * 5), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -166,24 +169,50 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
|
||||||
@Override
|
@Override
|
||||||
public int fillArea(LiquidStack resource, boolean doFill)
|
public int fillArea(LiquidStack resource, boolean doFill)
|
||||||
{
|
{
|
||||||
|
int drained = 0;
|
||||||
|
if (yFillStart == 0 || yFillStart >= 255)
|
||||||
|
{
|
||||||
|
yFillStart = this.yCoord + this.getFacing().offsetY;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.drainSources)
|
if (!this.drainSources)
|
||||||
{
|
{
|
||||||
System.out.println("Filling Area: " + doFill);
|
System.out.println("Filling Area: " + doFill);
|
||||||
if (resource == null || resource.amount < LiquidContainerRegistry.BUCKET_VOLUME || !(Block.blocksList[resource.itemID] instanceof ILiquid))
|
if (resource == null || resource.amount < LiquidContainerRegistry.BUCKET_VOLUME)
|
||||||
{
|
{
|
||||||
System.out.println("Invalid Resource");
|
System.out.println("Invalid Resource");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
System.out.println("Resource: " + LiquidDictionary.findLiquidName(resource) + ":" + resource.amount);
|
System.out.println("Resource: " + LiquidDictionary.findLiquidName(resource) + ":" + resource.amount);
|
||||||
|
int blockID = resource.itemID;
|
||||||
ILiquid liquidBlock = (ILiquid) Block.blocksList[resource.itemID];
|
int meta = resource.itemMeta;
|
||||||
|
if (resource.itemID == Block.waterStill.blockID)
|
||||||
int drained = 0;
|
{
|
||||||
|
blockID = Block.waterStill.blockID;
|
||||||
|
meta = 0;
|
||||||
|
}
|
||||||
|
else if (resource.itemID != Block.lavaStill.blockID)
|
||||||
|
{
|
||||||
|
blockID = Block.lavaStill.blockID;
|
||||||
|
meta = 0;
|
||||||
|
}
|
||||||
|
else if (Block.blocksList[resource.itemID] instanceof ILiquid)
|
||||||
|
{
|
||||||
|
ILiquid liquidBlock = (ILiquid) Block.blocksList[resource.itemID];
|
||||||
|
blockID = liquidBlock.stillLiquidId();
|
||||||
|
meta = liquidBlock.stillLiquidMeta();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int blocks = (resource.amount / LiquidContainerRegistry.BUCKET_VOLUME);
|
int blocks = (resource.amount / LiquidContainerRegistry.BUCKET_VOLUME);
|
||||||
|
|
||||||
PathfinderCheckerFindAir pathFinder = new PathfinderCheckerFindAir(this.worldObj);
|
PathfinderCheckerFindAir pathFinder = new PathfinderCheckerFindAir(this.worldObj);
|
||||||
pathFinder.init(new Vector3(this.xCoord + this.getFacing().offsetX, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ));
|
pathFinder.init(new Vector3(this.xCoord + this.getFacing().offsetX, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ));
|
||||||
System.out.println("Nodes: " + pathFinder.closedSet.size());
|
System.out.println("Nodes: " + pathFinder.closedSet.size());
|
||||||
|
int fillable = 0;
|
||||||
for (Vector3 loc : pathFinder.closedSet)
|
for (Vector3 loc : pathFinder.closedSet)
|
||||||
{
|
{
|
||||||
if (blocks <= 0)
|
if (blocks <= 0)
|
||||||
|
@ -193,12 +222,17 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
|
||||||
LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(worldObj));
|
LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(worldObj));
|
||||||
if (stack != null && stack.isLiquidEqual(resource) && loc.getBlockMetadata(worldObj) != 0)
|
if (stack != null && stack.isLiquidEqual(resource) && loc.getBlockMetadata(worldObj) != 0)
|
||||||
{
|
{
|
||||||
|
fillable++;
|
||||||
drained += LiquidContainerRegistry.BUCKET_VOLUME;
|
drained += LiquidContainerRegistry.BUCKET_VOLUME;
|
||||||
blocks--;
|
blocks--;
|
||||||
if (doFill)
|
if (doFill)
|
||||||
{
|
{
|
||||||
System.out.println("PlacedAt:Flowing: "+loc.toString());
|
System.out.println("PlacedAt:Flowing: " + loc.toString());
|
||||||
loc.setBlock(worldObj, liquidBlock.stillLiquidId(), liquidBlock.stillLiquidMeta(), 2);
|
loc.setBlock(worldObj, blockID, meta, 2);
|
||||||
|
if (!this.updateQue.contains(loc))
|
||||||
|
{
|
||||||
|
this.updateQue.add(loc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,17 +246,26 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
|
||||||
}
|
}
|
||||||
if (loc.getBlockID(worldObj) == 0)
|
if (loc.getBlockID(worldObj) == 0)
|
||||||
{
|
{
|
||||||
|
fillable++;
|
||||||
drained += LiquidContainerRegistry.BUCKET_VOLUME;
|
drained += LiquidContainerRegistry.BUCKET_VOLUME;
|
||||||
blocks--;
|
blocks--;
|
||||||
if (doFill)
|
if (doFill)
|
||||||
{
|
{
|
||||||
System.out.println("PlacedAt:Air: "+loc.toString());
|
System.out.println("PlacedAt:Air: " + loc.toString());
|
||||||
loc.setBlock(worldObj, liquidBlock.stillLiquidId(), liquidBlock.stillLiquidMeta(), 2);
|
loc.setBlock(worldObj, blockID, meta, 2);
|
||||||
|
if (!this.updateQue.contains(loc))
|
||||||
|
{
|
||||||
|
this.updateQue.add(loc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (fillable == 0)
|
||||||
|
{
|
||||||
|
this.yFillStart++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return drained;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class PathfinderCheckerFindAir extends Pathfinder
|
||||||
public Set<Vector3> getConnectedNodes(Pathfinder finder, Vector3 currentNode)
|
public Set<Vector3> getConnectedNodes(Pathfinder finder, Vector3 currentNode)
|
||||||
{
|
{
|
||||||
Set<Vector3> neighbors = new HashSet<Vector3>();
|
Set<Vector3> neighbors = new HashSet<Vector3>();
|
||||||
|
int fillable = 0;
|
||||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
if (direction != ForgeDirection.UP)
|
if (direction != ForgeDirection.UP)
|
||||||
|
@ -38,19 +39,14 @@ public class PathfinderCheckerFindAir extends Pathfinder
|
||||||
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
|
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
|
||||||
if (liquid != null || pos.getBlockID(world) == 0)
|
if (liquid != null || pos.getBlockID(world) == 0)
|
||||||
{
|
{
|
||||||
|
if(isFillableBlock(world,pos))
|
||||||
|
{
|
||||||
|
fillable++;
|
||||||
|
}
|
||||||
neighbors.add(pos);
|
neighbors.add(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(neighbors.size() == 0)
|
|
||||||
{
|
|
||||||
Vector3 pos = currentNode.clone().modifyPositionFromSide(ForgeDirection.UP);
|
|
||||||
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
|
|
||||||
if (liquid != null || pos.getBlockID(world) == 0)
|
|
||||||
{
|
|
||||||
neighbors.add(pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return neighbors;
|
return neighbors;
|
||||||
}
|
}
|
||||||
|
@ -67,4 +63,14 @@ public class PathfinderCheckerFindAir extends Pathfinder
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isFillableBlock(World world, Vector3 vec)
|
||||||
|
{
|
||||||
|
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(vec.getBlockID(world));
|
||||||
|
if ((liquid != null && vec.getBlockMetadata(world) != 0) || vec.getBlockID(world) == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue