Some new stuff on the liquid API for better RP2 interaction. Coming soon: blocks!

This commit is contained in:
Christian 2012-11-13 14:27:31 -05:00
parent 52ac3c1af8
commit 1072a8f0ae
4 changed files with 91 additions and 23 deletions

View file

@ -24,4 +24,14 @@ public interface ILiquidTank {
* @return Null if nothing was drained, otherwise a LiquidStack containing the drained.
*/
LiquidStack drain(int maxDrain, boolean doDrain);
/**
* Positive values indicate a positive liquid pressure (liquid wants to leave this tank)
* Negative values indicate a negative liquid pressure (liquid wants to fill this tank)
* Zero indicates no pressure
*
* @return a number indicating tank pressure
*/
public int getTankPressure();
}

View file

@ -40,8 +40,17 @@ public interface ITankContainer {
/**
* @param direction tank side: UNKNOWN for default tank set
* @return Array of {@link LiquidTank}s contained in this ITankContainer
* @return Array of {@link LiquidTank}s contained in this ITankContainer for this direction
*/
ILiquidTank[] getTanks(ForgeDirection direction);
/**
* Return the tank that this tank container desired to be used for the specified liquid type from the specified direction
*
* @param direction the direction
* @param type the liquid type, null is always an acceptable value
* @return a tank or null for no such tank
*/
ILiquidTank getTank(ForgeDirection direction, LiquidStack type);
}

View file

@ -3,6 +3,13 @@ package net.minecraftforge.liquids;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.src.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event;
import net.minecraftforge.oredict.OreDictionary.OreRegisterEvent;
import com.google.common.collect.ImmutableMap;
/**
* When creating liquids you should register them with this class.
*
@ -31,6 +38,7 @@ public abstract class LiquidDictionary
return existing.copy();
}
liquids.put(name, liquid.copy());
MinecraftForge.EVENT_BUS.post(new LiquidRegisterEvent(name, liquid));
return liquid;
}
@ -54,4 +62,33 @@ public abstract class LiquidDictionary
liquid.amount = amount;
return liquid;
}
/**
* Get an immutable list of the liquids defined
*
* @return the defined liquids
*/
public Map<String, LiquidStack> getDefinedLiquids()
{
return ImmutableMap.copyOf(liquids);
}
/**
* Fired when a new liquid is created
*
* @author cpw
*
*/
public static class LiquidRegisterEvent extends Event
{
public final String Name;
public final LiquidStack Liquid;
public LiquidRegisterEvent(String name, LiquidStack liquid)
{
this.Name = name;
this.Liquid = liquid.copy();
}
}
}

View file

@ -6,6 +6,7 @@ package net.minecraftforge.liquids;
public class LiquidTank implements ILiquidTank {
private LiquidStack liquid;
private int capacity;
private int tankPressure;
public LiquidTank(int capacity) {
this(null, capacity);
@ -97,4 +98,15 @@ public class LiquidTank implements ILiquidTank {
return drained;
}
@Override
public int getTankPressure() {
return tankPressure;
}
public void setTankPressure(int pressure)
{
this.tankPressure = pressure;
}
}