From 66a1502bf4508c7e5a215277a8490d540dd9173d Mon Sep 17 00:00:00 2001 From: Rseifert Date: Sun, 7 Apr 2013 03:52:08 -0400 Subject: [PATCH] Pump works \0/ Well i still need to check using other liquids than water Also need to recode to actual put the water somewhere else Need to make models, and textures A Gui for the pump to select liquid to pump and set the volume --- .../common/pump/PathfinderCheckerLiquid.java | 8 +- ....java => PathfinderFindHighestSource.java} | 8 +- .../common/pump/TileEntityDrain.java | 128 +++++++++++------- .../fluidnetwork/HydraulicNetworkHelper.java | 3 +- 4 files changed, 91 insertions(+), 56 deletions(-) rename src/minecraft/fluidmech/common/pump/{PathfinderFindLiquid.java => PathfinderFindHighestSource.java} (81%) diff --git a/src/minecraft/fluidmech/common/pump/PathfinderCheckerLiquid.java b/src/minecraft/fluidmech/common/pump/PathfinderCheckerLiquid.java index f90d2233..05b452ee 100644 --- a/src/minecraft/fluidmech/common/pump/PathfinderCheckerLiquid.java +++ b/src/minecraft/fluidmech/common/pump/PathfinderCheckerLiquid.java @@ -28,17 +28,17 @@ public class PathfinderCheckerLiquid extends Pathfinder @Override public Set getConnectedNodes(Pathfinder finder, Vector3 currentNode) { - System.out.println("AN:" + currentNode.toString()); + //System.out.println("AN:" + currentNode.toString()); Set neighbors = new HashSet(); 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)); + //System.out.println("AN:" + direction.ordinal() + ":" + pos.toString() + " " + pos.getBlockID(world) + ":" + pos.getBlockMetadata(world)); LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world)); - if (liquid != null && (liquid.equals(resource) || resource == null)) + if (pos.getBlockID(world) != 0 && liquid != null && (liquid.equals(resource) || resource == null)) { - System.out.println("ADD:" + pos.toString()); + //System.out.println("ADD:" + pos.toString()); neighbors.add(pos); } } diff --git a/src/minecraft/fluidmech/common/pump/PathfinderFindLiquid.java b/src/minecraft/fluidmech/common/pump/PathfinderFindHighestSource.java similarity index 81% rename from src/minecraft/fluidmech/common/pump/PathfinderFindLiquid.java rename to src/minecraft/fluidmech/common/pump/PathfinderFindHighestSource.java index 82696e71..d534bea8 100644 --- a/src/minecraft/fluidmech/common/pump/PathfinderFindLiquid.java +++ b/src/minecraft/fluidmech/common/pump/PathfinderFindHighestSource.java @@ -15,11 +15,11 @@ import universalelectricity.core.path.IPathCallBack; import universalelectricity.core.path.Pathfinder; import universalelectricity.core.vector.Vector3; -public class PathfinderFindLiquid extends Pathfinder +public class PathfinderFindHighestSource extends Pathfinder { public static int highestY = 0; - public PathfinderFindLiquid(final World world, final LiquidStack resource, final Vector3... ignoreList) + public PathfinderFindHighestSource(final World world, final LiquidStack resource, final Vector3... ignoreList) { super(new IPathCallBack() { @@ -30,7 +30,7 @@ public class PathfinderFindLiquid extends Pathfinder Vector3 pos = currentNode.clone().modifyPositionFromSide(ForgeDirection.UP); LiquidStack liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world)); - if (liquid != null && (liquid.equals(resource) || resource == null)) + if (pos.getBlockID(world) != 0 && liquid != null && (liquid.equals(resource) || resource == null)) { neighbors.add(pos); if (pos.intY() > highestY) @@ -44,7 +44,7 @@ public class PathfinderFindLiquid extends Pathfinder { pos = currentNode.clone().modifyPositionFromSide(direction); liquid = FluidHelper.getLiquidFromBlockId(pos.getBlockID(world)); - if (liquid != null && (liquid.equals(resource) || resource == null)) + if (pos.getBlockID(world) != 0 && liquid != null && (liquid.equals(resource) || resource == null)) { neighbors.add(pos); if (pos.intY() > highestY) diff --git a/src/minecraft/fluidmech/common/pump/TileEntityDrain.java b/src/minecraft/fluidmech/common/pump/TileEntityDrain.java index e1f01537..f35bb107 100644 --- a/src/minecraft/fluidmech/common/pump/TileEntityDrain.java +++ b/src/minecraft/fluidmech/common/pump/TileEntityDrain.java @@ -10,6 +10,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; +import java.util.Random; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; @@ -31,6 +32,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta private HashMap requestMap = new HashMap(); private List targetSources = new ArrayList(); + private List updateQue = new ArrayList(); @Override public String getMeterReading(EntityPlayer user, ForgeDirection side) @@ -52,65 +54,97 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta public void updateEntity() { - if (!this.worldObj.isRemote && this.ticks % 10 == 0) + if (!this.worldObj.isRemote) { - this.currentDrains = 0; - /* MAIN LOGIC PATH FOR DRAINING BODIES OF LIQUID */ - if (this.drainSources) + if (this.ticks % (200 + new Random().nextInt(100)) == 0 && updateQue.size() > 0 ) { - TileEntity pipe = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), this.getFacing().getOpposite()); - - if (pipe instanceof IFluidNetworkPart) + Iterator pp = this.updateQue.iterator(); + while (pp.hasNext()) { - if (this.requestMap.size() > 0) + Vector3 vec = (Vector3) pp.next(); + worldObj.markBlockForUpdate(vec.intX(), vec.intY(), vec.intZ()); + pp.remove(); + } + } + if (this.ticks % 20 == 0) + { + /* CLEANUP MAP */ + Iterator mn = this.requestMap.entrySet().iterator(); + while (mn.hasNext()) + { + Entry entry = (Entry) mn.next(); + TileEntity entity = entry.getKey(); + if (entity == null) { - this.getNextFluidBlock(); + mn.remove(); + } + else if (entity.isInvalid()) + { + mn.remove(); + } + } - for (Entry request : requestMap.entrySet()) + this.currentDrains = 0; + /* MAIN LOGIC PATH FOR DRAINING BODIES OF LIQUID */ + if (this.drainSources) + { + TileEntity pipe = VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), this.getFacing().getOpposite()); + + if (pipe instanceof IFluidNetworkPart) + { + if (this.requestMap.size() > 0) { - if (this.currentDrains >= MAX_DRAIN_PER_PROCESS) + this.getNextFluidBlock(); + + for (Entry request : requestMap.entrySet()) { - break; - } - if (((IFluidNetworkPart) pipe).getNetwork().isConnected(request.getKey()) && targetSources.size() > 0) - { - Iterator it = this.targetSources.iterator(); - while (it.hasNext()) + if (this.currentDrains >= MAX_DRAIN_PER_PROCESS) { - Vector3 loc = (Vector3) it.next(); - if (this.currentDrains >= MAX_DRAIN_PER_PROCESS) + break; + } + if (((IFluidNetworkPart) pipe).getNetwork().isConnected(request.getKey()) && targetSources.size() > 0) + { + Iterator it = this.targetSources.iterator(); + int m = 0; + while (it.hasNext()) { - break; - } - - if (FluidHelper.isLiquidBlock(this.worldObj, loc)) - { - LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(this.worldObj)); - LiquidStack requestStack = request.getValue(); - - if (stack != null && requestStack != null && (requestStack.isLiquidEqual(stack) || requestStack.itemID == -1)) + Vector3 loc = (Vector3) it.next(); + if (this.currentDrains >= MAX_DRAIN_PER_PROCESS) { - if (request.getKey().fill(0, stack, false) > 0) + break; + } + + if (FluidHelper.isLiquidBlock(this.worldObj, loc)) + { + LiquidStack stack = FluidHelper.getLiquidFromBlockId(loc.getBlockID(this.worldObj)); + LiquidStack requestStack = request.getValue(); + + if (stack != null && requestStack != null && (requestStack.isLiquidEqual(stack) || requestStack.itemID == -1)) { - int requestAmmount = requestStack.amount - request.getKey().fill(0, stack, true); - if (requestAmmount <= 0) + if (request.getKey().fill(0, stack, false) > 0) { - this.requestMap.remove(request); - } - else - { - request.setValue(FluidHelper.getStack(requestStack, requestAmmount)); - } - - loc.setBlock(this.worldObj, 0); - this.currentDrains++; - it.remove(); + int requestAmmount = requestStack.amount - request.getKey().fill(0, stack, true); + if (requestAmmount <= 0) + { + this.requestMap.remove(request); + } + else + { + request.setValue(FluidHelper.getStack(requestStack, requestAmmount)); + } + if (++m >= 3 && !this.updateQue.contains(loc)) + { + this.updateQue.add(loc); + } + loc.setBlock(this.worldObj, 0, 0, 2); + this.currentDrains++; + it.remove(); + } } } } } - } } } @@ -153,21 +187,23 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta this.requestMap.remove(pump); } } + public void addVectorToQue(Vector3 vector) { - if(!this.targetSources.contains(vector)) + if (!this.targetSources.contains(vector)) { this.targetSources.add(vector); } } + /** * Finds more liquid blocks using a path finder to be drained */ public void getNextFluidBlock() { - System.out.println("Before Targets:"+this.targetSources.size()); + System.out.println("Before Targets:" + this.targetSources.size()); /* FIND HIGHEST DRAIN POINT FIRST */ - PathfinderFindLiquid path = new PathfinderFindLiquid(this.worldObj, null); + 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)); int y = path.highestY; @@ -181,7 +217,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta this.targetSources.add(loc); } } - System.out.println("Targets:"+this.targetSources.size()); + System.out.println("Targets:" + this.targetSources.size()); } @Override diff --git a/src/minecraft/hydraulic/fluidnetwork/HydraulicNetworkHelper.java b/src/minecraft/hydraulic/fluidnetwork/HydraulicNetworkHelper.java index f43e8185..2cc8e590 100644 --- a/src/minecraft/hydraulic/fluidnetwork/HydraulicNetworkHelper.java +++ b/src/minecraft/hydraulic/fluidnetwork/HydraulicNetworkHelper.java @@ -12,8 +12,7 @@ public class HydraulicNetworkHelper { /** - * Invalidates a TileEntity from the electrical network, thereby removing it from all - * electricity network that are adjacent to it. + * Invalidates a TileEntity */ public static void invalidate(TileEntity tileEntity) {