Fixed up drain fill world

Made the path finder work better and stop filling block out of range of
the water it was filling in.
This commit is contained in:
Rseifert 2013-04-07 21:07:06 -04:00
parent e02f404d55
commit b63526ddaf
5 changed files with 78 additions and 44 deletions

View file

@ -1,8 +1,5 @@
package fluidmech.common.pump;
import fluidmech.common.FluidMech;
import fluidmech.common.TabFluidMech;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.EntityLiving;
@ -15,12 +12,14 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.prefab.block.BlockAdvanced;
import fluidmech.common.FluidMech;
import fluidmech.common.TabFluidMech;
public class BlockDrain extends BlockAdvanced
{
private Icon blockIcon;
private Icon drainIcon;
private Icon drainIcon2;
private Icon fillIcon;
public BlockDrain(int id)
{
super(id, Material.iron);
@ -35,7 +34,7 @@ public class BlockDrain extends BlockAdvanced
{
this.blockIcon = par1IconRegister.registerIcon(FluidMech.TEXTURE_NAME_PREFIX + "ironMachineSide");
this.drainIcon = par1IconRegister.registerIcon(FluidMech.TEXTURE_NAME_PREFIX + "drain");
this.drainIcon2 = par1IconRegister.registerIcon(FluidMech.TEXTURE_NAME_PREFIX + "drain2");
this.fillIcon = par1IconRegister.registerIcon(FluidMech.TEXTURE_NAME_PREFIX + "drain2");
}
@Override
@ -65,7 +64,7 @@ public class BlockDrain extends BlockAdvanced
}
else
{
return this.drainIcon2;
return this.fillIcon;
}
}
@ -95,6 +94,12 @@ public class BlockDrain extends BlockAdvanced
meta -= 6;
}
world.setBlockMetadataWithNotify(x, y, z, meta, 3);
TileEntity entity = world.getBlockTileEntity(x, y, z);
if(entity instanceof TileEntityDrain)
{
entityPlayer.sendChatToPlayer("Draining Sources? " + ((TileEntityDrain) entity).canDrainSources());
}
return true;
}
return true;

View file

@ -1,7 +1,7 @@
package fluidmech.common.pump;
import fluidmech.common.FluidMech;
import fluidmech.common.pump.path.PathfinderCheckerFindAir;
import fluidmech.common.pump.path.PathfinderCheckerFindFillable;
import fluidmech.common.pump.path.PathfinderCheckerLiquid;
import fluidmech.common.pump.path.PathfinderFindHighestSource;
import hydraulic.api.IDrain;
@ -35,7 +35,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
/* MAX BLOCKS DRAINED PER 1/2 SECOND */
public static int MAX_DRAIN_PER_PROCESS = 30;
private int currentDrains = 0;
int yFillStart = 0;
public int yFillStart = 0;
/* LIST OF PUMPS AND THERE REQUESTS FOR THIS DRAIN */
private HashMap<TileEntityConstructionPump, LiquidStack> requestMap = new HashMap<TileEntityConstructionPump, LiquidStack>();
@ -76,7 +76,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 % (20 + new Random().nextInt(100)) == 0 && updateQue.size() > 0)
{
Iterator pp = this.updateQue.iterator();
while (pp.hasNext())
@ -134,7 +134,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
break;
}
if (FluidHelper.isLiquidBlock(this.worldObj, loc))
if (FluidHelper.isSourceBlock(this.worldObj, loc))
{
LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(this.worldObj));
LiquidStack requestStack = request.getValue();
@ -222,8 +222,8 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
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));
PathfinderCheckerFindFillable pathFinder = new PathfinderCheckerFindFillable(this.worldObj);
pathFinder.init(new Vector3(this.xCoord + this.getFacing().offsetX, yFillStart, this.zCoord + this.getFacing().offsetZ));
System.out.println("Nodes: " + pathFinder.closedSet.size());
int fillable = 0;
for (Vector3 loc : pathFinder.closedSet)
@ -241,7 +241,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
if (doFill)
{
System.out.println("PlacedAt:Flowing: " + loc.toString());
loc.setBlock(worldObj, blockID, meta, 2);
loc.setBlock(worldObj, blockID, meta);
if (!this.updateQue.contains(loc))
{
this.updateQue.add(loc);
@ -265,7 +265,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
if (doFill)
{
System.out.println("PlacedAt:Air: " + loc.toString());
loc.setBlock(worldObj, blockID, meta, 2);
loc.setBlock(worldObj, blockID, meta);
if (!this.updateQue.contains(loc))
{
this.updateQue.add(loc);

View file

@ -18,11 +18,11 @@ import universalelectricity.core.path.IPathCallBack;
import universalelectricity.core.path.Pathfinder;
import universalelectricity.core.vector.Vector3;
public class PathfinderCheckerFindAir extends Pathfinder
public class PathfinderCheckerFindFillable extends Pathfinder
{
public List<Vector3> targetList = new ArrayList<Vector3>();
public PathfinderCheckerFindAir(final World world)
public PathfinderCheckerFindFillable(final World world)
{
super(new IPathCallBack()
{
@ -30,24 +30,29 @@ public class PathfinderCheckerFindAir extends Pathfinder
public Set<Vector3> getConnectedNodes(Pathfinder finder, Vector3 currentNode)
{
Set<Vector3> neighbors = new HashSet<Vector3>();
int fillable = 0;
int sources = 0;
Vector3 pos = currentNode.clone().modifyPositionFromSide(ForgeDirection.DOWN);
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
/* SEARCH DOWN */
if ((liquid != null || pos.getBlockID(world) == 0) && FluidHelper.getConnectedSources(world, pos) > 0)
{
neighbors.add(pos);
return neighbors;
}
/* SEARCH AROUND - UP SEARCH IS DONE BY THE OBJECT USING THIS PATHFINDER */
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if (direction != ForgeDirection.UP)
if (direction != ForgeDirection.UP && direction != ForgeDirection.DOWN)
{
Vector3 pos = currentNode.clone().modifyPositionFromSide(direction);
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
if (liquid != null || pos.getBlockID(world) == 0)
pos = currentNode.clone().modifyPositionFromSide(direction);
liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
if ((liquid != null || pos.getBlockID(world) == 0) && FluidHelper.getConnectedSources(world, pos) > 0)
{
if(isFillableBlock(world,pos))
{
fillable++;
}
neighbors.add(pos);
}
}
}
return neighbors;
}
@ -64,13 +69,5 @@ 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;
}
}

View file

@ -599,7 +599,7 @@ public class HydraulicNetwork
{
if (node != splitPoint)
{
((IFluidNetworkPart) node).setNetwork(this);
((IFluidNetworkPart) entity).setNetwork(this);
}
}
}

View file

@ -3,6 +3,7 @@ package hydraulic.helpers;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquid;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidDictionary;
@ -136,19 +137,50 @@ public class FluidHelper
}
/**
* is block at the location is a still source block
*
* Is the location a liquid source block
*/
public static boolean isLiquidBlock(World world, Vector3 pos)
public static boolean isSourceBlock(World world, Vector3 vec)
{
int blockID = pos.getBlockID(world);
int meta = pos.getBlockMetadata(world);
int LiquidID = FluidHelper.getLiquidId(blockID);
if (LiquidID != -1 && meta == 0)
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(vec.getBlockID(world));
if ((liquid != null && vec.getBlockMetadata(world) == 0))
{
return true;
}
return false;
}
/**
* Gets the number of source liquids blocks around the locaiton
*/
public static int getConnectedSources(World world, Vector3 vec)
{
int sources = 0;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
Vector3 pos = vec.clone().modifyPositionFromSide(direction);
if (isSourceBlock(world, pos))
{
sources++;
}
}
return sources;
}
/**
* Gets the number of liquid fillable blocks around the location
*/
public static int getConnectedFillables(World world, Vector3 vec)
{
int sources = 0;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
Vector3 pos = vec.clone().modifyPositionFromSide(direction);
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
if ((liquid != null || pos.getBlockID(world) == 0) && getConnectedSources(world, pos) > 0)
{
sources++;
}
}
return sources;
}
}