updated LiquidHandler's comments and methods

Still need to work on this and maybe break it up into better classes.
This commit is contained in:
Rseifert 2013-03-29 14:05:18 -04:00
parent e8d553c4ef
commit b92214e864
2 changed files with 48 additions and 43 deletions

View file

@ -142,8 +142,10 @@ public class TileEntityMinorPump extends TileEntityElectricityRunnable implement
double amps = (this.WATTS_PER_TICK / this.getVoltage());
return new ElectricityPack(amps, this.getVoltage());
}
/**
* checks to see if this pump can pump the selected target block
*
* @param x y z - location of the block, use the tileEntities world
* @return true if it can pump
*/
@ -152,26 +154,11 @@ public class TileEntityMinorPump extends TileEntityElectricityRunnable implement
int blockID = worldObj.getBlockId(x, y, z);
int meta = worldObj.getBlockMetadata(x, y, z);
LiquidData resource = LiquidHandler.getFromBlockID(blockID);
LiquidData resource = LiquidHandler.getFromBlockAndMetadata(blockID, meta);
ITankContainer fillTarget = getFillTarget();
if (fillTarget == null || fillTarget.fill(pipeConnection, this.color.getLiquidData().getStack(), false) == 0)
{
return false;
}
else if ((LiquidHandler.getFromBlockID(worldObj.getBlockId(x, y, z)) == null || LiquidHandler.getFromBlockID(worldObj.getBlockId(x, y, z)) == LiquidHandler.unkown))
{
return false;
}
else if (blockID == Block.waterMoving.blockID || blockID == Block.lavaMoving.blockID)
{
return false;
}
else if (blockID == Block.waterStill.blockID || blockID == Block.waterStill.blockID)
{
}
// TODO redo this
return true;
}
@ -186,7 +173,7 @@ public class TileEntityMinorPump extends TileEntityElectricityRunnable implement
int blockID = worldObj.getBlockId(loc.intX(), loc.intY(), loc.intZ());
int meta = worldObj.getBlockMetadata(loc.intX(), loc.intY(), loc.intZ());
LiquidData resource = LiquidHandler.getFromBlockID(blockID);
LiquidData resource = LiquidHandler.getFromBlockAndMetadata(blockID, meta);
if (color.isValidLiquid(resource.getStack()) && meta == 0 && getFillTarget().fill(pipeConnection, resource.getStack(), false) != 0)
{

View file

@ -92,6 +92,10 @@ public class LiquidHandler
* Gets the LiquidData linked to the liquid by name
*
* @param name - String name, not case sensitive
*
* @return the data
*
* Note: @LiquidHandler.unkown is the same as null and should be treated that way.
*/
public static LiquidData get(String name)
{
@ -105,6 +109,14 @@ public class LiquidHandler
return unkown;
}
/**
* Gets the LiquidData linked to the liquidStack
*
* @param stack - @LiquidStack
* @return the data
*
* Note: @LiquidHandler.unkown is the same as null and should be treated that way.
*/
public static LiquidData get(LiquidStack stack)
{
for (LiquidData data : LiquidHandler.allowedLiquids)
@ -118,8 +130,11 @@ public class LiquidHandler
}
/**
* gets the name of the liquidStack using either LiquidData or running threw the LiquidDirectory
* mapping
* Gets the name of a LiquidStack using the LiquidData name or Value hidden in the LiquidStack
* map stored at @LiquidDictionary
*
* @param stack - @LiquidStack
* @return - (String) Name of the Stack or unkown if one couldn't be found
*/
public static String getName(LiquidStack stack)
{
@ -142,17 +157,27 @@ public class LiquidHandler
}
/**
* creates a new LiquidStack using type and vol
* Creates a new LiquidStack using the sample stack from the data
*
* @param liquidData - liquidData being used to create the stack
* @param vol - amount or volume of the stack
* @return a new @LiquidStack
*/
public static LiquidStack getStack(LiquidData type, int vol)
public static LiquidStack getStack(LiquidData liquidData, int vol)
{
if (liquidData == null)
{
if (type == null)
return null;
return new LiquidStack(type.getStack().itemID, vol, type.getStack().itemMeta);
}
return new LiquidStack(liquidData.getStack().itemID, vol, liquidData.getStack().itemMeta);
}
/**
* creates a new LiquidStack using a liquidStack and vol
* Creates a new LiquidStack using the sample stack
*
* @param stack - liquidLiquid being used to create the stack
* @param vol - amount or volume of the stack
* @return a new @LiquidStack
*/
public static LiquidStack getStack(LiquidStack stack, int vol)
{
@ -163,25 +188,18 @@ public class LiquidHandler
return new LiquidStack(stack.itemID, vol, stack.itemMeta);
}
public static int getMeta(LiquidData stack)
{
if (stack != null && stack != unkown)
{
return stack.getColor().ordinal();
}
return 15;
}
public static LiquidData getFromMeta(int meta)
{
return ColorCode.get(meta).getLiquidData();
}
public static LiquidData getFromBlockID(int id)
/**
* gets the LiquidData from the blockID and metadata
*
* @param blockID - id used to reference the block in @Block
* @param blockMeta - the blocks sub id from 0-15. -1 will ignore metadata
* @return LiquidData if there is one for this block or unkown in place of null/not found
*/
public static LiquidData getFromBlockAndMetadata(int blockID, int blockMeta)
{
for (LiquidData data : allowedLiquids)
{
if (data.getStack().itemID == id)
if (data.getStack().itemID == blockID)
{
return data;
}