diff --git a/src/minecraft/fluidmech/common/pump/BlockDrain.java b/src/minecraft/fluidmech/common/pump/BlockDrain.java index f4850323..7591360f 100644 --- a/src/minecraft/fluidmech/common/pump/BlockDrain.java +++ b/src/minecraft/fluidmech/common/pump/BlockDrain.java @@ -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; diff --git a/src/minecraft/fluidmech/common/pump/TileEntityDrain.java b/src/minecraft/fluidmech/common/pump/TileEntityDrain.java index 50d636c6..a883e59f 100644 --- a/src/minecraft/fluidmech/common/pump/TileEntityDrain.java +++ b/src/minecraft/fluidmech/common/pump/TileEntityDrain.java @@ -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 requestMap = new HashMap(); @@ -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); diff --git a/src/minecraft/fluidmech/common/pump/path/PathfinderCheckerFindAir.java b/src/minecraft/fluidmech/common/pump/path/PathfinderCheckerFindFillable.java similarity index 57% rename from src/minecraft/fluidmech/common/pump/path/PathfinderCheckerFindAir.java rename to src/minecraft/fluidmech/common/pump/path/PathfinderCheckerFindFillable.java index 121e21e9..3f56e7bf 100644 --- a/src/minecraft/fluidmech/common/pump/path/PathfinderCheckerFindAir.java +++ b/src/minecraft/fluidmech/common/pump/path/PathfinderCheckerFindFillable.java @@ -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 targetList = new ArrayList(); - public PathfinderCheckerFindAir(final World world) + public PathfinderCheckerFindFillable(final World world) { super(new IPathCallBack() { @@ -30,24 +30,29 @@ public class PathfinderCheckerFindAir extends Pathfinder public Set getConnectedNodes(Pathfinder finder, Vector3 currentNode) { Set neighbors = new HashSet(); - 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; - } + } diff --git a/src/minecraft/hydraulic/fluidnetwork/HydraulicNetwork.java b/src/minecraft/hydraulic/fluidnetwork/HydraulicNetwork.java index 59e307ee..8e989ce3 100644 --- a/src/minecraft/hydraulic/fluidnetwork/HydraulicNetwork.java +++ b/src/minecraft/hydraulic/fluidnetwork/HydraulicNetwork.java @@ -599,7 +599,7 @@ public class HydraulicNetwork { if (node != splitPoint) { - ((IFluidNetworkPart) node).setNetwork(this); + ((IFluidNetworkPart) entity).setNetwork(this); } } } diff --git a/src/minecraft/hydraulic/helpers/FluidHelper.java b/src/minecraft/hydraulic/helpers/FluidHelper.java index 403a7034..5fa1a8bf 100644 --- a/src/minecraft/hydraulic/helpers/FluidHelper.java +++ b/src/minecraft/hydraulic/helpers/FluidHelper.java @@ -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; + } }