Change out the canConnect methods

removed the old canConnect methods from every class that used it and
replaced it with the new one still matching how the class used the old
one. Though i'm concerned that the new method might increase processor
use a bit since it sifts threw all stacks that the pipe can handle
instead of the first valid one.
This commit is contained in:
Rseifert 2013-03-26 13:49:00 -04:00
parent b6048c7cac
commit 0a020c24df
6 changed files with 59 additions and 24 deletions

View file

@ -105,6 +105,10 @@ public class TileEntityMinorPump extends TileEntityElectricityRunnable implement
}
/**
* gets the fluidConductor or storageTank to ouput its pumped liquids too if there is not one it
* will not function
*/
public ITankContainer getFillTarget()
{
TileEntity ent = worldObj.getBlockTileEntity(xCoord + pipeConnection.offsetX, yCoord + pipeConnection.offsetY, zCoord + pipeConnection.offsetZ);
@ -138,7 +142,11 @@ public class TileEntityMinorPump extends TileEntityElectricityRunnable implement
double amps = (this.WATTS_PER_TICK / this.getVoltage());
return new ElectricityPack(amps, this.getVoltage());
}
/**
* checks to see if this pump can pump the selected target block
* @param x y z - location of the block, use the tileEntities world
* @return true if it can pump
*/
boolean canPump(int x, int y, int z)
{
int blockID = worldObj.getBlockId(x, y, z);
@ -168,9 +176,9 @@ public class TileEntityMinorPump extends TileEntityElectricityRunnable implement
}
/**
* drains the block or in other words removes it
* drains the block(removes) at the location given
*
* @param loc
* @param loc - vector 3 location
* @return true if the block was drained
*/
boolean drainBlock(Vector3 loc)
@ -180,13 +188,14 @@ public class TileEntityMinorPump extends TileEntityElectricityRunnable implement
LiquidData resource = LiquidHandler.getFromBlockID(blockID);
if (color.isValidLiquid(resource.getStack()) && meta == 0 && getFillTarget().fill(wireConnection, resource.getStack(), false) != 0)
if (color.isValidLiquid(resource.getStack()) && meta == 0 && getFillTarget().fill(pipeConnection, resource.getStack(), false) != 0)
{
LiquidStack stack = resource.getStack();
stack.amount = LiquidContainerRegistry.BUCKET_VOLUME;
int f = getFillTarget().fill(wireConnection, this.color.getLiquidData().getStack(), true);
if (f > 0)
int fillAmmount = getFillTarget().fill(pipeConnection, this.color.getLiquidData().getStack(), true);
if (fillAmmount > 0)
{
worldObj.setBlockAndMetadataWithNotify(xCoord, yCoord - 1, zCoord, 0, 0, 3);
return true;
@ -199,7 +208,7 @@ public class TileEntityMinorPump extends TileEntityElectricityRunnable implement
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
return this.wattsReceived + "/" + this.WATTS_PER_TICK + "W " + this.percentPumped+"% DONE";
return this.wattsReceived + "/" + this.WATTS_PER_TICK + "W " + this.percentPumped + "% DONE";
}
@Override
@ -221,15 +230,15 @@ public class TileEntityMinorPump extends TileEntityElectricityRunnable implement
@Override
public boolean canConnect(ForgeDirection dir, LiquidStack... stacks)
{
if(dir == this.pipeConnection.getOpposite())
if (dir == this.pipeConnection.getOpposite())
{
if(stacks == null || stacks.length == 0)
if (stacks == null || stacks.length == 0)
{
return true;
}
for(int i =0; i< stacks.length; i++)
for (int i = 0; i < stacks.length; i++)
{
if(this.color.isValidLiquid(stacks[i]))
if (this.color.isValidLiquid(stacks[i]))
{
return true;
}

View file

@ -213,9 +213,16 @@ public class TileEntityReleaseValve extends TileEntityAdvanced implements IPsiCr
}
@Override
public boolean getCanPressureTo(LiquidStack type, ForgeDirection dir)
public boolean canConnect(ForgeDirection dir, LiquidStack... stacks)
{
return type != null && this.canConnect(ColorCode.get(type));
for (int i = 0; i < stacks.length; i++)
{
if (this.canConnect(ColorCode.get(stacks[i])))
{
return true;
}
}
return false;
}
@Override

View file

@ -220,15 +220,15 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
}
@Override
public boolean getCanPressureTo(LiquidStack type, ForgeDirection dir)
public boolean canConnect(ForgeDirection dir, LiquidStack... stacks)
{
if (color.isValidLiquid(type) || type.isLiquidEqual(LiquidHandler.unkown.getStack()))
for (int i = 0; i < stacks.length; i++)
{
LiquidData data = LiquidHandler.get(type);
if (data.getCanFloat() && dir == ForgeDirection.DOWN)
return true;
if (!data.getCanFloat() && dir == ForgeDirection.UP)
LiquidData data = LiquidHandler.get(stacks[i]);
if (color.isValidLiquid(stacks[i]) && ((data.getCanFloat() && dir == ForgeDirection.DOWN) || (!data.getCanFloat() && dir == ForgeDirection.UP)))
{
return true;
}
}
return false;
}

View file

@ -3,6 +3,7 @@ package fluidmech.common.machines.pipes;
import fluidmech.common.machines.TileEntityTank;
import hydraulic.api.ColorCode;
import hydraulic.api.IColorCoded;
import hydraulic.api.IPipeConnector;
import hydraulic.api.IPsiCreator;
import hydraulic.api.IReadOut;
import hydraulic.core.liquidNetwork.LiquidHandler;
@ -274,9 +275,9 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
connectedBlocks[side] = null;
}
}
else if (tileEntity instanceof IPsiCreator)
else if (tileEntity instanceof IPipeConnector)
{
if (!((IPsiCreator) tileEntity).getCanPressureTo(color.getLiquidData().getStack(), direction))
if (!((IPipeConnector) tileEntity).canConnect(direction, color.getLiquidData().getStack()))
{
connectedBlocks[side] = null;
}
@ -307,12 +308,15 @@ public class TileEntityPipe extends TileEntityAdvanced implements ITankContainer
highestPressure = ((TileEntityPipe) connectedBlocks[i]).getPressure();
}
}
if (connectedBlocks[i] instanceof IPsiCreator && ((IPsiCreator) connectedBlocks[i]).getCanPressureTo(color.getLiquidData().getStack(), dir))
if (connectedBlocks[i] instanceof IPsiCreator && ((IPipeConnector) connectedBlocks[i]).canConnect(dir, color.getArrayLiquidStacks()))
{
int p = ((IPsiCreator) connectedBlocks[i]).getPressureOut(color.getLiquidData().getStack(), dir);
if (p > highestPressure)
{
highestPressure = p;
}
}
}
this.presure = highestPressure - 1;

View file

@ -92,7 +92,7 @@ public enum ColorCode
return validLiquids;
}
public List<LiquidStack> getAllLiquidStacks()
public List<LiquidStack> getAllLiquidStack()
{
List<LiquidStack> validStacks = new ArrayList<LiquidStack>();
for (LiquidData data : getAllLiquidData())
@ -101,6 +101,21 @@ public enum ColorCode
}
return validStacks;
}
public LiquidStack[] getArrayLiquidStacks()
{
List<LiquidStack> validStacks = new ArrayList<LiquidStack>();
for (LiquidData data : getAllLiquidData())
{
validStacks.add(data.getStack());
}
LiquidStack[] stacks = new LiquidStack[validStacks.size()];
for(int i =0; i < validStacks.size();i++)
{
stacks[i] = validStacks.get(i);
}
return stacks;
}
/**
* checks to see if the liquidStack is valid for the given color

View file

@ -57,7 +57,7 @@ public class HydraulicNetwork
this.pressureProduced = 0;
for (TileEntity ent : receivers)
{
if (ent instanceof IPipeConnector && ((IPipeConnector) ent).canConnect(ForgeDirection.UNKNOWN, (LiquidStack[]) this.color.getAllLiquidStacks().toArray()))
if (ent instanceof IPipeConnector && ((IPipeConnector) ent).canConnect(ForgeDirection.UNKNOWN, this.color.getArrayLiquidStacks()))
{
if (ent instanceof IPsiReciever)
{