Adding fill world handling for drain

doesn't work at all but the ideal is there at least
This commit is contained in:
Rseifert 2013-04-07 04:54:44 -04:00
parent 66a1502bf4
commit 3063368d31
4 changed files with 135 additions and 11 deletions

View file

@ -1,5 +1,8 @@
package fluidmech.common.pump;
import fluidmech.common.pump.path.PathfinderCheckerFindAir;
import fluidmech.common.pump.path.PathfinderCheckerLiquid;
import fluidmech.common.pump.path.PathfinderFindHighestSource;
import hydraulic.api.IDrain;
import hydraulic.fluidnetwork.IFluidNetworkPart;
import hydraulic.helpers.FluidHelper;
@ -16,15 +19,18 @@ import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquid;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper;
public class TileEntityDrain extends TileEntityFluidDevice implements ITankContainer, IDrain
{
private boolean drainSources = true;
private boolean drainSources = false;
/* MAX BLOCKS DRAINED PER 1/2 SECOND */
public static int MAX_DRAIN_PER_PROCESS = 30;
private int currentDrains = 0;
@ -56,7 +62,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
if (!this.worldObj.isRemote)
{
if (this.ticks % (200 + new Random().nextInt(100)) == 0 && updateQue.size() > 0 )
if (this.ticks % (200 + new Random().nextInt(100)) == 0 && updateQue.size() > 0)
{
Iterator pp = this.updateQue.iterator();
while (pp.hasNext())
@ -158,11 +164,63 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
}
@Override
public int fillArea(LiquidStack stack, boolean doFill)
public int fillArea(LiquidStack resource, boolean doFill)
{
if (!this.drainSources)
{
System.out.println("Filling Area: " + doFill);
if (resource == null || resource.amount < LiquidContainerRegistry.BUCKET_VOLUME || !(Block.blocksList[resource.itemID] instanceof ILiquid))
{
System.out.println("Invalid Resource");
return 0;
}
System.out.println("Resource: " + LiquidDictionary.findLiquidName(resource) + ":" + resource.amount);
ILiquid liquidBlock = (ILiquid) Block.blocksList[resource.itemID];
int drained = 0;
int blocks = (resource.amount / LiquidContainerRegistry.BUCKET_VOLUME);
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));
System.out.println("Nodes: " + pathFinder.closedSet.size());
for (Vector3 loc : pathFinder.closedSet)
{
if (blocks <= 0)
{
break;
}
LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(worldObj));
if (stack != null && stack.isLiquidEqual(resource) && loc.getBlockMetadata(worldObj) != 0)
{
drained += LiquidContainerRegistry.BUCKET_VOLUME;
blocks--;
if (doFill)
{
System.out.println("PlacedAt:Flowing: "+loc.toString());
loc.setBlock(worldObj, liquidBlock.stillLiquidId(), liquidBlock.stillLiquidMeta(), 2);
}
}
}
for (Vector3 loc : pathFinder.closedSet)
{
if (blocks <= 0)
{
break;
}
if (loc.getBlockID(worldObj) == 0)
{
drained += LiquidContainerRegistry.BUCKET_VOLUME;
blocks--;
if (doFill)
{
System.out.println("PlacedAt:Air: "+loc.toString());
loc.setBlock(worldObj, liquidBlock.stillLiquidId(), liquidBlock.stillLiquidMeta(), 2);
}
}
}
}
return 0;
}
@ -201,7 +259,6 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
*/
public void getNextFluidBlock()
{
System.out.println("Before Targets:" + this.targetSources.size());
/* FIND HIGHEST DRAIN POINT FIRST */
PathfinderFindHighestSource path = new PathfinderFindHighestSource(this.worldObj, null);
path.init(new Vector3(this.xCoord + this.getFacing().offsetX, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ));
@ -217,13 +274,12 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
this.targetSources.add(loc);
}
}
System.out.println("Targets:" + this.targetSources.size());
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (this.drainSources || from != this.getFacing().getOpposite())
if (this.drainSources)
{
return 0;
}

View file

@ -0,0 +1,70 @@
package fluidmech.common.pump.path;
import fluidmech.common.FluidMech;
import fluidmech.common.pump.TileEntityDrain;
import hydraulic.helpers.FluidHelper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidStack;
import universalelectricity.core.path.IPathCallBack;
import universalelectricity.core.path.Pathfinder;
import universalelectricity.core.vector.Vector3;
public class PathfinderCheckerFindAir extends Pathfinder
{
public List<Vector3> targetList = new ArrayList<Vector3>();
public PathfinderCheckerFindAir(final World world)
{
super(new IPathCallBack()
{
@Override
public Set<Vector3> getConnectedNodes(Pathfinder finder, Vector3 currentNode)
{
Set<Vector3> neighbors = new HashSet<Vector3>();
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if (direction != ForgeDirection.UP)
{
Vector3 pos = currentNode.clone().modifyPositionFromSide(direction);
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
if (liquid != null || pos.getBlockID(world) == 0)
{
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;
}
@Override
public boolean onSearch(Pathfinder finder, Vector3 node)
{
if (finder.closedSet.size() >= 2000)
{
return true;
}
return false;
}
});
}
}

View file

@ -1,6 +1,7 @@
package fluidmech.common.pump;
package fluidmech.common.pump.path;
import fluidmech.common.FluidMech;
import fluidmech.common.pump.TileEntityDrain;
import hydraulic.helpers.FluidHelper;
import java.util.ArrayList;
@ -28,17 +29,14 @@ public class PathfinderCheckerLiquid extends Pathfinder
@Override
public Set<Vector3> getConnectedNodes(Pathfinder finder, Vector3 currentNode)
{
//System.out.println("AN:" + currentNode.toString());
Set<Vector3> neighbors = new HashSet<Vector3>();
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
Vector3 pos = currentNode.clone().modifyPositionFromSide(direction);
//System.out.println("AN:" + direction.ordinal() + ":" + pos.toString() + " " + pos.getBlockID(world) + ":" + pos.getBlockMetadata(world));
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
if (pos.getBlockID(world) != 0 && liquid != null && (liquid.equals(resource) || resource == null))
{
//System.out.println("ADD:" + pos.toString());
neighbors.add(pos);
}
}

View file

@ -1,4 +1,4 @@
package fluidmech.common.pump;
package fluidmech.common.pump.path;
import fluidmech.common.FluidMech;
import hydraulic.helpers.FluidHelper;