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,19 +24,17 @@ 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];
private List<TileEntityPipe> output = new ArrayList<TileEntityPipe>();
private List<ILiquidTank> input = new ArrayList<ILiquidTank>();
private int ticks = 0;
private List<ITankContainer> input = new ArrayList<ITankContainer>();
public boolean isPowered = false;
public boolean converted = false;
private ItemStack[] inventory = new ItemStack[0];
@ -44,42 +42,44 @@ public class TileEntityReleaseValve extends TileEntity implements IPsiCreator, I
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
{
this.isPowered = worldObj.isBlockGettingPowered(xCoord, yCoord, zCoord) || worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
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;
}
}
if (!this.worldObj.isRemote && ticks++ >= 20)
else
{
connected[i] = null;
}
}
if (!this.worldObj.isRemote && this.ticks % 20 == 0)
{
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)
for (ITankContainer drainedTank : input)
{
if (tank.getLiquid() != null && tank.getLiquid().amount > 0)
LiquidStack stack = drainedTank.drain(ForgeDirection.UNKNOWN, TileEntityPipe.maxVolume, false);
if (stack != null && stack.amount > 0)
{
//FMLLog.warning("Tank: " + LiquidHandler.getName(tank.getLiquid()) + " Vol: " + tank.getLiquid().amount);
TileEntityPipe pipe = this.findValidPipe(tank.getLiquid());
if (pipe != null)
TileEntityPipe inputPipe = this.findValidPipe(stack);
if (inputPipe != 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);
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);
}
}
}
@ -91,12 +91,11 @@ public class TileEntityReleaseValve extends TileEntity implements IPsiCreator, I
/** 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()))
if (LiquidHandler.isEqual(pipe.getColor().getLiquidData().getStack(), stack) && (tank.getLiquid() == null || tank.getLiquid().amount < tank.getCapacity()))
{
//
return pipe;
@ -105,7 +104,10 @@ public class TileEntityReleaseValve extends TileEntity implements IPsiCreator, I
// if no color selective pipe is found look for generic pipes
for (TileEntityPipe pipe : output)
{
if (pipe.getColor() == ColorCode.NONE) { return pipe; }
if (pipe.getColor() == ColorCode.NONE)
{
return pipe;
}
}
return null;
@ -118,36 +120,47 @@ public class TileEntityReleaseValve extends TileEntity implements IPsiCreator, 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;
}
/** if any of allowed list is true
/**
* if any of allowed list is true
*
* @return true */
* @return true
*/
public boolean isRestricted()
{
for (int i = 0; i < this.allowed.length; i++)
{
if (allowed[i]) { return true; }
if (allowed[i])
{
return true;
}
}
return false;
}
/** checks a liquidstack against its color code
/**
* checks a liquidstack against its color code
*
* @param stack
* @return */
* @return
*/
public boolean canAcceptLiquid(LiquidStack stack)
{
if (!this.isRestricted()) { return true; }
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)
* and fill-able(TileEntityPipes) instances
*/
public void validateNBuildList()
{
// cleanup
@ -186,7 +199,8 @@ public class TileEntityReleaseValve extends TileEntity implements IPsiCreator, I
{
if (this.canAcceptLiquid(ll))
{
this.input.add(tanks[t]);
this.input.add((ITankContainer) ent);
break;
}
}
}
@ -201,17 +215,13 @@ public class TileEntityReleaseValve extends TileEntity implements IPsiCreator, I
@Override
public int getPressureOut(LiquidData type, ForgeDirection dir)
{
if (type == null) return 0;
if (this.canConnect(type.getColor())) { return type.getPressure(); }
return 0;
return (type != null && this.canConnect(type.getColor()) ? type.getPressure() : 0);
}
@Override
public boolean getCanPressureTo(LiquidData type, ForgeDirection dir)
{
if (type == null) return false;
if (this.canConnect(type.getColor())) return true;
return false;
return type != null && this.canConnect(type.getColor());
}
@Override
@ -229,11 +239,11 @@ public class TileEntityReleaseValve extends TileEntity implements IPsiCreator, I
}
if (!this.isPowered)
{
output += " Running ";
output += " Open ";
}
else
{
output += " Offline ";
output += " Closed ";
}
return output;
}
@ -258,122 +268,4 @@ public class TileEntityReleaseValve extends TileEntity implements IPsiCreator, 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()
{
}
}

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;
@ -33,7 +34,9 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
public TileEntity[] connectedBlocks = new TileEntity[6];
private LiquidTank stored = new LiquidTank(LiquidContainerRegistry.BUCKET_VOLUME * 2);
public static final int maxVolume = LiquidContainerRegistry.BUCKET_VOLUME * 2;
private LiquidTank tank = new LiquidTank(maxVolume);
@Override
public void updateEntity()
@ -49,7 +52,7 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
{
this.randomDisplayTick();
}
LiquidStack stack = stored.getLiquid();
LiquidStack stack = tank.getLiquid();
if (!worldObj.isRemote && stack != null && stack.amount >= 0)
{
@ -63,7 +66,7 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
{
if (((TileEntityPipe) connectedBlocks[i]).presure < this.presure)
{
stored.drain(((TileEntityPipe) connectedBlocks[i]).fill(dir, stack, true), true);
tank.drain(((TileEntityPipe) connectedBlocks[i]).fill(dir, stack, true), true);
}
}
@ -79,12 +82,12 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
}
else
{
stored.drain(((ITankContainer) connectedBlocks[i]).fill(dir.getOpposite(), stack, true), true);
tank.drain(((ITankContainer) connectedBlocks[i]).fill(dir.getOpposite(), stack, true), true);
}
}
else
{
stored.drain(((ITankContainer) connectedBlocks[i]).fill(dir.getOpposite(), stack, true), true);
tank.drain(((ITankContainer) connectedBlocks[i]).fill(dir.getOpposite(), stack, true), true);
}
}
@ -101,7 +104,7 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
public void randomDisplayTick()
{
Random random = new Random();
LiquidStack stack = stored.getLiquid();
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
@ -160,7 +163,10 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
LiquidStack liquid = new LiquidStack(0, 0, 0);
liquid.readFromNBT(nbt.getCompoundTag("stored"));
stored.setLiquid(liquid);
if (Item.itemsList[liquid.itemID] != null && liquid.amount > 0)
{
this.tank.setLiquid(liquid);
}
}
/**
@ -170,17 +176,20 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
if (stored.getLiquid() != null)
if (tank.getLiquid() != null)
{
nbt.setTag("stored", stored.getLiquid().writeToNBT(new NBTTagCompound()));
nbt.setTag("stored", tank.getLiquid().writeToNBT(new NBTTagCompound()));
}
}
@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"; }
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";
}
return "Empty" + " @ " + this.presure + "p";
}
@ -188,8 +197,11 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (resource == null) { return 0; }
LiquidStack stack = stored.getLiquid();
if (resource == null)
{
return 0;
}
LiquidStack stack = tank.getLiquid();
if (color != ColorCode.NONE)
{
@ -219,13 +231,19 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
if (tankIndex != 0 || resource == null) { return 0; }
return stored.fill(resource, doFill);
if (tankIndex != 0 || resource == null)
{
return 0;
}
return tank.fill(resource, doFill);
}
public int causeMix(LiquidStack stored, LiquidStack fill)
{
if (stored == null || fill == null) { return 0; }
if (stored == null || fill == null)
{
return 0;
}
// water flowing into lava creates obby
if (LiquidHandler.isEqual(stored, LiquidHandler.lava) && LiquidHandler.isEqual(fill, LiquidHandler.water))
{
@ -240,10 +258,10 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
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;
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.stored.setLiquid(stack);
this.tank.setLiquid(stack);
return f;
}
}
@ -263,7 +281,7 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[] { this.stored };
return new ILiquidTank[] { this.tank };
}
@Override