Fixed pump crash and power issues

This commit is contained in:
Robert Seifert 2013-05-16 12:03:29 -04:00
parent c9967983e1
commit 2ffcabd410
4 changed files with 78 additions and 60 deletions

View file

@ -13,10 +13,10 @@ import net.minecraftforge.liquids.LiquidTank;
import universalelectricity.core.electricity.ElectricityPack; import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper; import universalelectricity.core.vector.VectorHelper;
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
import dark.library.helpers.MetaGroup; 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 */ /* ENERGY PER TICK TO TRY TO PUMP */
public static final double WATTS_PER_TICK = 100; 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)); TileEntity entity = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), getFacing(false));
if (entity instanceof ITankContainer) 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 @Override

View file

@ -37,13 +37,21 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
private List<Vector3> targetSources = new ArrayList<Vector3>(); private List<Vector3> targetSources = new ArrayList<Vector3>();
private List<Vector3> updateQue = new ArrayList<Vector3>(); private List<Vector3> updateQue = new ArrayList<Vector3>();
private LiquidPathFinder pathFinder = new LiquidPathFinder(this.worldObj, false, TileEntityDrain.MAX_WORLD_EDITS_PER_PROCESS * 2); private LiquidPathFinder pathFinder;
@Override @Override
public String getMeterReading(EntityPlayer user, ForgeDirection side) public String getMeterReading(EntityPlayer user, ForgeDirection side)
{ {
return "Set to " + (canDrainSources() ? "input liquids" : "output liquids"); 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() public boolean canDrainSources()
{ {
int meta = 0; int meta = 0;
@ -71,6 +79,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
@Override @Override
public void updateEntity() public void updateEntity()
{ {
super.updateEntity();
/* MAIN LOGIC PATH FOR DRAINING BODIES OF LIQUID */ /* MAIN LOGIC PATH FOR DRAINING BODIES OF LIQUID */
if (!this.worldObj.isRemote && this.ticks % 30 == 0) if (!this.worldObj.isRemote && this.ticks % 30 == 0)
{ {
@ -94,7 +103,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
Iterator<Vector3> it = this.targetSources.iterator(); Iterator<Vector3> it = this.targetSources.iterator();
while (it.hasNext()) while (it.hasNext())
{ {
Vector3 loc = (Vector3) it.next(); Vector3 loc = it.next();
if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS) if (this.currentWorldEdits >= MAX_WORLD_EDITS_PER_PROCESS)
{ {
break; break;
@ -147,6 +156,10 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
*/ */
public void getNextFluidBlock() public void getNextFluidBlock()
{ {
if (pathFinder == null)
{
pathFinder = new LiquidPathFinder(this.worldObj, false, TileEntityDrain.MAX_WORLD_EDITS_PER_PROCESS * 2);
}
pathFinder.reset(); pathFinder.reset();
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, this.yCoord + this.getFacing().offsetY, this.zCoord + this.getFacing().offsetZ));
// System.out.println("Nodes:" + pathFinder.nodes.size() + "Results:" + // System.out.println("Nodes:" + pathFinder.nodes.size() + "Results:" +
@ -157,6 +170,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
} }
} }
@SuppressWarnings("unchecked")
public void doCleanup() public void doCleanup()
{ {
/* CALL UPDATE ON EDITED BLOCKS */ /* CALL UPDATE ON EDITED BLOCKS */
@ -166,7 +180,7 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
int up = 0; int up = 0;
while (pp.hasNext() && up < TileEntityDrain.MAX_WORLD_EDITS_PER_PROCESS) 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.notifyBlockChange(vec.intX(), vec.intY(), vec.intZ(), vec.getBlockID(this.worldObj));
worldObj.notifyBlockOfNeighborChange(vec.intX(), vec.intY(), vec.intZ(), vec.getBlockID(this.worldObj)); worldObj.notifyBlockOfNeighborChange(vec.intX(), vec.intY(), vec.intZ(), vec.getBlockID(this.worldObj));
pp.remove(); pp.remove();
@ -195,10 +209,10 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
} }
} }
/* CLEANUP TARGET LIST AND REMOVE INVALID SOURCES */ /* CLEANUP TARGET LIST AND REMOVE INVALID SOURCES */
Iterator mn = this.targetSources.iterator(); Iterator<Vector3> mn = this.targetSources.iterator();
while (mn.hasNext()) while (mn.hasNext())
{ {
Vector3 vec = (Vector3) mn.next(); Vector3 vec = mn.next();
if (!FluidHelper.isSourceBlock(this.worldObj, vec)) if (!FluidHelper.isSourceBlock(this.worldObj, vec))
{ {
mn.remove(); mn.remove();
@ -219,20 +233,20 @@ public class TileEntityDrain extends TileEntityFluidDevice implements ITankConta
{ {
return 0; return 0;
} }
Vector3 a = (Vector3) o1; Vector3 first = (Vector3) o1;
Vector3 b = (Vector3) o2; Vector3 second = (Vector3) o2;
double da = Vector3.distance(a, faceVec); double firstDistance = Vector3.distance(first, faceVec);
double db = Vector3.distance(b, faceVec); double secondDistance = Vector3.distance(second, faceVec);
; if (first.equals(second))
if (a.equals(b))
{ {
return 0; 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);
} }
}); });
} }

View file

@ -17,13 +17,13 @@ import universalelectricity.core.electricity.ElectricityPack;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import universalelectricity.core.vector.VectorHelper; import universalelectricity.core.vector.VectorHelper;
import universalelectricity.prefab.network.IPacketReceiver; import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.tile.TileEntityElectricityRunnable;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
import dark.library.helpers.MetaGroup; 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); public final double WATTS_PER_TICK = (400 / 20);
private double percentPumped = 0.0; private double percentPumped = 0.0;

View file

@ -44,59 +44,63 @@ public class LiquidPathFinder
/** /**
* @return True on success finding, false on failure. * @return True on success finding, false on failure.
*/ */
public boolean findNodes(Vector3 node) public boolean findNodes(final Vector3 node)
{ {
Vector3 vec = node.clone(); try
Chunk chunk = this.world.getChunkFromBlockCoords(vec.intX(), vec.intZ());
if (!chunk.isChunkLoaded)
{
return true;
}else
{ {
Vector3 vec = node.clone();
this.nodes.add(node); this.nodes.add(node);
} Chunk chunk = this.world.getChunkFromBlockCoords(vec.intX(), vec.intZ());
int id = node.getBlockID(world); if (chunk == null || !chunk.isChunkLoaded)
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);
}
if (this.isDone(node))
{
return false;
}
vec = node.clone().modifyPositionFromSide(this.priority);
if (this.isValidNode(vec) & !this.nodes.contains(vec))
{
if (this.findNodes(vec))
{ {
return true; return true;
} }
}
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) int id = node.getBlockID(world);
{ int meta = node.getBlockID(world);
if (direction != this.priority) if (this.fill && (id == 0 || (FluidHelper.getLiquidFromBlockId(id) != null && meta != 0)))
{ {
vec = node.clone().modifyPositionFromSide(direction); this.results.add(node);
if (this.isValidNode(vec) & !this.nodes.contains(vec)) }
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; return false;
} }