From 2ffcabd4105ef8b9fe83fe0e2facdef3186b097d Mon Sep 17 00:00:00 2001 From: Robert Seifert Date: Thu, 16 May 2013 12:03:29 -0400 Subject: [PATCH] Fixed pump crash and power issues --- .../pump/TileEntityConstructionPump.java | 8 +- .../common/pump/TileEntityDrain.java | 44 ++++++---- .../common/pump/TileEntityStarterPump.java | 4 +- .../common/pump/path/LiquidPathFinder.java | 82 ++++++++++--------- 4 files changed, 78 insertions(+), 60 deletions(-) diff --git a/src/minecraft/fluidmech/common/pump/TileEntityConstructionPump.java b/src/minecraft/fluidmech/common/pump/TileEntityConstructionPump.java index bcce9321..c85c81b1 100644 --- a/src/minecraft/fluidmech/common/pump/TileEntityConstructionPump.java +++ b/src/minecraft/fluidmech/common/pump/TileEntityConstructionPump.java @@ -13,10 +13,10 @@ import net.minecraftforge.liquids.LiquidTank; import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.VectorHelper; -import universalelectricity.prefab.tile.TileEntityElectricityRunnable; import dark.library.helpers.MetaGroup; +import dark.library.machine.TileEntityRunnableMachine; -public class TileEntityConstructionPump extends TileEntityElectricityRunnable implements ITankContainer, IPipeConnection +public class TileEntityConstructionPump extends TileEntityRunnableMachine implements ITankContainer, IPipeConnection { /* ENERGY PER TICK TO TRY TO PUMP */ public static final double WATTS_PER_TICK = 100; @@ -121,9 +121,9 @@ public class TileEntityConstructionPump extends TileEntityElectricityRunnable im TileEntity entity = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), getFacing(false)); if (entity instanceof ITankContainer) { - return ((ITankContainer) entity).fill(getFacing(false).getOpposite(), resource, doFill); + //return ((ITankContainer) entity).fill(getFacing(false).getOpposite(), resource, doFill); } - return 0; + return resource.amount; } @Override diff --git a/src/minecraft/fluidmech/common/pump/TileEntityDrain.java b/src/minecraft/fluidmech/common/pump/TileEntityDrain.java index 62059a07..e58f1914 100644 --- a/src/minecraft/fluidmech/common/pump/TileEntityDrain.java +++ b/src/minecraft/fluidmech/common/pump/TileEntityDrain.java @@ -37,13 +37,21 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta private List targetSources = new ArrayList(); private List updateQue = new ArrayList(); - private LiquidPathFinder pathFinder = new LiquidPathFinder(this.worldObj, false, TileEntityDrain.MAX_WORLD_EDITS_PER_PROCESS * 2); + private LiquidPathFinder pathFinder; + @Override public String getMeterReading(EntityPlayer user, ForgeDirection side) { return "Set to " + (canDrainSources() ? "input liquids" : "output liquids"); } + @Override + public void invalidate() + { + super.invalidate(); + pathFinder = new LiquidPathFinder(this.worldObj, false, TileEntityDrain.MAX_WORLD_EDITS_PER_PROCESS * 2); + } + public boolean canDrainSources() { int meta = 0; @@ -71,6 +79,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta @Override public void updateEntity() { + super.updateEntity(); /* MAIN LOGIC PATH FOR DRAINING BODIES OF LIQUID */ if (!this.worldObj.isRemote && this.ticks % 30 == 0) { @@ -94,7 +103,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta Iterator it = this.targetSources.iterator(); while (it.hasNext()) { - Vector3 loc = (Vector3) it.next(); + Vector3 loc = it.next(); if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS) { break; @@ -146,7 +155,11 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta * Finds more liquid blocks using a path finder to be drained */ public void getNextFluidBlock() - { + { + if (pathFinder == null) + { + pathFinder = new LiquidPathFinder(this.worldObj, false, TileEntityDrain.MAX_WORLD_EDITS_PER_PROCESS * 2); + } pathFinder.reset(); pathFinder.init(new Vector3(this.xCoord + this.getFacing().offsetX, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ)); // System.out.println("Nodes:" + pathFinder.nodes.size() + "Results:" + @@ -157,6 +170,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta } } + @SuppressWarnings("unchecked") public void doCleanup() { /* CALL UPDATE ON EDITED BLOCKS */ @@ -166,7 +180,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta int up = 0; while (pp.hasNext() && up < TileEntityDrain.MAX_WORLD_EDITS_PER_PROCESS) { - Vector3 vec = (Vector3) pp.next(); + Vector3 vec = pp.next(); worldObj.notifyBlockChange(vec.intX(), vec.intY(), vec.intZ(), vec.getBlockID(this.worldObj)); worldObj.notifyBlockOfNeighborChange(vec.intX(), vec.intY(), vec.intZ(), vec.getBlockID(this.worldObj)); pp.remove(); @@ -195,10 +209,10 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta } } /* CLEANUP TARGET LIST AND REMOVE INVALID SOURCES */ - Iterator mn = this.targetSources.iterator(); + Iterator mn = this.targetSources.iterator(); while (mn.hasNext()) { - Vector3 vec = (Vector3) mn.next(); + Vector3 vec = mn.next(); if (!FluidHelper.isSourceBlock(this.worldObj, vec)) { mn.remove(); @@ -219,20 +233,20 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta { return 0; } - Vector3 a = (Vector3) o1; - Vector3 b = (Vector3) o2; - double da = Vector3.distance(a, faceVec); - double db = Vector3.distance(b, faceVec); - ; - if (a.equals(b)) + Vector3 first = (Vector3) o1; + Vector3 second = (Vector3) o2; + double firstDistance = Vector3.distance(first, faceVec); + double secondDistance = Vector3.distance(second, faceVec); + if (first.equals(second)) { return 0; } - if (Integer.compare(b.intY(), a.intY()) != 0) + int cc = Integer.compare(second.intY(), first.intY()); + if (cc != 0) { - return Integer.compare(b.intY(), a.intY()); + return cc; } - return Double.compare(da, db); + return Double.compare(secondDistance,firstDistance); } }); } diff --git a/src/minecraft/fluidmech/common/pump/TileEntityStarterPump.java b/src/minecraft/fluidmech/common/pump/TileEntityStarterPump.java index 636d9cc1..3950d55b 100644 --- a/src/minecraft/fluidmech/common/pump/TileEntityStarterPump.java +++ b/src/minecraft/fluidmech/common/pump/TileEntityStarterPump.java @@ -17,13 +17,13 @@ import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.VectorHelper; import universalelectricity.prefab.network.IPacketReceiver; -import universalelectricity.prefab.tile.TileEntityElectricityRunnable; import com.google.common.io.ByteArrayDataInput; import dark.library.helpers.MetaGroup; +import dark.library.machine.TileEntityRunnableMachine; -public class TileEntityStarterPump extends TileEntityElectricityRunnable implements IPacketReceiver, IReadOut, IPipeConnection +public class TileEntityStarterPump extends TileEntityRunnableMachine implements IPacketReceiver, IReadOut, IPipeConnection { public final double WATTS_PER_TICK = (400 / 20); private double percentPumped = 0.0; diff --git a/src/minecraft/fluidmech/common/pump/path/LiquidPathFinder.java b/src/minecraft/fluidmech/common/pump/path/LiquidPathFinder.java index 32a1bf7c..6e326727 100644 --- a/src/minecraft/fluidmech/common/pump/path/LiquidPathFinder.java +++ b/src/minecraft/fluidmech/common/pump/path/LiquidPathFinder.java @@ -44,59 +44,63 @@ public class LiquidPathFinder /** * @return True on success finding, false on failure. */ - public boolean findNodes(Vector3 node) - { - Vector3 vec = node.clone(); - - Chunk chunk = this.world.getChunkFromBlockCoords(vec.intX(), vec.intZ()); - - if (!chunk.isChunkLoaded) - { - return true; - }else + public boolean findNodes(final Vector3 node) + { + try { + Vector3 vec = node.clone(); this.nodes.add(node); - } - - int id = node.getBlockID(world); - int meta = node.getBlockID(world); - if (this.fill && (id == 0 || (FluidHelper.getLiquidFromBlockId(id) != null && meta != 0))) - { - this.results.add(node); - } - else if (!this.fill && FluidHelper.isSourceBlock(world, node)) - { - this.results.add(node); - } + Chunk chunk = this.world.getChunkFromBlockCoords(vec.intX(), vec.intZ()); - if (this.isDone(node)) - { - return false; - } - - vec = node.clone().modifyPositionFromSide(this.priority); - if (this.isValidNode(vec) & !this.nodes.contains(vec)) - { - if (this.findNodes(vec)) + if (chunk == null || !chunk.isChunkLoaded) { return true; } - } - for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) - { - if (direction != this.priority) + int id = node.getBlockID(world); + int meta = node.getBlockID(world); + if (this.fill && (id == 0 || (FluidHelper.getLiquidFromBlockId(id) != null && meta != 0))) { - vec = node.clone().modifyPositionFromSide(direction); - if (this.isValidNode(vec) & !this.nodes.contains(vec)) + this.results.add(node); + } + else if (!this.fill && FluidHelper.isSourceBlock(world, node)) + { + this.results.add(node); + } + + if (this.isDone(node)) + { + return false; + } + + vec = node.clone().modifyPositionFromSide(this.priority); + if (this.isValidNode(vec) & !this.nodes.contains(vec)) + { + if (this.findNodes(vec)) { - if (this.findNodes(vec)) + return true; + } + } + + for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) + { + if (direction != this.priority) + { + vec = node.clone().modifyPositionFromSide(direction); + if (this.isValidNode(vec) & !this.nodes.contains(vec)) { - return true; + if (this.findNodes(vec)) + { + return true; + } } } } } + catch (Exception e) + { + e.printStackTrace(); + } return false; }