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:
parent
e02f404d55
commit
b63526ddaf
5 changed files with 78 additions and 44 deletions
|
@ -1,8 +1,5 @@
|
||||||
package fluidmech.common.pump;
|
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.block.material.Material;
|
||||||
import net.minecraft.client.renderer.texture.IconRegister;
|
import net.minecraft.client.renderer.texture.IconRegister;
|
||||||
import net.minecraft.entity.EntityLiving;
|
import net.minecraft.entity.EntityLiving;
|
||||||
|
@ -15,12 +12,14 @@ import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import universalelectricity.prefab.block.BlockAdvanced;
|
import universalelectricity.prefab.block.BlockAdvanced;
|
||||||
|
import fluidmech.common.FluidMech;
|
||||||
|
import fluidmech.common.TabFluidMech;
|
||||||
|
|
||||||
public class BlockDrain extends BlockAdvanced
|
public class BlockDrain extends BlockAdvanced
|
||||||
{
|
{
|
||||||
private Icon blockIcon;
|
private Icon blockIcon;
|
||||||
private Icon drainIcon;
|
private Icon drainIcon;
|
||||||
private Icon drainIcon2;
|
private Icon fillIcon;
|
||||||
public BlockDrain(int id)
|
public BlockDrain(int id)
|
||||||
{
|
{
|
||||||
super(id, Material.iron);
|
super(id, Material.iron);
|
||||||
|
@ -35,7 +34,7 @@ public class BlockDrain extends BlockAdvanced
|
||||||
{
|
{
|
||||||
this.blockIcon = par1IconRegister.registerIcon(FluidMech.TEXTURE_NAME_PREFIX + "ironMachineSide");
|
this.blockIcon = par1IconRegister.registerIcon(FluidMech.TEXTURE_NAME_PREFIX + "ironMachineSide");
|
||||||
this.drainIcon = par1IconRegister.registerIcon(FluidMech.TEXTURE_NAME_PREFIX + "drain");
|
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
|
@Override
|
||||||
|
@ -65,7 +64,7 @@ public class BlockDrain extends BlockAdvanced
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return this.drainIcon2;
|
return this.fillIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -95,6 +94,12 @@ public class BlockDrain extends BlockAdvanced
|
||||||
meta -= 6;
|
meta -= 6;
|
||||||
}
|
}
|
||||||
world.setBlockMetadataWithNotify(x, y, z, meta, 3);
|
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;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package fluidmech.common.pump;
|
package fluidmech.common.pump;
|
||||||
|
|
||||||
import fluidmech.common.FluidMech;
|
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.PathfinderCheckerLiquid;
|
||||||
import fluidmech.common.pump.path.PathfinderFindHighestSource;
|
import fluidmech.common.pump.path.PathfinderFindHighestSource;
|
||||||
import hydraulic.api.IDrain;
|
import hydraulic.api.IDrain;
|
||||||
|
@ -35,7 +35,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;
|
public 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>();
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
|
||||||
|
|
||||||
if (!this.worldObj.isRemote)
|
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();
|
Iterator pp = this.updateQue.iterator();
|
||||||
while (pp.hasNext())
|
while (pp.hasNext())
|
||||||
|
@ -134,7 +134,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FluidHelper.isLiquidBlock(this.worldObj, loc))
|
if (FluidHelper.isSourceBlock(this.worldObj, loc))
|
||||||
{
|
{
|
||||||
LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(this.worldObj));
|
LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(this.worldObj));
|
||||||
LiquidStack requestStack = request.getValue();
|
LiquidStack requestStack = request.getValue();
|
||||||
|
@ -222,8 +222,8 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
|
||||||
|
|
||||||
int blocks = (resource.amount / LiquidContainerRegistry.BUCKET_VOLUME);
|
int blocks = (resource.amount / LiquidContainerRegistry.BUCKET_VOLUME);
|
||||||
|
|
||||||
PathfinderCheckerFindAir pathFinder = new PathfinderCheckerFindAir(this.worldObj);
|
PathfinderCheckerFindFillable pathFinder = new PathfinderCheckerFindFillable(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, yFillStart, this.zCoord + this.getFacing().offsetZ));
|
||||||
System.out.println("Nodes: " + pathFinder.closedSet.size());
|
System.out.println("Nodes: " + pathFinder.closedSet.size());
|
||||||
int fillable = 0;
|
int fillable = 0;
|
||||||
for (Vector3 loc : pathFinder.closedSet)
|
for (Vector3 loc : pathFinder.closedSet)
|
||||||
|
@ -241,7 +241,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
|
||||||
if (doFill)
|
if (doFill)
|
||||||
{
|
{
|
||||||
System.out.println("PlacedAt:Flowing: " + loc.toString());
|
System.out.println("PlacedAt:Flowing: " + loc.toString());
|
||||||
loc.setBlock(worldObj, blockID, meta, 2);
|
loc.setBlock(worldObj, blockID, meta);
|
||||||
if (!this.updateQue.contains(loc))
|
if (!this.updateQue.contains(loc))
|
||||||
{
|
{
|
||||||
this.updateQue.add(loc);
|
this.updateQue.add(loc);
|
||||||
|
@ -265,7 +265,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
|
||||||
if (doFill)
|
if (doFill)
|
||||||
{
|
{
|
||||||
System.out.println("PlacedAt:Air: " + loc.toString());
|
System.out.println("PlacedAt:Air: " + loc.toString());
|
||||||
loc.setBlock(worldObj, blockID, meta, 2);
|
loc.setBlock(worldObj, blockID, meta);
|
||||||
if (!this.updateQue.contains(loc))
|
if (!this.updateQue.contains(loc))
|
||||||
{
|
{
|
||||||
this.updateQue.add(loc);
|
this.updateQue.add(loc);
|
||||||
|
|
|
@ -18,11 +18,11 @@ import universalelectricity.core.path.IPathCallBack;
|
||||||
import universalelectricity.core.path.Pathfinder;
|
import universalelectricity.core.path.Pathfinder;
|
||||||
import universalelectricity.core.vector.Vector3;
|
import universalelectricity.core.vector.Vector3;
|
||||||
|
|
||||||
public class PathfinderCheckerFindAir extends Pathfinder
|
public class PathfinderCheckerFindFillable extends Pathfinder
|
||||||
{
|
{
|
||||||
public List<Vector3> targetList = new ArrayList<Vector3>();
|
public List<Vector3> targetList = new ArrayList<Vector3>();
|
||||||
|
|
||||||
public PathfinderCheckerFindAir(final World world)
|
public PathfinderCheckerFindFillable(final World world)
|
||||||
{
|
{
|
||||||
super(new IPathCallBack()
|
super(new IPathCallBack()
|
||||||
{
|
{
|
||||||
|
@ -30,24 +30,29 @@ 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;
|
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)
|
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
if (direction != ForgeDirection.UP)
|
if (direction != ForgeDirection.UP && direction != ForgeDirection.DOWN)
|
||||||
{
|
{
|
||||||
Vector3 pos = currentNode.clone().modifyPositionFromSide(direction);
|
pos = currentNode.clone().modifyPositionFromSide(direction);
|
||||||
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
|
liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world));
|
||||||
if (liquid != null || pos.getBlockID(world) == 0)
|
if ((liquid != null || pos.getBlockID(world) == 0) && FluidHelper.getConnectedSources(world, pos) > 0)
|
||||||
{
|
{
|
||||||
if(isFillableBlock(world,pos))
|
|
||||||
{
|
|
||||||
fillable++;
|
|
||||||
}
|
|
||||||
neighbors.add(pos);
|
neighbors.add(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return neighbors;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -599,7 +599,7 @@ public class HydraulicNetwork
|
||||||
{
|
{
|
||||||
if (node != splitPoint)
|
if (node != splitPoint)
|
||||||
{
|
{
|
||||||
((IFluidNetworkPart) node).setNetwork(this);
|
((IFluidNetworkPart) entity).setNetwork(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package hydraulic.helpers;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
import net.minecraftforge.liquids.ILiquid;
|
import net.minecraftforge.liquids.ILiquid;
|
||||||
import net.minecraftforge.liquids.LiquidContainerRegistry;
|
import net.minecraftforge.liquids.LiquidContainerRegistry;
|
||||||
import net.minecraftforge.liquids.LiquidDictionary;
|
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);
|
LiquidStack liquid = FluidHelper.getLiquidFromBlockId(vec.getBlockID(world));
|
||||||
int meta = pos.getBlockMetadata(world);
|
if ((liquid != null && vec.getBlockMetadata(world) == 0))
|
||||||
int LiquidID = FluidHelper.getLiquidId(blockID);
|
|
||||||
|
|
||||||
if (LiquidID != -1 && meta == 0)
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue