Fixed a major duping bug with the release valve

Due to the way i was getting all the valid tanks inside of a block i
failed to get the block itself. This resulted in the release valve
draining the ILiquidTank varables rather than the ITankContainer block.
Its now fixed hower i need to go back threw and make changes to use
ForgeDirection later.
This commit is contained in:
Rseifert 2013-02-22 10:16:36 -05:00
parent 8abbbfdba2
commit f86ec909b7
4 changed files with 528 additions and 616 deletions

View file

@ -1 +1 @@
20
22

View file

@ -17,4 +17,6 @@ x Fluid-Mechanics_v0.2.7.15.jar Fluid-Mechanics_v0.2.7.15_api.zip
@ Fluid-Mechanics_v0.2.7.17.jar Fluid-Mechanics_v0.2.7.17_api.zip
* Fluid-Mechanics_v0.2.7.18.jar Fluid-Mechanics_v0.2.7.18_api.zip
x Fluid-Mechanics_v0.2.7.19.jar Fluid-Mechanics_v0.2.7.19_api.zip
* Fluid-Mechanics_v0.2.7.20.jar Fluid-Mechanics_v0.2.7.20_api.zip
x Fluid-Mechanics_v0.2.7.20.jar Fluid-Mechanics_v0.2.7.20_api.zip
x Fluid-Mechanics_v0.2.7.21.jar hydraulic_v0.2.7.21_api.zip
@ Fluid-Mechanics_v0.2.7.22.jar hydraulic_v0.2.7.22_api.zip

View file

@ -24,356 +24,248 @@ import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidStack;
import universalelectricity.prefab.implement.IRedstoneReceptor;
import universalelectricity.prefab.tile.TileEntityAdvanced;
public class TileEntityReleaseValve extends TileEntity implements IPsiCreator, IReadOut, IRedstoneReceptor, IInventory
public class TileEntityReleaseValve extends TileEntityAdvanced implements IPsiCreator, IReadOut
{
public boolean[] allowed = new boolean[ColorCode.values().length - 1];
public TileEntity[] connected = new TileEntity[6];
public boolean[] allowed = new boolean[ColorCode.values().length - 1];
public TileEntity[] connected = new TileEntity[6];
private List<TileEntityPipe> output = new ArrayList<TileEntityPipe>();
private List<ILiquidTank> input = new ArrayList<ILiquidTank>();
private List<TileEntityPipe> output = new ArrayList<TileEntityPipe>();
private List<ITankContainer> input = new ArrayList<ITankContainer>();
private int ticks = 0;
public boolean isPowered = false;
public boolean isPowered = false;
public boolean converted = false;
private ItemStack[] inventory = new ItemStack[0];
private ItemStack[] inventory = new ItemStack[0];
@Override
public void updateEntity()
{
super.updateEntity();
@Override
public void updateEntity()
{
super.updateEntity();
connected = connectionHelper.getSurroundingTileEntities(this);
for(int i =0; i < 6;i++)
{
if(connected[i] instanceof ITankContainer)
{
if(connected[i] instanceof IColorCoded && !this.canConnect(((IColorCoded) connected[i]).getColor()))
{
connected[i] = null;
}
}else
{
connected[i] = null;
}
}
if (!this.worldObj.isRemote && ticks++ >= 20)
{
ticks = 0;
BlockReleaseValve.checkForPower(worldObj, xCoord, yCoord, zCoord);
validateNBuildList();
// start the draining process
if (this.input.size() > 0 && this.output.size() > 0)
{
for (ILiquidTank tank : input)
{
this.isPowered = worldObj.isBlockGettingPowered(xCoord, yCoord, zCoord) || worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
if (tank.getLiquid() != null && tank.getLiquid().amount > 0)
{
//FMLLog.warning("Tank: " + LiquidHandler.getName(tank.getLiquid()) + " Vol: " + tank.getLiquid().amount);
TileEntityPipe pipe = this.findValidPipe(tank.getLiquid());
if (pipe != null)
{
ILiquidTank tankP = pipe.getTanks(ForgeDirection.UNKNOWN)[0];
//FMLLog.warning("Pipe: " + pipe.getColor() + " Vol: " + (tankP.getLiquid() != null ? tankP.getLiquid().amount : 0000));
int drain = pipe.fill(ForgeDirection.UNKNOWN, tank.getLiquid(), true);
tank.drain(drain, true);
}
}
}
}
connected = connectionHelper.getSurroundingTileEntities(this);
}
}
for (int i = 0; i < 6; i++)
{
if (connected[i] instanceof ITankContainer)
{
if (connected[i] instanceof IColorCoded && !this.canConnect(((IColorCoded) connected[i]).getColor()))
{
connected[i] = null;
}
}
else
{
connected[i] = null;
}
}
/** used to find a valid pipe for filling of the liquid type */
public TileEntityPipe findValidPipe(LiquidStack stack)
{
// find normal color selective pipe first
for (TileEntityPipe pipe : output)
{
ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0];
if (LiquidHandler.isEqual(pipe.getColor().getLiquidData().getStack(),stack) && (tank.getLiquid() == null || tank.getLiquid().amount < tank.getCapacity()))
{
//
return pipe;
}
}
// if no color selective pipe is found look for generic pipes
for (TileEntityPipe pipe : output)
{
if (pipe.getColor() == ColorCode.NONE) { return pipe; }
}
return null;
}
if (!this.worldObj.isRemote && this.ticks % 20 == 0)
{
validateNBuildList();
// start the draining process
if (this.input.size() > 0 && this.output.size() > 0)
{
for (ITankContainer drainedTank : input)
{
LiquidStack stack = drainedTank.drain(ForgeDirection.UNKNOWN, TileEntityPipe.maxVolume, false);
if (stack != null && stack.amount > 0)
{
TileEntityPipe inputPipe = this.findValidPipe(stack);
if (inputPipe != null)
{
ILiquidTank pipeVolume = inputPipe.getTanks(ForgeDirection.UNKNOWN)[0];
int ammountFilled = inputPipe.fill(ForgeDirection.UNKNOWN, stack, true);
System.out.print("/n Amount Drained: "+ammountFilled);
drainedTank.drain(ForgeDirection.UNKNOWN, ammountFilled, true);
}
}
}
}
/** sees if it can connect to a pipe of some color */
public boolean canConnect(ColorCode cc)
{
if (this.isRestricted())
{
for (int i = 0; i < this.allowed.length; i++)
{
if (i == cc.ordinal()) { return allowed[i]; }
}
}
return true;
}
}
}
/** if any of allowed list is true
*
* @return true */
public boolean isRestricted()
{
for (int i = 0; i < this.allowed.length; i++)
{
if (allowed[i]) { return true; }
}
return false;
}
/** used to find a valid pipe for filling of the liquid type */
public TileEntityPipe findValidPipe(LiquidStack stack)
{
// find normal color selective pipe first
for (TileEntityPipe pipe : output)
{
ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0];
if (LiquidHandler.isEqual(pipe.getColor().getLiquidData().getStack(), stack) && (tank.getLiquid() == null || tank.getLiquid().amount < tank.getCapacity()))
{
//
return pipe;
}
}
// if no color selective pipe is found look for generic pipes
for (TileEntityPipe pipe : output)
{
if (pipe.getColor() == ColorCode.NONE)
{
return pipe;
}
}
/** checks a liquidstack against its color code
*
* @param stack
* @return */
public boolean canAcceptLiquid(LiquidStack stack)
{
if (!this.isRestricted()) { return true; }
return canConnect(ColorCode.get(LiquidHandler.get(stack)));
}
return null;
}
/** Collects info about the surrounding 6 tiles and orders them into
* drain-able(ITankContainer) and fill-able(TileEntityPipes) instances */
public void validateNBuildList()
{
// cleanup
this.connected = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord);
this.input.clear();
this.output.clear();
// read surroundings
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
TileEntity ent = connected[i];
if (ent instanceof TileEntityPipe)
{
TileEntityPipe pipe = (TileEntityPipe) ent;
ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0];
if (this.isRestricted() && this.canConnect(pipe.getColor()))
{
connected[i] = null;
}
else if (tank.getLiquid() != null && tank.getLiquid().amount >= tank.getCapacity())
{
connected[i] = null;
}
else
{
this.output.add(pipe);
}
}
else if (ent instanceof ITankContainer)
{
ILiquidTank[] tanks = ((ITankContainer) connected[i]).getTanks(dir);
for (int t = 0; t < tanks.length; t++)
{
LiquidStack ll = tanks[t].getLiquid();
if (ll != null && ll.amount > 0 && ll.amount > 0)
{
if (this.canAcceptLiquid(ll))
{
this.input.add(tanks[t]);
}
}
}
}
else
{
connected[i] = null;
}
}
}
/** sees if it can connect to a pipe of some color */
public boolean canConnect(ColorCode cc)
{
if (this.isRestricted())
{
for (int i = 0; i < this.allowed.length; i++)
{
if (i == cc.ordinal())
{
return allowed[i];
}
}
}
return true;
}
@Override
public int getPressureOut(LiquidData type, ForgeDirection dir)
{
if (type == null) return 0;
if (this.canConnect(type.getColor())) { return type.getPressure(); }
return 0;
}
/**
* if any of allowed list is true
*
* @return true
*/
public boolean isRestricted()
{
for (int i = 0; i < this.allowed.length; i++)
{
if (allowed[i])
{
return true;
}
}
return false;
}
@Override
public boolean getCanPressureTo(LiquidData type, ForgeDirection dir)
{
if (type == null) return false;
if (this.canConnect(type.getColor())) return true;
return false;
}
/**
* checks a liquidstack against its color code
*
* @param stack
* @return
*/
public boolean canAcceptLiquid(LiquidStack stack)
{
return !this.isRestricted() || canConnect(ColorCode.get(LiquidHandler.get(stack)));
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
// TODO maybe debug on # of connected units of input/output
String output = "";
if (this.isRestricted())
{
output += "Output: Restricted and";
}
else
{
output += " Output: UnRestricted and";
}
if (!this.isPowered)
{
output += " Running ";
}
else
{
output += " Offline ";
}
return output;
}
/**
* Collects info about the surrounding 6 tiles and orders them into drain-able(ITankContainer)
* and fill-able(TileEntityPipes) instances
*/
public void validateNBuildList()
{
// cleanup
this.connected = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord);
this.input.clear();
this.output.clear();
// read surroundings
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
TileEntity ent = connected[i];
if (ent instanceof TileEntityPipe)
{
TileEntityPipe pipe = (TileEntityPipe) ent;
ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0];
if (this.isRestricted() && this.canConnect(pipe.getColor()))
{
connected[i] = null;
}
else if (tank.getLiquid() != null && tank.getLiquid().amount >= tank.getCapacity())
{
connected[i] = null;
}
else
{
this.output.add(pipe);
}
}
else if (ent instanceof ITankContainer)
{
ILiquidTank[] tanks = ((ITankContainer) connected[i]).getTanks(dir);
for (int t = 0; t < tanks.length; t++)
{
LiquidStack ll = tanks[t].getLiquid();
if (ll != null && ll.amount > 0 && ll.amount > 0)
{
if (this.canAcceptLiquid(ll))
{
this.input.add((ITankContainer) ent);
break;
}
}
}
}
else
{
connected[i] = null;
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
for (int i = 0; i < this.allowed.length; i++)
{
allowed[i] = nbt.getBoolean("allowed" + i);
}
}
@Override
public int getPressureOut(LiquidData type, ForgeDirection dir)
{
return (type != null && this.canConnect(type.getColor()) ? type.getPressure() : 0);
}
/** Writes a tile entity to NBT. */
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
for (int i = 0; i < this.allowed.length; i++)
{
nbt.setBoolean("allowed" + i, allowed[i]);
}
}
@Override
public boolean getCanPressureTo(LiquidData type, ForgeDirection dir)
{
return type != null && this.canConnect(type.getColor());
}
@Override
public void onPowerOn()
{
this.isPowered = true;
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
// TODO maybe debug on # of connected units of input/output
String output = "";
if (this.isRestricted())
{
output += "Output: Restricted and";
}
else
{
output += " Output: UnRestricted and";
}
if (!this.isPowered)
{
output += " Open ";
}
else
{
output += " Closed ";
}
return output;
}
}
@Override
public void onPowerOff()
{
this.isPowered = false;
}
public int getSizeInventory()
{
return this.inventory.length;
}
/** Returns the stack in slot i */
public ItemStack getStackInSlot(int par1)
{
return this.inventory[par1];
}
/** Removes from an inventory slot (first arg) up to a specified number
* (second arg) of items and returns them in a new stack. */
public ItemStack decrStackSize(int par1, int par2)
{
if (this.inventory[par1] != null)
{
ItemStack var3;
if (this.inventory[par1].stackSize <= par2)
{
var3 = this.inventory[par1];
this.inventory[par1] = null;
return var3;
}
else
{
var3 = this.inventory[par1].splitStack(par2);
if (this.inventory[par1].stackSize == 0)
{
this.inventory[par1] = null;
}
return var3;
}
}
else
{
return null;
}
}
/** When some containers are closed they call this on each slot, then drop
* whatever it returns as an EntityItem - like when you close a workbench
* GUI. */
public ItemStack getStackInSlotOnClosing(int par1)
{
if (this.inventory[par1] != null)
{
ItemStack var2 = this.inventory[par1];
this.inventory[par1] = null;
return var2;
}
else
{
return null;
}
}
/** Sets the given item stack to the specified slot in the inventory (can be
* crafting or armor sections). */
public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
{
this.inventory[par1] = par2ItemStack;
if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
{
par2ItemStack.stackSize = this.getInventoryStackLimit();
}
}
@Override
public String getInvName()
{
return "Release Valve";
}
@Override
public int getInventoryStackLimit()
{
return 0;
}
@Override
public boolean isUseableByPlayer(EntityPlayer var1)
{
return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : var1.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
}
@Override
public void openChest()
{
}
@Override
public void closeChest()
{
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
for (int i = 0; i < this.allowed.length; i++)
{
allowed[i] = nbt.getBoolean("allowed" + i);
}
}
/** Writes a tile entity to NBT. */
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
for (int i = 0; i < this.allowed.length; i++)
{
nbt.setBoolean("allowed" + i, allowed[i]);
}
}
}

View file

@ -12,6 +12,7 @@ import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
@ -23,323 +24,340 @@ import net.minecraftforge.liquids.LiquidTank;
public class TileEntityPipe extends TileEntity implements ITankContainer, IReadOut, IColorCoded
{
private ColorCode color = ColorCode.NONE;
private ColorCode color = ColorCode.NONE;
private int count = 20;
private int count2, presure = 0;
private int count = 20;
private int count2, presure = 0;
public boolean converted = false;
public boolean isUniversal = false;
public boolean converted = false;
public boolean isUniversal = false;
public TileEntity[] connectedBlocks = new TileEntity[6];
public TileEntity[] connectedBlocks = new TileEntity[6];
public static final int maxVolume = LiquidContainerRegistry.BUCKET_VOLUME * 2;
private LiquidTank tank = new LiquidTank(maxVolume);
private LiquidTank stored = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME * 2);
@Override
public void updateEntity()
{
@Override
public void updateEntity()
{
this.validataConnections();
this.color = ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
if (++count >= 20)
{
count = 0;
this.updatePressure();
if (this.worldObj.isRemote)
{
this.randomDisplayTick();
}
LiquidStack stack = tank.getLiquid();
if (!worldObj.isRemote && stack != null && stack.amount >= 0)
{
this.validataConnections();
this.color = ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
if (++count >= 20)
{
count = 0;
this.updatePressure();
if (this.worldObj.isRemote)
{
this.randomDisplayTick();
}
LiquidStack stack = stored.getLiquid();
if (!worldObj.isRemote && stack != null && stack.amount >= 0)
{
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (connectedBlocks[i] instanceof ITankContainer)
{
if (connectedBlocks[i] instanceof TileEntityPipe)
{
if (((TileEntityPipe) connectedBlocks[i]).presure < this.presure)
{
tank.drain(((TileEntityPipe) connectedBlocks[i]).fill(dir, stack, true), true);
}
if (connectedBlocks[i] instanceof ITankContainer)
{
if (connectedBlocks[i] instanceof TileEntityPipe)
{
if (((TileEntityPipe) connectedBlocks[i]).presure < this.presure)
{
stored.drain(((TileEntityPipe) connectedBlocks[i]).fill(dir, stack, true), true);
}
}
else if (connectedBlocks[i] instanceof TileEntityTank && ((TileEntityTank) connectedBlocks[i]).getColor() == this.color)
{
if (dir == ForgeDirection.UP && !color.getLiquidData().getCanFloat())
{
/* do nothing */
}
else if (dir == ForgeDirection.DOWN && color.getLiquidData().getCanFloat())
{
/* do nothing */
}
else
{
tank.drain(((ITankContainer) connectedBlocks[i]).fill(dir.getOpposite(), stack, true), true);
}
}
else
{
tank.drain(((ITankContainer) connectedBlocks[i]).fill(dir.getOpposite(), stack, true), true);
}
}
}
else if (connectedBlocks[i] instanceof TileEntityTank && ((TileEntityTank) connectedBlocks[i]).getColor() == this.color)
{
if (dir == ForgeDirection.UP && !color.getLiquidData().getCanFloat())
{
/* do nothing */
}
else if (dir == ForgeDirection.DOWN && color.getLiquidData().getCanFloat())
{
/* do nothing */
}
else
{
stored.drain(((ITankContainer) connectedBlocks[i]).fill(dir.getOpposite(), stack, true), true);
}
}
else
{
stored.drain(((ITankContainer) connectedBlocks[i]).fill(dir.getOpposite(), stack, true), true);
}
}
if (stack == null || stack.amount <= 0)
{
break;
}
}
}
}
if (stack == null || stack.amount <= 0)
{
break;
}
}
}
}
}
}
public void randomDisplayTick()
{
Random random = new Random();
LiquidStack stack = tank.getLiquid();
if (stack != null && random.nextInt(10) == 0)
{
// TODO align this with the pipe model so not to drip where there is
// no pipe
double xx = (double) ((float) xCoord + random.nextDouble());
double zz = (double) yCoord + .3D;
double yy = (double) ((float) zCoord + random.nextDouble());
public void randomDisplayTick()
{
Random random = new Random();
LiquidStack stack = stored.getLiquid();
if (stack != null && random.nextInt(10) == 0)
{
// TODO align this with the pipe model so not to drip where there is
// no pipe
double xx = (double) ((float) xCoord + random.nextDouble());
double zz = (double) yCoord + .3D;
double yy = (double) ((float) zCoord + random.nextDouble());
if (ColorCode.get(stack) != ColorCode.RED)
{
worldObj.spawnParticle("dripWater", xx, zz, yy, 0.0D, 0.0D, 0.0D);
}
else
{
worldObj.spawnParticle("dripLava", xx, zz, yy, 0.0D, 0.0D, 0.0D);
}
}
}
if (ColorCode.get(stack) != ColorCode.RED)
{
worldObj.spawnParticle("dripWater", xx, zz, yy, 0.0D, 0.0D, 0.0D);
}
else
{
worldObj.spawnParticle("dripLava", xx, zz, yy, 0.0D, 0.0D, 0.0D);
}
}
}
/**
* gets the current color mark of the pipe
*/
@Override
public ColorCode getColor()
{
return this.color;
}
/**
* gets the current color mark of the pipe
*/
@Override
public ColorCode getColor()
{
return this.color;
}
/**
* sets the current color mark of the pipe
*/
@Override
public void setColor(Object cc)
{
this.color = ColorCode.get(cc);
}
/**
* sets the current color mark of the pipe
*/
@Override
public void setColor(Object cc)
{
this.color = ColorCode.get(cc);
}
/**
* sets the current color mark of the pipe
*/
public void setColor(int i)
{
if (i < ColorCode.values().length)
{
this.color = ColorCode.values()[i];
}
}
/**
* sets the current color mark of the pipe
*/
public void setColor(int i)
{
if (i < ColorCode.values().length)
{
this.color = ColorCode.values()[i];
}
}
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
/**
* Reads a tile entity from NBT.
*/
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
LiquidStack liquid = new LiquidStack(0, 0, 0);
liquid.readFromNBT(nbt.getCompoundTag("stored"));
if (Item.itemsList[liquid.itemID] != null && liquid.amount > 0)
{
this.tank.setLiquid(liquid);
}
}
LiquidStack liquid = new LiquidStack(0, 0, 0);
liquid.readFromNBT(nbt.getCompoundTag("stored"));
stored.setLiquid(liquid);
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (tank.getLiquid() != null)
{
nbt.setTag("stored", tank.getLiquid().writeToNBT(new NBTTagCompound()));
}
}
/**
* Writes a tile entity to NBT.
*/
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (stored.getLiquid() != null)
{
nbt.setTag("stored", stored.getLiquid().writeToNBT(new NBTTagCompound()));
}
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
LiquidStack stack = this.tank.getLiquid();
if (stack != null)
{
return (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + "/" + (this.tank.getCapacity() / LiquidContainerRegistry.BUCKET_VOLUME) + " " + LiquidHandler.get(stack).getName() + " @ " + this.presure + "p";
}
@Override
public String getMeterReading(EntityPlayer user, ForgeDirection side)
{
LiquidStack stack = this.stored.getLiquid();
if (stack != null) { return (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + "/" + (this.stored.getCapacity() / LiquidContainerRegistry.BUCKET_VOLUME) + " " + LiquidHandler.get(stack).getName() + " @ " + this.presure + "p"; }
return "Empty" + " @ " + this.presure + "p";
}
return "Empty" + " @ " + this.presure + "p";
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (resource == null)
{
return 0;
}
LiquidStack stack = tank.getLiquid();
if (color != ColorCode.NONE)
{
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (resource == null) { return 0; }
LiquidStack stack = stored.getLiquid();
if (color != ColorCode.NONE)
{
if (stack == null || LiquidHandler.isEqual(resource, this.color.getLiquidData()))
{
return this.fill(0, resource, doFill);
}
else
{
return this.causeMix(stack, resource);
}
if (stack == null || LiquidHandler.isEqual(resource, this.color.getLiquidData()))
{
return this.fill(0, resource, doFill);
}
else
{
return this.causeMix(stack, resource);
}
}
else
{
if (stack == null || LiquidHandler.isEqual(stack, resource))
{
return this.fill(0, resource, doFill);
}
else
{
return this.causeMix(stack, resource);
}
}
}
}
else
{
if (stack == null || LiquidHandler.isEqual(stack, resource))
{
return this.fill(0, resource, doFill);
}
else
{
return this.causeMix(stack, resource);
}
}
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
if (tankIndex != 0 || resource == null)
{
return 0;
}
return tank.fill(resource, doFill);
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
if (tankIndex != 0 || resource == null) { return 0; }
return stored.fill(resource, doFill);
}
public int causeMix(LiquidStack stored, LiquidStack fill)
{
if (stored == null || fill == null)
{
return 0;
}
// water flowing into lava creates obby
if (LiquidHandler.isEqual(stored, LiquidHandler.lava) && LiquidHandler.isEqual(fill, LiquidHandler.water))
{
worldObj.setBlockWithNotify(xCoord, yCoord, zCoord, Block.obsidian.blockID);
return fill.amount;
}// lava flowing into water creates cobble
else if (LiquidHandler.isEqual(stored, LiquidHandler.water) && LiquidHandler.isEqual(fill, LiquidHandler.lava))
{
worldObj.setBlockWithNotify(xCoord, yCoord, zCoord, Block.cobblestone.blockID);
return fill.amount;
}
else
// anything else creates waste liquid
{
int f = this.tank.fill(new LiquidStack(stored.itemID, fill.amount, stored.itemMeta), true);
int s = this.tank.getLiquid().amount;
LiquidStack stack = LiquidHandler.getStack(LiquidHandler.waste, s);
this.tank.setLiquid(stack);
return f;
}
}
public int causeMix(LiquidStack stored, LiquidStack fill)
{
if (stored == null || fill == null) { return 0; }
// water flowing into lava creates obby
if (LiquidHandler.isEqual(stored, LiquidHandler.lava) && LiquidHandler.isEqual(fill, LiquidHandler.water))
{
worldObj.setBlockWithNotify(xCoord, yCoord, zCoord, Block.obsidian.blockID);
return fill.amount;
}// lava flowing into water creates cobble
else if (LiquidHandler.isEqual(stored, LiquidHandler.water) && LiquidHandler.isEqual(fill, LiquidHandler.lava))
{
worldObj.setBlockWithNotify(xCoord, yCoord, zCoord, Block.cobblestone.blockID);
return fill.amount;
}
else
// anything else creates waste liquid
{
int f = this.stored.fill(new LiquidStack(stored.itemID, fill.amount, stored.itemMeta), true);
int s = this.stored.getLiquid().amount;
LiquidStack stack = LiquidHandler.getStack(LiquidHandler.waste, s);
this.stored.setLiquid(stack);
return f;
}
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[] { this.tank };
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[] { this.stored };
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
return null;
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
return null;
}
/**
* collects and sorts the surrounding TE for valid connections
*/
public void validataConnections()
{
this.connectedBlocks = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord);
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
TileEntity ent = connectedBlocks[i];
if (ent instanceof ITankContainer)
{
if (ent instanceof TileEntityPipe && color != ((TileEntityPipe) ent).getColor())
{
connectedBlocks[i] = null;
}
// TODO switch side catch for IPressure
if (this.color != ColorCode.NONE && ent instanceof TileEntityTank && ((TileEntityTank) ent).getColor() != ColorCode.NONE && color != ((TileEntityTank) ent).getColor())
{
connectedBlocks[i] = null;
}
}
else if (ent instanceof IPsiCreator)
{
if (!((IPsiCreator) ent).getCanPressureTo(color.getLiquidData(), dir))
{
connectedBlocks[i] = null;
}
}
else
{
connectedBlocks[i] = null;
}
}
}
/**
* collects and sorts the surrounding TE for valid connections
*/
public void validataConnections()
{
this.connectedBlocks = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord);
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
TileEntity ent = connectedBlocks[i];
if (ent instanceof ITankContainer)
{
if (ent instanceof TileEntityPipe && color != ((TileEntityPipe) ent).getColor())
{
connectedBlocks[i] = null;
}
// TODO switch side catch for IPressure
if (this.color != ColorCode.NONE && ent instanceof TileEntityTank && ((TileEntityTank) ent).getColor() != ColorCode.NONE && color != ((TileEntityTank) ent).getColor())
{
connectedBlocks[i] = null;
}
}
else if (ent instanceof IPsiCreator)
{
if (!((IPsiCreator) ent).getCanPressureTo(color.getLiquidData(), dir))
{
connectedBlocks[i] = null;
}
}
else
{
connectedBlocks[i] = null;
}
}
}
/**
* updates this units pressure level using the pipe/machines around it
*/
public void updatePressure()
{
int highestPressure = 0;
this.presure = 0;
/**
* updates this units pressure level using the pipe/machines around it
*/
public void updatePressure()
{
int highestPressure = 0;
this.presure = 0;
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = ForgeDirection.getOrientation(i);
if (connectedBlocks[i] instanceof TileEntityPipe)
{
if (((TileEntityPipe) connectedBlocks[i]).getPressure() > highestPressure)
{
highestPressure = ((TileEntityPipe) connectedBlocks[i]).getPressure();
}
}
if (connectedBlocks[i] instanceof IPsiCreator && ((IPsiCreator) connectedBlocks[i]).getCanPressureTo(color.getLiquidData(), dir))
{
if (connectedBlocks[i] instanceof TileEntityPipe)
{
if (((TileEntityPipe) connectedBlocks[i]).getPressure() > highestPressure)
{
highestPressure = ((TileEntityPipe) connectedBlocks[i]).getPressure();
}
}
if (connectedBlocks[i] instanceof IPsiCreator && ((IPsiCreator) connectedBlocks[i]).getCanPressureTo(color.getLiquidData(), dir))
{
int p = ((IPsiCreator) connectedBlocks[i]).getPressureOut(color.getLiquidData(), dir);
if (p > highestPressure)
highestPressure = p;
}
}
this.presure = highestPressure - 1;
}
int p = ((IPsiCreator) connectedBlocks[i]).getPressureOut(color.getLiquidData(), dir);
if (p > highestPressure)
highestPressure = p;
}
}
this.presure = highestPressure - 1;
}
public int getPressure()
{
return this.presure;
}
public int getPressure()
{
return this.presure;
}
}