Fixed a pipe error plus changed some functions

This is were bug testers are so nice. Turns out that machine from other
mods could directly put the wrong liquid into the pipe the way i had it
coded.

Also i'm going to work threw my api and clean it up the best i can. A
few of the functions i have are unneed as well as not very well made.
This commit is contained in:
Rseifert 2013-02-23 12:05:17 -05:00
parent f86ec909b7
commit 87308ec86b
10 changed files with 119 additions and 110 deletions

View file

@ -1 +1 @@
22
23

View file

@ -20,3 +20,4 @@ x Fluid-Mechanics_v0.2.7.19.jar Fluid-Mechanics_v0.2.7.19_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
@ Fluid-Mechanics_v0.2.8.23.jar hydraulic_v0.2.8.23_api.zip

View file

@ -1 +1 @@
0.2.7
0.2.8

View file

@ -78,7 +78,6 @@ public class TileEntityReleaseValve extends TileEntityAdvanced implements IPsiCr
{
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);
}
}
@ -95,7 +94,7 @@ public class TileEntityReleaseValve extends TileEntityAdvanced implements IPsiCr
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 (pipe.getColor().getLiquidData().getStack().isLiquidEqual(stack) && (tank.getLiquid() == null || tank.getLiquid().amount < tank.getCapacity()))
{
//
return pipe;

View file

@ -102,7 +102,7 @@ public class TileEntitySink extends TileEntity implements IPacketReceiver, ITank
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (resource == null || (!LiquidHandler.isEqual(resource, color.getLiquidData().getStack()))) { return 0; }
if (resource == null || (!color.getLiquidData().getStack().isLiquidEqual(resource))) { return 0; }
return this.fill(0, resource, doFill);
}

View file

@ -117,7 +117,7 @@ public class TileEntityTank extends TileEntity implements IPacketReceiver, IRead
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if (resource == null || (!LiquidHandler.isEqual(resource, color.getLiquidData().getStack()) && this.color != ColorCode.NONE)) { return 0; }
if (resource == null || (!color.getLiquidData().getStack().isLiquidEqual(resource) && this.color != ColorCode.NONE)) { return 0; }
return this.fill(0, resource, doFill);
}

View file

@ -202,10 +202,9 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
return 0;
}
LiquidStack stack = tank.getLiquid();
if (color != ColorCode.NONE)
if (this.color.isValidLiquid(resource))
{
if (stack == null || LiquidHandler.isEqual(resource, this.color.getLiquidData()))
if (stack == null || (stack != null && stack.isLiquidEqual(resource)))
{
return this.fill(0, resource, doFill);
}
@ -215,17 +214,7 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
}
}
else
{
if (stack == null || LiquidHandler.isEqual(stack, resource))
{
return this.fill(0, resource, doFill);
}
else
{
return this.causeMix(stack, resource);
}
}
return 0;
}
@Override
@ -245,12 +234,12 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
return 0;
}
// water flowing into lava creates obby
if (LiquidHandler.isEqual(stored, LiquidHandler.lava) && LiquidHandler.isEqual(fill, LiquidHandler.water))
if (fill.isLiquidEqual(LiquidHandler.lava.getStack()) && fill.isLiquidEqual(LiquidHandler.water.getStack()))
{
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))
else if (fill.isLiquidEqual(LiquidHandler.water.getStack()) && fill.isLiquidEqual(LiquidHandler.lava.getStack()))
{
worldObj.setBlockWithNotify(xCoord, yCoord, zCoord, Block.cobblestone.blockID);
return fill.amount;
@ -287,6 +276,10 @@ public class TileEntityPipe extends TileEntity implements ITankContainer, IReadO
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
if(this.color.isValidLiquid(type))
{
return this.tank;
}
return null;
}

View file

@ -1,74 +1,111 @@
package hydraulic.core.implement;
import java.util.ArrayList;
import java.util.List;
import net.minecraftforge.liquids.LiquidStack;
import hydraulic.core.liquids.LiquidData;
import hydraulic.core.liquids.LiquidHandler;
public enum ColorCode
{
BLACK("Black"),
RED("Red"),
GREEN("Green"),
BROWN("Brown"),
BLUE("Blue"),
PURPLE("Purple"),
CYAN("Cyan"),
SILVER("Silver"),
GREY("Grey"),
PINK("Pink"),
LIME("Lime"),
YELLOW("Yellow"),
LIGHTBLUE("LightBlue"),
WHITE("White"),
ORANGE("Orange"),
NONE("");
String name;
BLACK("Black"), RED("Red"), GREEN("Green"), BROWN("Brown"), BLUE("Blue"), PURPLE("Purple"), CYAN("Cyan"), SILVER("Silver"), GREY("Grey"), PINK("Pink"), LIME("Lime"), YELLOW("Yellow"), LIGHTBLUE("LightBlue"), WHITE("White"), ORANGE("Orange"), NONE("");
private ColorCode(String name)
{
this.name = name;
}
String name;
public String getName()
{
return this.name;
}
private ColorCode(String name)
{
this.name = name;
}
/** gets a ColorCode from any of the following
*
* @param obj
* - Integer,String,LiquidData,ColorCode
* @return Color NONE if it can't find it */
public static ColorCode get(Object obj)
{
if (obj instanceof Integer && ((Integer) obj) < ColorCode.values().length)
{
return ColorCode.values()[((Integer) obj)];
} else if (obj instanceof LiquidData)
{
return ((LiquidData) obj).getColor();
} else if (obj instanceof ColorCode)
{
return (ColorCode) obj;
} else if (obj instanceof String)
{
for (int i = 0; i < ColorCode.values().length; i++)
{
if (((String) obj).equalsIgnoreCase(ColorCode.get(i).getName())) { return ColorCode.get(i); }
}
}
return NONE;
}
public String getName()
{
return this.name;
}
/** gets the liquidData linked with this color. in rare cases there could be
* more than one, but first instance will be returned */
public LiquidData getLiquidData()
{
for (LiquidData data : LiquidHandler.allowedLiquids)
{
if (data.getColor() == this) { return data; }
}
return LiquidHandler.unkown;
}
/**
* gets a ColorCode from any of the following
*
* @param obj - Integer,String,LiquidData,ColorCode
* @return Color NONE if it can't find it
*/
public static ColorCode get(Object obj)
{
if (obj instanceof Integer && ((Integer) obj) < ColorCode.values().length)
{
return ColorCode.values()[((Integer) obj)];
}
else if (obj instanceof LiquidData)
{
return ((LiquidData) obj).getColor();
}
else if (obj instanceof ColorCode)
{
return (ColorCode) obj;
}
else if (obj instanceof String)
{
for (int i = 0; i < ColorCode.values().length; i++)
{
if (((String) obj).equalsIgnoreCase(ColorCode.get(i).getName()))
{
return ColorCode.get(i);
}
}
}
return NONE;
}
/**
* gets the liquidData linked with this color
*/
public LiquidData getLiquidData()
{
for (LiquidData data : LiquidHandler.allowedLiquids)
{
if (data.getColor() == this)
{
return data;
}
}
return LiquidHandler.unkown;
}
/**
* Gets a list of LiquidData that are linked with the color
*/
public List<LiquidData> getAllLiquidData()
{
List<LiquidData> validLiquids = new ArrayList<LiquidData>();
for (LiquidData data : LiquidHandler.allowedLiquids)
{
if (data.getColor() == this && !validLiquids.contains(data))
{
validLiquids.add(data);
}
}
return validLiquids;
}
/**
* checks to see if the liquidStack is valid for the given color
*/
public boolean isValidLiquid(LiquidStack stack)
{
if (stack == null)
{
return false;
}
if (this == NONE)
{
return true;
}
for (LiquidData data : LiquidHandler.allowedLiquids)
{
if (data.getStack().isLiquidEqual(stack) && data.getColor() == this)
{
return true;
}
}
return false;
}
}

View file

@ -35,7 +35,7 @@ public class HydraulicNetwork
*/
public void startProducing(TileEntity tileEntity, FluidPacket pack)
{
if (tileEntity != null && pack.liquidStack != null && LiquidHandler.isEqual(stack, pack.liquidStack))
if (tileEntity != null && pack.liquidStack != null && stack.isLiquidEqual(pack.liquidStack))
{
this.producers.put(tileEntity, pack);
}
@ -64,7 +64,7 @@ public class HydraulicNetwork
*/
public void startRequesting(TileEntity tileEntity, FluidPacket pack)
{
if (tileEntity != null && pack.liquidStack != null && LiquidHandler.isEqual(stack, pack.liquidStack))
if (tileEntity != null && pack.liquidStack != null && stack.isLiquidEqual(pack.liquidStack))
{
this.consumers.put(tileEntity, pack);
}

View file

@ -103,7 +103,7 @@ public class LiquidHandler
{
for (LiquidData data : LiquidHandler.allowedLiquids)
{
if (isEqual(stack, data)) { return data; }
if (stack.isLiquidEqual(data.getStack())) { return data; }
}
return unkown;
}
@ -123,8 +123,7 @@ public class LiquidHandler
Map<String, LiquidStack> l = LiquidDictionary.getLiquids();
for (Entry<String, LiquidStack> liquid : l.entrySet())
{
LiquidStack t = liquid.getValue();
if (isEqual(t, stack)) { return liquid.getKey(); }
if (liquid.getValue().isLiquidEqual(stack)) { return liquid.getKey(); }
}
}
return "unkown";
@ -166,27 +165,7 @@ public class LiquidHandler
if (data.getStack().itemID == id) { return data; }
}
return unkown;
}
/**
* Compares a liquidStack to a sample stack stored in the LiquidData
*/
public static boolean isEqual(LiquidStack stack, LiquidData type)
{
if (stack == null || type == null) { return false; }
if (type.getStack().itemID == stack.itemID && type.getStack().itemMeta == stack.itemMeta) { return true; }
return false;
}
/**
* Compares one liquidStack to another LiquidStack
*/
public static boolean isEqual(LiquidStack stack, LiquidStack stack2)
{
if (stack == null || stack2 == null)
return false;
if (stack2.itemID == stack.itemID && stack2.itemMeta == stack.itemMeta) { return true; }
return false;
}
}
/**
* Consumes one item of a the ItemStack
*/