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.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 * 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 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.ITankContainer;
import net.minecraftforge.liquids.LiquidStack; import net.minecraftforge.liquids.LiquidStack;
import universalelectricity.prefab.implement.IRedstoneReceptor; 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 boolean[] allowed = new boolean[ColorCode.values().length - 1];
public TileEntity[] connected = new TileEntity[6]; public TileEntity[] connected = new TileEntity[6];
private List<TileEntityPipe> output = new ArrayList<TileEntityPipe>(); private List<TileEntityPipe> output = new ArrayList<TileEntityPipe>();
private List<ILiquidTank> input = new ArrayList<ILiquidTank>(); private List<ITankContainer> input = new ArrayList<ITankContainer>();
private int ticks = 0; public boolean isPowered = false;
public boolean isPowered = false; private ItemStack[] inventory = new ItemStack[0];
public boolean converted = false;
private ItemStack[] inventory = new ItemStack[0]; @Override
public void updateEntity()
{
super.updateEntity();
@Override this.isPowered = worldObj.isBlockGettingPowered(xCoord, yCoord, zCoord) || worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
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; connected = connectionHelper.getSurroundingTileEntities(this);
}
}
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)
{
if (tank.getLiquid() != null && tank.getLiquid().amount > 0) for (int i = 0; i < 6; i++)
{ {
//FMLLog.warning("Tank: " + LiquidHandler.getName(tank.getLiquid()) + " Vol: " + tank.getLiquid().amount); if (connected[i] instanceof ITankContainer)
TileEntityPipe pipe = this.findValidPipe(tank.getLiquid()); {
if (pipe != null) if (connected[i] instanceof IColorCoded && !this.canConnect(((IColorCoded) connected[i]).getColor()))
{ {
ILiquidTank tankP = pipe.getTanks(ForgeDirection.UNKNOWN)[0]; connected[i] = null;
//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); else
} {
} connected[i] = 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);
}
}
}
}
/** used to find a valid pipe for filling of the liquid type */ }
public TileEntityPipe findValidPipe(LiquidStack stack) }
{
// find normal color selective pipe first /** used to find a valid pipe for filling of the liquid type */
for (TileEntityPipe pipe : output) public TileEntityPipe findValidPipe(LiquidStack stack)
{ {
ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0]; // find normal color selective pipe first
if (LiquidHandler.isEqual(pipe.getColor().getLiquidData().getStack(),stack) && (tank.getLiquid() == null || tank.getLiquid().amount < tank.getCapacity())) for (TileEntityPipe pipe : output)
{ {
// ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0];
return pipe; if (LiquidHandler.isEqual(pipe.getColor().getLiquidData().getStack(), stack) && (tank.getLiquid() == null || tank.getLiquid().amount < tank.getCapacity()))
} {
} //
// if no color selective pipe is found look for generic pipes return pipe;
for (TileEntityPipe pipe : output) }
{ }
if (pipe.getColor() == ColorCode.NONE) { 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; return null;
} }
/** sees if it can connect to a pipe of some color */ /** sees if it can connect to a pipe of some color */
public boolean canConnect(ColorCode cc) public boolean canConnect(ColorCode cc)
{ {
if (this.isRestricted()) if (this.isRestricted())
{ {
for (int i = 0; i < this.allowed.length; i++) for (int i = 0; i < this.allowed.length; i++)
{ {
if (i == cc.ordinal()) { return allowed[i]; } if (i == cc.ordinal())
} {
} return allowed[i];
return true; }
} }
}
return true;
}
/** if any of allowed list is true /**
* * if any of allowed list is true
* @return true */ *
public boolean isRestricted() * @return true
{ */
for (int i = 0; i < this.allowed.length; i++) public boolean isRestricted()
{ {
if (allowed[i]) { return true; } for (int i = 0; i < this.allowed.length; i++)
} {
return false; if (allowed[i])
} {
return true;
}
}
return false;
}
/** checks a liquidstack against its color code /**
* * checks a liquidstack against its color code
* @param stack *
* @return */ * @param stack
public boolean canAcceptLiquid(LiquidStack stack) * @return
{ */
if (!this.isRestricted()) { return true; } public boolean canAcceptLiquid(LiquidStack stack)
return canConnect(ColorCode.get(LiquidHandler.get(stack))); {
} return !this.isRestricted() || canConnect(ColorCode.get(LiquidHandler.get(stack)));
}
/** Collects info about the surrounding 6 tiles and orders them into /**
* drain-able(ITankContainer) and fill-able(TileEntityPipes) instances */ * Collects info about the surrounding 6 tiles and orders them into drain-able(ITankContainer)
public void validateNBuildList() * and fill-able(TileEntityPipes) instances
{ */
// cleanup public void validateNBuildList()
this.connected = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord); {
this.input.clear(); // cleanup
this.output.clear(); this.connected = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord);
// read surroundings this.input.clear();
for (int i = 0; i < 6; i++) this.output.clear();
{ // read surroundings
ForgeDirection dir = ForgeDirection.getOrientation(i); for (int i = 0; i < 6; i++)
TileEntity ent = connected[i]; {
if (ent instanceof TileEntityPipe) ForgeDirection dir = ForgeDirection.getOrientation(i);
{ TileEntity ent = connected[i];
TileEntityPipe pipe = (TileEntityPipe) ent; if (ent instanceof TileEntityPipe)
ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0]; {
if (this.isRestricted() && this.canConnect(pipe.getColor())) TileEntityPipe pipe = (TileEntityPipe) ent;
{ ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0];
connected[i] = null; if (this.isRestricted() && this.canConnect(pipe.getColor()))
} {
else if (tank.getLiquid() != null && tank.getLiquid().amount >= tank.getCapacity()) connected[i] = null;
{ }
connected[i] = null; else if (tank.getLiquid() != null && tank.getLiquid().amount >= tank.getCapacity())
} {
else connected[i] = null;
{ }
this.output.add(pipe); else
} {
} this.output.add(pipe);
else if (ent instanceof ITankContainer) }
{ }
ILiquidTank[] tanks = ((ITankContainer) connected[i]).getTanks(dir); else if (ent instanceof ITankContainer)
for (int t = 0; t < tanks.length; t++) {
{ ILiquidTank[] tanks = ((ITankContainer) connected[i]).getTanks(dir);
LiquidStack ll = tanks[t].getLiquid(); for (int t = 0; t < tanks.length; t++)
if (ll != null && ll.amount > 0 && ll.amount > 0) {
{ LiquidStack ll = tanks[t].getLiquid();
if (this.canAcceptLiquid(ll)) if (ll != null && ll.amount > 0 && ll.amount > 0)
{ {
this.input.add(tanks[t]); if (this.canAcceptLiquid(ll))
} {
} this.input.add((ITankContainer) ent);
} break;
} }
else }
{ }
connected[i] = null; }
} else
} {
} connected[i] = null;
}
}
}
@Override @Override
public int getPressureOut(LiquidData type, ForgeDirection dir) public int getPressureOut(LiquidData type, ForgeDirection dir)
{ {
if (type == null) return 0; return (type != null && this.canConnect(type.getColor()) ? type.getPressure() : 0);
if (this.canConnect(type.getColor())) { return type.getPressure(); } }
return 0;
}
@Override @Override
public boolean getCanPressureTo(LiquidData type, ForgeDirection dir) public boolean getCanPressureTo(LiquidData type, ForgeDirection dir)
{ {
if (type == null) return false; return type != null && this.canConnect(type.getColor());
if (this.canConnect(type.getColor())) return true; }
return false;
}
@Override @Override
public String getMeterReading(EntityPlayer user, ForgeDirection side) public String getMeterReading(EntityPlayer user, ForgeDirection side)
{ {
// TODO maybe debug on # of connected units of input/output // TODO maybe debug on # of connected units of input/output
String output = ""; String output = "";
if (this.isRestricted()) if (this.isRestricted())
{ {
output += "Output: Restricted and"; output += "Output: Restricted and";
} }
else else
{ {
output += " Output: UnRestricted and"; output += " Output: UnRestricted and";
} }
if (!this.isPowered) if (!this.isPowered)
{ {
output += " Running "; output += " Open ";
} }
else else
{ {
output += " Offline "; output += " Closed ";
} }
return output; return output;
} }
@Override @Override
public void readFromNBT(NBTTagCompound nbt) public void readFromNBT(NBTTagCompound nbt)
{ {
super.readFromNBT(nbt); super.readFromNBT(nbt);
for (int i = 0; i < this.allowed.length; i++) for (int i = 0; i < this.allowed.length; i++)
{ {
allowed[i] = nbt.getBoolean("allowed" + 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]);
}
}
@Override
public void onPowerOn()
{
this.isPowered = true;
}
@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()
{
}
/** 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.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -23,323 +24,340 @@ import net.minecraftforge.liquids.LiquidTank;
public class TileEntityPipe extends TileEntity implements ITankContainer, IReadOut, IColorCoded 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 count = 20;
private int count2, presure = 0; private int count2, presure = 0;
public boolean converted = false; public boolean converted = false;
public boolean isUniversal = false; public boolean isUniversal = false;
public TileEntity[] connectedBlocks = new TileEntity[6]; public TileEntity[] connectedBlocks = new TileEntity[6];
private LiquidTank stored = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME * 2); public static final int maxVolume = LiquidContainerRegistry.BUCKET_VOLUME * 2;
@Override private LiquidTank tank = new LiquidTank(maxVolume);
public void updateEntity()
{
this.validataConnections(); @Override
this.color = ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); public void updateEntity()
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++) this.validataConnections();
{ this.color = ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
ForgeDirection dir = ForgeDirection.getOrientation(i); 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)
{
if (connectedBlocks[i] instanceof ITankContainer) for (int i = 0; i < 6; i++)
{ {
if (connectedBlocks[i] instanceof TileEntityPipe) ForgeDirection dir = ForgeDirection.getOrientation(i);
{
if (((TileEntityPipe) connectedBlocks[i]).presure < this.presure)
{
stored.drain(((TileEntityPipe) connectedBlocks[i]).fill(dir, stack, true), true);
}
} if (connectedBlocks[i] instanceof ITankContainer)
else if (connectedBlocks[i] instanceof TileEntityTank && ((TileEntityTank) connectedBlocks[i]).getColor() == this.color) {
{ if (connectedBlocks[i] instanceof TileEntityPipe)
if (dir == ForgeDirection.UP && !color.getLiquidData().getCanFloat()) {
{ if (((TileEntityPipe) connectedBlocks[i]).presure < this.presure)
/* do nothing */ {
} tank.drain(((TileEntityPipe) connectedBlocks[i]).fill(dir, stack, true), true);
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) }
{ else if (connectedBlocks[i] instanceof TileEntityTank && ((TileEntityTank) connectedBlocks[i]).getColor() == this.color)
break; {
} 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);
}
}
} if (stack == null || stack.amount <= 0)
{
break;
}
}
}
}
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) public void randomDisplayTick()
{ {
worldObj.spawnParticle("dripWater", xx, zz, yy, 0.0D, 0.0D, 0.0D); Random random = new Random();
} LiquidStack stack = tank.getLiquid();
else if (stack != null && random.nextInt(10) == 0)
{ {
worldObj.spawnParticle("dripLava", xx, zz, yy, 0.0D, 0.0D, 0.0D); // 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)
* gets the current color mark of the pipe {
*/ worldObj.spawnParticle("dripWater", xx, zz, yy, 0.0D, 0.0D, 0.0D);
@Override }
public ColorCode getColor() else
{ {
return this.color; worldObj.spawnParticle("dripLava", xx, zz, yy, 0.0D, 0.0D, 0.0D);
} }
}
}
/** /**
* sets the current color mark of the pipe * gets the current color mark of the pipe
*/ */
@Override @Override
public void setColor(Object cc) public ColorCode getColor()
{ {
this.color = ColorCode.get(cc); return this.color;
} }
/** /**
* sets the current color mark of the pipe * sets the current color mark of the pipe
*/ */
public void setColor(int i) @Override
{ public void setColor(Object cc)
if (i < ColorCode.values().length) {
{ this.color = ColorCode.get(cc);
this.color = ColorCode.values()[i]; }
}
}
/** /**
* Reads a tile entity from NBT. * sets the current color mark of the pipe
*/ */
@Override public void setColor(int i)
public void readFromNBT(NBTTagCompound nbt) {
{ if (i < ColorCode.values().length)
super.readFromNBT(nbt); {
this.color = ColorCode.values()[i];
}
}
LiquidStack liquid = new LiquidStack(0, 0, 0); /**
liquid.readFromNBT(nbt.getCompoundTag("stored")); * Reads a tile entity from NBT.
stored.setLiquid(liquid); */
} @Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
/** LiquidStack liquid = new LiquidStack(0, 0, 0);
* Writes a tile entity to NBT. liquid.readFromNBT(nbt.getCompoundTag("stored"));
*/ if (Item.itemsList[liquid.itemID] != null && liquid.amount > 0)
@Override {
public void writeToNBT(NBTTagCompound nbt) this.tank.setLiquid(liquid);
{ }
super.writeToNBT(nbt); }
if (stored.getLiquid() != null)
{
nbt.setTag("stored", stored.getLiquid().writeToNBT(new NBTTagCompound()));
}
}
@Override /**
public String getMeterReading(EntityPlayer user, ForgeDirection side) * Writes a tile entity to NBT.
{ */
LiquidStack stack = this.stored.getLiquid(); @Override
if (stack != null) { return (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + "/" + (this.stored.getCapacity() / LiquidContainerRegistry.BUCKET_VOLUME) + " " + LiquidHandler.get(stack).getName() + " @ " + this.presure + "p"; } public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (tank.getLiquid() != null)
{
nbt.setTag("stored", tank.getLiquid().writeToNBT(new NBTTagCompound()));
}
}
return "Empty" + " @ " + this.presure + "p"; @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 return "Empty" + " @ " + this.presure + "p";
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())) @Override
{ public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
return this.fill(0, resource, doFill); {
} if (resource == null)
else {
{ return 0;
return this.causeMix(stack, resource); }
} LiquidStack stack = tank.getLiquid();
if (color != ColorCode.NONE)
{
} if (stack == null || LiquidHandler.isEqual(resource, this.color.getLiquidData()))
else {
{ return this.fill(0, resource, doFill);
if (stack == null || LiquidHandler.isEqual(stack, resource)) }
{ else
return this.fill(0, resource, doFill); {
} return this.causeMix(stack, resource);
else }
{
return this.causeMix(stack, resource);
}
}
}
@Override }
public int fill(int tankIndex, LiquidStack resource, boolean doFill) else
{ {
if (tankIndex != 0 || resource == null) { return 0; } if (stack == null || LiquidHandler.isEqual(stack, resource))
return stored.fill(resource, doFill); {
} return this.fill(0, resource, doFill);
}
else
{
return this.causeMix(stack, resource);
}
}
}
public int causeMix(LiquidStack stored, LiquidStack fill) @Override
{ public int fill(int tankIndex, LiquidStack resource, boolean doFill)
if (stored == null || fill == null) { return 0; } {
// water flowing into lava creates obby if (tankIndex != 0 || resource == null)
if (LiquidHandler.isEqual(stored, LiquidHandler.lava) && LiquidHandler.isEqual(fill, LiquidHandler.water)) {
{ return 0;
worldObj.setBlockWithNotify(xCoord, yCoord, zCoord, Block.obsidian.blockID); }
return fill.amount; return tank.fill(resource, doFill);
}// 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 int causeMix(LiquidStack stored, LiquidStack fill)
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
{ if (stored == null || fill == null)
return 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;
}
}
@Override @Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{ {
return null; return null;
} }
@Override @Override
public ILiquidTank[] getTanks(ForgeDirection direction) public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{ {
return new ILiquidTank[] { this.stored }; return null;
} }
@Override @Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) public ILiquidTank[] getTanks(ForgeDirection direction)
{ {
return null; return new ILiquidTank[] { this.tank };
} }
/** @Override
* collects and sorts the surrounding TE for valid connections public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
*/ {
public void validataConnections() return null;
{ }
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 * collects and sorts the surrounding TE for valid connections
*/ */
public void updatePressure() public void validataConnections()
{ {
int highestPressure = 0; this.connectedBlocks = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord);
this.presure = 0; 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;
}
}
}
for (int i = 0; i < 6; i++) /**
{ * updates this units pressure level using the pipe/machines around it
ForgeDirection dir = ForgeDirection.getOrientation(i); */
public void updatePressure()
{
int highestPressure = 0;
this.presure = 0;
if (connectedBlocks[i] instanceof TileEntityPipe) for (int i = 0; i < 6; i++)
{ {
if (((TileEntityPipe) connectedBlocks[i]).getPressure() > highestPressure) ForgeDirection dir = ForgeDirection.getOrientation(i);
{
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 (connectedBlocks[i] instanceof TileEntityPipe)
if (p > highestPressure) {
highestPressure = p; if (((TileEntityPipe) connectedBlocks[i]).getPressure() > highestPressure)
} {
} highestPressure = ((TileEntityPipe) connectedBlocks[i]).getPressure();
this.presure = highestPressure - 1; }
} }
if (connectedBlocks[i] instanceof IPsiCreator && ((IPsiCreator) connectedBlocks[i]).getCanPressureTo(color.getLiquidData(), dir))
{
public int getPressure() int p = ((IPsiCreator) connectedBlocks[i]).getPressureOut(color.getLiquidData(), dir);
{ if (p > highestPressure)
return this.presure; highestPressure = p;
} }
}
this.presure = highestPressure - 1;
}
public int getPressure()
{
return this.presure;
}
} }