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;
}
}
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) connected = connectionHelper.getSurroundingTileEntities(this);
{
//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);
}
}
}
}
} 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 */ if (!this.worldObj.isRemote && this.ticks % 20 == 0)
public TileEntityPipe findValidPipe(LiquidStack stack) {
{ validateNBuildList();
// start the draining process
// find normal color selective pipe first if (this.input.size() > 0 && this.output.size() > 0)
for (TileEntityPipe pipe : output) {
{ for (ITankContainer drainedTank : input)
ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0]; {
if (LiquidHandler.isEqual(pipe.getColor().getLiquidData().getStack(),stack) && (tank.getLiquid() == null || tank.getLiquid().amount < tank.getCapacity())) LiquidStack stack = drainedTank.drain(ForgeDirection.UNKNOWN, TileEntityPipe.maxVolume, false);
{ if (stack != null && stack.amount > 0)
// {
return pipe; TileEntityPipe inputPipe = this.findValidPipe(stack);
} if (inputPipe != null)
} {
// if no color selective pipe is found look for generic pipes ILiquidTank pipeVolume = inputPipe.getTanks(ForgeDirection.UNKNOWN)[0];
for (TileEntityPipe pipe : output) int ammountFilled = inputPipe.fill(ForgeDirection.UNKNOWN, stack, true);
{ System.out.print("/n Amount Drained: "+ammountFilled);
if (pipe.getColor() == ColorCode.NONE) { return pipe; } drainedTank.drain(ForgeDirection.UNKNOWN, ammountFilled, true);
} }
}
return 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;
}
/** if any of allowed list is true /** used to find a valid pipe for filling of the liquid type */
* public TileEntityPipe findValidPipe(LiquidStack stack)
* @return true */ {
public boolean isRestricted() // find normal color selective pipe first
{ for (TileEntityPipe pipe : output)
for (int i = 0; i < this.allowed.length; i++) {
{ ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0];
if (allowed[i]) { return true; } if (LiquidHandler.isEqual(pipe.getColor().getLiquidData().getStack(), stack) && (tank.getLiquid() == null || tank.getLiquid().amount < tank.getCapacity()))
} {
return false; //
} 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 return null;
* }
* @param stack
* @return */
public boolean canAcceptLiquid(LiquidStack stack)
{
if (!this.isRestricted()) { return true; }
return canConnect(ColorCode.get(LiquidHandler.get(stack)));
}
/** Collects info about the surrounding 6 tiles and orders them into /** sees if it can connect to a pipe of some color */
* drain-able(ITankContainer) and fill-able(TileEntityPipes) instances */ public boolean canConnect(ColorCode cc)
public void validateNBuildList() {
{ if (this.isRestricted())
// cleanup {
this.connected = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord); for (int i = 0; i < this.allowed.length; i++)
this.input.clear(); {
this.output.clear(); if (i == cc.ordinal())
// read surroundings {
for (int i = 0; i < 6; i++) return allowed[i];
{ }
ForgeDirection dir = ForgeDirection.getOrientation(i); }
TileEntity ent = connected[i]; }
if (ent instanceof TileEntityPipe) return true;
{ }
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;
}
}
}
@Override /**
public int getPressureOut(LiquidData type, ForgeDirection dir) * if any of allowed list is true
{ *
if (type == null) return 0; * @return true
if (this.canConnect(type.getColor())) { return type.getPressure(); } */
return 0; 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) * checks a liquidstack against its color code
{ *
if (type == null) return false; * @param stack
if (this.canConnect(type.getColor())) return true; * @return
return false; */
} public boolean canAcceptLiquid(LiquidStack stack)
{
return !this.isRestricted() || canConnect(ColorCode.get(LiquidHandler.get(stack)));
}
@Override /**
public String getMeterReading(EntityPlayer user, ForgeDirection side) * Collects info about the surrounding 6 tiles and orders them into drain-able(ITankContainer)
{ * and fill-able(TileEntityPipes) instances
// TODO maybe debug on # of connected units of input/output */
String output = ""; public void validateNBuildList()
if (this.isRestricted()) {
{ // cleanup
output += "Output: Restricted and"; this.connected = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord);
} this.input.clear();
else this.output.clear();
{ // read surroundings
output += " Output: UnRestricted and"; for (int i = 0; i < 6; i++)
} {
if (!this.isPowered) ForgeDirection dir = ForgeDirection.getOrientation(i);
{ TileEntity ent = connected[i];
output += " Running "; if (ent instanceof TileEntityPipe)
} {
else TileEntityPipe pipe = (TileEntityPipe) ent;
{ ILiquidTank tank = pipe.getTanks(ForgeDirection.UNKNOWN)[0];
output += " Offline "; if (this.isRestricted() && this.canConnect(pipe.getColor()))
} {
return output; 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 @Override
public void readFromNBT(NBTTagCompound nbt) public int getPressureOut(LiquidData type, ForgeDirection dir)
{ {
super.readFromNBT(nbt); return (type != null && this.canConnect(type.getColor()) ? type.getPressure() : 0);
for (int i = 0; i < this.allowed.length; i++) }
{
allowed[i] = nbt.getBoolean("allowed" + i);
}
}
/** Writes a tile entity to NBT. */ @Override
@Override public boolean getCanPressureTo(LiquidData type, ForgeDirection dir)
public void writeToNBT(NBTTagCompound nbt) {
{ return type != null && this.canConnect(type.getColor());
super.writeToNBT(nbt); }
for (int i = 0; i < this.allowed.length; i++)
{
nbt.setBoolean("allowed" + i, allowed[i]);
}
}
@Override @Override
public void onPowerOn() public String getMeterReading(EntityPlayer user, ForgeDirection side)
{ {
this.isPowered = true; // 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 readFromNBT(NBTTagCompound nbt)
@Override {
public void onPowerOff() super.readFromNBT(nbt);
{ for (int i = 0; i < this.allowed.length; i++)
this.isPowered = false; {
allowed[i] = nbt.getBoolean("allowed" + i);
} }
}
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];
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 this.validataConnections();
public void updateEntity() 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(); for (int i = 0; i < 6; i++)
this.color = ColorCode.get(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); {
if (++count >= 20) ForgeDirection dir = ForgeDirection.getOrientation(i);
{
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++) if (connectedBlocks[i] instanceof ITankContainer)
{ {
ForgeDirection dir = ForgeDirection.getOrientation(i); 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) }
{ 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 */
stored.drain(((TileEntityPipe) connectedBlocks[i]).fill(dir, stack, true), true); }
} 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)
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
{
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;
}
}
}
}
} 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() if (ColorCode.get(stack) != ColorCode.RED)
{ {
Random random = new Random(); worldObj.spawnParticle("dripWater", xx, zz, yy, 0.0D, 0.0D, 0.0D);
LiquidStack stack = stored.getLiquid(); }
if (stack != null && random.nextInt(10) == 0) else
{ {
// TODO align this with the pipe model so not to drip where there is worldObj.spawnParticle("dripLava", xx, zz, yy, 0.0D, 0.0D, 0.0D);
// 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
else public ColorCode getColor()
{ {
worldObj.spawnParticle("dripLava", xx, zz, yy, 0.0D, 0.0D, 0.0D); return this.color;
} }
}
}
/** /**
* gets the current color mark of the pipe * sets the current color mark of the pipe
*/ */
@Override @Override
public ColorCode getColor() public void setColor(Object cc)
{ {
return this.color; this.color = ColorCode.get(cc);
} }
/** /**
* sets the current color mark of the pipe * sets the current color mark of the pipe
*/ */
@Override public void setColor(int i)
public void setColor(Object cc) {
{ if (i < ColorCode.values().length)
this.color = ColorCode.get(cc); {
} this.color = ColorCode.values()[i];
}
}
/** /**
* sets the current color mark of the pipe * Reads a tile entity from NBT.
*/ */
public void setColor(int i) @Override
{ 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);
* Reads a tile entity from NBT. liquid.readFromNBT(nbt.getCompoundTag("stored"));
*/ if (Item.itemsList[liquid.itemID] != null && liquid.amount > 0)
@Override {
public void readFromNBT(NBTTagCompound nbt) this.tank.setLiquid(liquid);
{ }
super.readFromNBT(nbt); }
LiquidStack liquid = new LiquidStack(0, 0, 0); /**
liquid.readFromNBT(nbt.getCompoundTag("stored")); * Writes a tile entity to NBT.
stored.setLiquid(liquid); */
} @Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (tank.getLiquid() != null)
{
nbt.setTag("stored", tank.getLiquid().writeToNBT(new NBTTagCompound()));
}
}
/** @Override
* Writes a tile entity to NBT. public String getMeterReading(EntityPlayer user, ForgeDirection side)
*/ {
@Override LiquidStack stack = this.tank.getLiquid();
public void writeToNBT(NBTTagCompound nbt) if (stack != null)
{ {
super.writeToNBT(nbt); return (stack.amount / LiquidContainerRegistry.BUCKET_VOLUME) + "/" + (this.tank.getCapacity() / LiquidContainerRegistry.BUCKET_VOLUME) + " " + LiquidHandler.get(stack).getName() + " @ " + this.presure + "p";
if (stored.getLiquid() != null) }
{
nbt.setTag("stored", stored.getLiquid().writeToNBT(new NBTTagCompound()));
}
}
@Override return "Empty" + " @ " + this.presure + "p";
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"; @Override
} public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (resource == null)
{
return 0;
}
LiquidStack stack = tank.getLiquid();
if (color != ColorCode.NONE)
{
@Override if (stack == null || LiquidHandler.isEqual(resource, this.color.getLiquidData()))
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) {
{ return this.fill(0, resource, doFill);
if (resource == null) { return 0; } }
LiquidStack stack = stored.getLiquid(); else
if (color != ColorCode.NONE) {
{ return this.causeMix(stack, resource);
}
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
else public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{ {
if (stack == null || LiquidHandler.isEqual(stack, resource)) if (tankIndex != 0 || resource == null)
{ {
return this.fill(0, resource, doFill); return 0;
} }
else return tank.fill(resource, doFill);
{ }
return this.causeMix(stack, resource);
}
}
}
@Override public int causeMix(LiquidStack stored, LiquidStack fill)
public int fill(int tankIndex, LiquidStack resource, boolean doFill) {
{ if (stored == null || fill == null)
if (tankIndex != 0 || resource == null) { return 0; } {
return stored.fill(resource, doFill); 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) @Override
{ public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
if (stored == null || fill == null) { return 0; } {
// water flowing into lava creates obby return null;
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 @Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{ {
return null; return null;
} }
@Override @Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain) public ILiquidTank[] getTanks(ForgeDirection direction)
{ {
return null; return new ILiquidTank[] { this.tank };
} }
@Override @Override
public ILiquidTank[] getTanks(ForgeDirection direction) public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{ {
return new ILiquidTank[] { this.stored }; return null;
} }
@Override /**
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type) * collects and sorts the surrounding TE for valid connections
{ */
return null; 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 * updates this units pressure level using the pipe/machines around it
*/ */
public void validataConnections() public void updatePressure()
{ {
this.connectedBlocks = connectionHelper.getSurroundingTileEntities(worldObj, xCoord, yCoord, zCoord); int highestPressure = 0;
for (int i = 0; i < 6; i++) this.presure = 0;
{
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;
for (int i = 0; i < 6; i++) if (connectedBlocks[i] instanceof TileEntityPipe)
{ {
ForgeDirection dir = ForgeDirection.getOrientation(i); 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) int p = ((IPsiCreator) connectedBlocks[i]).getPressureOut(color.getLiquidData(), dir);
{ if (p > highestPressure)
if (((TileEntityPipe) connectedBlocks[i]).getPressure() > highestPressure) highestPressure = p;
{ }
highestPressure = ((TileEntityPipe) connectedBlocks[i]).getPressure(); }
} this.presure = highestPressure - 1;
} }
if (connectedBlocks[i] instanceof IPsiCreator && ((IPsiCreator) connectedBlocks[i]).getCanPressureTo(color.getLiquidData(), dir))
{
int p = ((IPsiCreator) connectedBlocks[i]).getPressureOut(color.getLiquidData(), dir); public int getPressure()
if (p > highestPressure) {
highestPressure = p; return this.presure;
} }
}
this.presure = highestPressure - 1;
}
public int getPressure()
{
return this.presure;
}
} }