Re-added deprecated liquids system. To be removed next major MC versions after issues with Fluids are fixed. (reverse-merged from commit 9b5208fa30)

This WILL be removed and should not be developed against aside for a temporary 1.6 release.
This commit is contained in:
LexManos 2013-07-22 15:19:35 -07:00
parent 8c3ebc7f87
commit b6d543f15e
10 changed files with 1016 additions and 0 deletions

View file

@ -0,0 +1,59 @@
package net.minecraftforge.liquids;
import net.minecraft.nbt.NBTTagCompound;
/**
* Implementors of this interface are a liquid which may receive a block implementation and can be placed in the world.
*
* @author cpw
*
*/
@Deprecated //See new net.minecraftforge.fluids
public interface IBlockLiquid extends ILiquid {
/**
* Controls the type of block that is generated by this IBlockLiquid
*
*/
public enum BlockType {
/**
* No block. Completeness really.
*/
NONE,
/**
* Vanilla style block, up to 8 flowing states. May be able to generate new sources.
*/
VANILLA,
/**
* Finite liquid style, uses cellular automata to model flowing behaviour.
*/
FINITE;
}
/**
* Can this liquid, when placed in a specific configuration, generate new source blocks of the liquid.
* @return if this liquid will generate new sources
*/
public boolean willGenerateSources();
/**
* @return the distance this liquid will flow if placed in the world. Maximum of 7 levels for vanilla types.
*/
public int getFlowDistance();
/**
* @return the RGB rendering for this liquid
*/
public byte[] getLiquidRGB();
/**
* Get the texture file for rendering the liquid
* @return the texture file for this liquid
*/
public String getLiquidBlockTextureFile();
/**
* Custom properties of the liquid.
* @return a compound tag of custom liquid properties
*/
public NBTTagCompound getLiquidProperties();
}

View file

@ -0,0 +1,36 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package net.minecraftforge.liquids;
/**
* Liquids implement this interface
*
*/
@Deprecated //See new net.minecraftforge.fluids
public interface ILiquid {
/**
* The itemId of the liquid item
* @return the itemId
*/
public int stillLiquidId();
/**
* Is this liquid a metadata based liquid
* @return if this is a metadata liquid
*/
public boolean isMetaSensitive();
/**
* The item metadata of the liquid
* @return the metadata of the liquid
*/
public int stillLiquidMeta();
}

View file

@ -0,0 +1,45 @@
package net.minecraftforge.liquids;
/**
* A tank is the unit of interaction with liquid inventories.
*
* @author cpw
*/
@Deprecated //See new net.minecraftforge.fluids
public interface ILiquidTank {
/**
* @return LiquidStack representing the liquid contained in the tank, null if empty.
*/
LiquidStack getLiquid();
/**
* @return capacity of this tank
*/
int getCapacity();
/**
*
* @param resource
* @param doFill
* @return Amount of liquid used for filling.
*/
int fill(LiquidStack resource, boolean doFill);
/**
*
* @param maxDrain
* @param doDrain
* @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

@ -0,0 +1,56 @@
package net.minecraftforge.liquids;
import net.minecraftforge.common.ForgeDirection;
@Deprecated //See new net.minecraftforge.fluids
public interface ITankContainer {
/**
* Fills liquid into internal tanks, distribution is left to the ITankContainer.
* @param from Orientation the liquid is pumped in from.
* @param resource LiquidStack representing the maximum amount of liquid filled into the ITankContainer
* @param doFill If false filling will only be simulated.
* @return Amount of resource that was filled into internal tanks.
*/
int fill(ForgeDirection from, LiquidStack resource, boolean doFill);
/**
* Fills liquid into the specified internal tank.
* @param tankIndex the index of the tank to fill
* @param resource LiquidStack representing the maximum amount of liquid filled into the ITankContainer
* @param doFill If false filling will only be simulated.
* @return Amount of resource that was filled into internal tanks.
*/
int fill(int tankIndex, LiquidStack resource, boolean doFill);
/**
* Drains liquid out of internal tanks, distribution is left to the ITankContainer.
* @param from Orientation the liquid is drained to.
* @param maxDrain Maximum amount of liquid to drain.
* @param doDrain If false draining will only be simulated.
* @return LiquidStack representing the liquid and amount actually drained from the ITankContainer
*/
LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain);
/**
* Drains liquid out of the specified internal tank.
* @param tankIndex the index of the tank to drain
* @param maxDrain Maximum amount of liquid to drain.
* @param doDrain If false draining will only be simulated.
* @return LiquidStack representing the liquid and amount actually drained from the ITankContainer
*/
LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain);
/**
* @param direction tank side: UNKNOWN for default tank set
* @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

@ -0,0 +1,31 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package net.minecraftforge.liquids;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@Deprecated //See new net.minecraftforge.fluids
public class LiquidContainerData {
public final LiquidStack stillLiquid;
public final ItemStack filled;
public final ItemStack container;
public LiquidContainerData(LiquidStack stillLiquid, ItemStack filled, ItemStack container) {
this.stillLiquid = stillLiquid;
this.filled = filled;
this.container = container;
if(stillLiquid == null || filled == null || container == null)
throw new RuntimeException("stillLiquid, filled, or container is null, this is an error");
}
}

View file

@ -0,0 +1,131 @@
package net.minecraftforge.liquids;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@Deprecated //See new net.minecraftforge.fluids
public class LiquidContainerRegistry
{
public static final int BUCKET_VOLUME = 1000;
public static final ItemStack EMPTY_BUCKET = new ItemStack(Item.bucketEmpty);
private static Map<List, LiquidContainerData> mapFilledItemFromLiquid = new HashMap();
private static Map<List, LiquidContainerData> mapLiquidFromFilledItem = new HashMap();
private static Set<List> setContainerValidation = new HashSet();
private static Set<List> setLiquidValidation = new HashSet();
private static ArrayList<LiquidContainerData> liquids = new ArrayList();
/**
* Default registrations
*/
static
{
registerLiquid(new LiquidContainerData(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketWater), new ItemStack(Item.bucketEmpty)));
registerLiquid(new LiquidContainerData(new LiquidStack(Block.lavaStill, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketLava), new ItemStack(Item.bucketEmpty)));
registerLiquid(new LiquidContainerData(new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.potion), new ItemStack(Item.glassBottle)));
// registerLiquid(new LiquidContainerData(new LiquidStack(Item.bucketMilk, LiquidContainerRegistry.BUCKET_VOLUME), new ItemStack(Item.bucketMilk), new ItemStack(Item.bucketEmpty)));
}
/**
* To register a container with a non-bucket size, the LiquidContainerData entry simply needs to use a size other than LiquidManager.BUCKET_VOLUME
*/
public static void registerLiquid(LiquidContainerData data)
{
mapFilledItemFromLiquid.put(Arrays.asList(data.container.itemID, data.container.getItemDamage(), data.stillLiquid.itemID, data.stillLiquid.itemMeta), data);
mapLiquidFromFilledItem.put(Arrays.asList(data.filled.itemID, data.filled.getItemDamage()), data);
setContainerValidation.add(Arrays.asList(data.container.itemID, data.container.getItemDamage()));
setLiquidValidation.add(Arrays.asList(data.stillLiquid.itemID, data.stillLiquid.itemMeta));
liquids.add(data);
}
public static LiquidStack getLiquidForFilledItem(ItemStack filledContainer)
{
if (filledContainer == null)
{
return null;
}
LiquidContainerData ret = mapLiquidFromFilledItem.get(Arrays.asList(filledContainer.itemID, filledContainer.getItemDamage()));
return ret == null ? null : ret.stillLiquid.copy();
}
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer)
{
if (emptyContainer == null || liquid == null)
{
return null;
}
LiquidContainerData ret = mapFilledItemFromLiquid.get(Arrays.asList(emptyContainer.itemID, emptyContainer.getItemDamage(), liquid.itemID, liquid.itemMeta));
if (ret != null && liquid.amount >= ret.stillLiquid.amount)
{
return ret.filled.copy();
}
return null;
}
public static boolean containsLiquid(ItemStack filledContainer, LiquidStack liquid)
{
if (filledContainer == null || liquid == null)
{
return false;
}
LiquidContainerData ret = mapLiquidFromFilledItem.get(Arrays.asList(filledContainer.itemID, filledContainer.getItemDamage()));
return ret != null && ret.stillLiquid.isLiquidEqual(liquid);
}
public static boolean isBucket(ItemStack container)
{
if (container == null)
{
return false;
}
if (container.isItemEqual(EMPTY_BUCKET))
{
return true;
}
LiquidContainerData ret = mapLiquidFromFilledItem.get(Arrays.asList(container.itemID, container.getItemDamage()));
return ret != null && ret.container.isItemEqual(EMPTY_BUCKET);
}
public static boolean isContainer(ItemStack container)
{
return isEmptyContainer(container) || isFilledContainer(container);
}
public static boolean isEmptyContainer(ItemStack emptyContainer)
{
return emptyContainer != null && setContainerValidation.contains(Arrays.asList(emptyContainer.itemID, emptyContainer.getItemDamage()));
}
public static boolean isFilledContainer(ItemStack filledContainer)
{
return filledContainer != null && getLiquidForFilledItem(filledContainer) != null;
}
public static boolean isLiquid(ItemStack item)
{
return item != null && setLiquidValidation.contains(Arrays.asList(item.itemID, item.getItemDamage()));
}
public static LiquidContainerData[] getRegisteredLiquidContainerData()
{
return liquids.toArray(new LiquidContainerData[liquids.size()]);
}
}

View file

@ -0,0 +1,124 @@
package net.minecraftforge.liquids;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableMap;
/**
* When creating liquids you should register them with this class.
*
* @author CovertJaguar <railcraft.wikispaces.com>
*/
@Deprecated //See new net.minecraftforge.fluids
public abstract class LiquidDictionary
{
private static BiMap<String, LiquidStack> liquids = HashBiMap.create();
/**
* When creating liquids you should call this function.
*
* Upon passing it a name and liquid item it will return either
* a preexisting implementation of that liquid or the liquid passed in.
*
*
* @param name the name of the liquid
* @param liquid the liquid to use if one doesn't exist
* @return the matching liquid stack
*/
public static LiquidStack getOrCreateLiquid(String name, LiquidStack liquid)
{
if (liquid == null)
{
throw new NullPointerException("You cannot register a null LiquidStack");
}
LiquidStack existing = liquids.get(name);
if(existing != null) {
return existing.copy();
}
liquids.put(name, liquid.copy());
MinecraftForge.EVENT_BUS.post(new LiquidRegisterEvent(name, liquid));
return liquid;
}
/**
* Returns the liquid matching the name,
* if such a liquid exists.
*
* Can return null.
*
* @param name the name of the liquid
* @param amount the amout of liquid
* @return a liquidstack for the requested liquid
*/
public static LiquidStack getLiquid(String name, int amount)
{
LiquidStack liquid = liquids.get(name);
if(liquid == null)
return null;
liquid = liquid.copy();
liquid.amount = amount;
return liquid;
}
public static LiquidStack getCanonicalLiquid(String name)
{
return liquids.get(name);
}
/**
* Get an immutable list of the liquids defined
*
* @return the defined liquids
*/
public static Map<String, LiquidStack> getLiquids()
{
return ImmutableMap.copyOf(liquids);
}
/**
* Fired when a new liquid is created
*
*/
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();
}
}
static
{
getOrCreateLiquid("Water", new LiquidStack(Block.waterStill, LiquidContainerRegistry.BUCKET_VOLUME));
getOrCreateLiquid("Lava", new LiquidStack(Block.lavaStill, LiquidContainerRegistry.BUCKET_VOLUME));
}
public static String findLiquidName(LiquidStack reference)
{
if (reference != null)
{
return liquids.inverse().get(reference);
}
else
{
return null;
}
}
public static LiquidStack getCanonicalLiquid(LiquidStack liquidStack)
{
return liquids.get(liquids.inverse().get(liquidStack));
}
}

View file

@ -0,0 +1,96 @@
package net.minecraftforge.liquids;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event;
@Deprecated //See new net.minecraftforge.fluids
public class LiquidEvent extends Event {
public final LiquidStack liquid;
public final int x;
public final int y;
public final int z;
public final World world;
public LiquidEvent(LiquidStack liquid, World world, int x, int y, int z)
{
this.liquid = liquid;
this.world = world;
this.x = x;
this.y = y;
this.z = z;
}
/**
* Mods should fire this event when they move liquids around (pipe networks etc)
*
* @author cpw
*
*/
public static class LiquidMotionEvent extends LiquidEvent
{
public LiquidMotionEvent(LiquidStack liquid, World world, int x, int y, int z)
{
super(liquid, world, x, y, z);
}
}
/**
* Mods should fire this event when a liquid is {@link ILiquidTank#fill(LiquidStack, boolean)} their tank implementation.
* {@link LiquidTank} does.
*
* @author cpw
*
*/
public static class LiquidFillingEvent extends LiquidEvent
{
public final ILiquidTank tank;
public LiquidFillingEvent(LiquidStack liquid, World world, int x, int y, int z, ILiquidTank tank)
{
super(liquid, world, x, y, z);
this.tank = tank;
}
}
/**
* Mods should fire this event when a liquid is {@link ILiquidTank#drain(int, boolean)} from their tank.
* @author cpw
*
*/
public static class LiquidDrainingEvent extends LiquidEvent
{
public final ILiquidTank tank;
public LiquidDrainingEvent(LiquidStack liquid, World world, int x, int y, int z, ILiquidTank tank)
{
super(liquid, world, x, y, z);
this.tank = tank;
}
}
/**
* Mods should fire this event when a liquid "spills", for example, if a block containing liquid is broken.
*
* @author cpw
*
*/
public static class LiquidSpilledEvent extends LiquidEvent
{
public LiquidSpilledEvent(LiquidStack liquid, World world, int x, int y, int z)
{
super(liquid, world, x, y, z);
}
}
/**
* A handy shortcut for firing the various liquid events
*
* @param event
*/
public static final void fireEvent(LiquidEvent event)
{
MinecraftForge.EVENT_BUS.post(event);
}
}

View file

@ -0,0 +1,257 @@
package net.minecraftforge.liquids;
import static cpw.mods.fml.relauncher.Side.CLIENT;
import com.google.common.base.Objects;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFluid;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Icon;
/**
* ItemStack substitute for liquids
* Things of note: they are equal if their items are equal. Amount does NOT matter for java equals() testing
* <br/>
* The canonical liquidstack is probably the only one that has a lot of the rendering data on it. Use {@link #canonical()}
* to get it.
*
* @author SirSengir
*/
@Deprecated //See new net.minecraftforge.fluids
public class LiquidStack
{
public final int itemID;
public int amount;
public final int itemMeta;
public NBTTagCompound extra;
public LiquidStack(int itemID, int amount) { this(itemID, amount, 0); }
public LiquidStack(Item item, int amount) { this(item.itemID, amount, 0); }
public LiquidStack(Block block, int amount) { this(block.blockID, amount, 0); }
public LiquidStack(int itemID, int amount, int itemDamage)
{
this.itemID = itemID;
this.amount = amount;
this.itemMeta = itemDamage;
}
public LiquidStack(int itemID, int amount, int itemDamage, NBTTagCompound nbt)
{
this(itemID, amount, itemDamage);
if (nbt != null)
{
extra = (NBTTagCompound)nbt.copy();
}
}
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
nbt.setInteger("Amount", amount);
nbt.setShort("Id", (short)itemID);
nbt.setShort("Meta", (short)itemMeta);
String name = LiquidDictionary.findLiquidName(this);
if(name != null)
{
nbt.setString("LiquidName", name);
}
if (extra != null)
{
nbt.setTag("extra", extra);
}
return nbt;
}
/**
* @return A copy of this LiquidStack
*/
public LiquidStack copy()
{
return new LiquidStack(itemID, amount, itemMeta, extra);
}
/**
* @param other
* @return true if this LiquidStack contains the same liquid as the one passed in.
*/
public boolean isLiquidEqual(LiquidStack other)
{
return other != null && itemID == other.itemID && itemMeta == other.itemMeta && (extra == null ? other.extra == null : extra.equals(other.extra));
}
/**
* @param other
* @return true if this LiquidStack contains the other liquid (liquids are equal and amount >= other.amount).
*/
public boolean containsLiquid(LiquidStack other)
{
return isLiquidEqual(other) && amount >= other.amount;
}
/**
* @param other ItemStack containing liquids.
* @return true if this LiquidStack contains the same liquid as the one passed in.
*/
public boolean isLiquidEqual(ItemStack other)
{
if (other == null)
{
return false;
}
if (itemID == other.itemID && itemMeta == other.getItemDamage())
{
return true;
}
return isLiquidEqual(LiquidContainerRegistry.getLiquidForFilledItem(other));
}
/**
* @return ItemStack representation of this LiquidStack
*/
public ItemStack asItemStack()
{
ItemStack stack = new ItemStack(itemID, 1, itemMeta);
if (extra != null)
{
stack.stackTagCompound = (NBTTagCompound)extra.copy();
}
return stack;
}
/**
* Reads a liquid stack from the passed nbttagcompound and returns it.
*
* @param nbt
* @return the liquid stack
*/
public static LiquidStack loadLiquidStackFromNBT(NBTTagCompound nbt)
{
if (nbt == null)
{
return null;
}
String liquidName = nbt.getString("LiquidName");
int itemID = nbt.getShort("Id");
int itemMeta = nbt.getShort("Meta");
LiquidStack liquid = LiquidDictionary.getCanonicalLiquid(liquidName);
if(liquid != null) {
itemID = liquid.itemID;
itemMeta = liquid.itemMeta;
}
// if the item is not existent, and no liquid dictionary is found, null returns
else if (Item.itemsList[itemID] == null)
{
return null;
}
int amount = nbt.getInteger("Amount");
LiquidStack liquidstack = new LiquidStack(itemID, amount, itemMeta);
if (nbt.hasKey("extra"))
{
liquidstack.extra = nbt.getCompoundTag("extra");
}
return liquidstack.itemID == 0 ? null : liquidstack;
}
private String textureSheet = "/terrain.png";
/**
* Return the textureSheet used for this liquid stack's texture Icon
* Defaults to '/terrain.png'
*
* See {@link #getRenderingIcon()} for the actual icon
*
* @return The texture sheet
*/
public String getTextureSheet()
{
return textureSheet;
}
/**
* Set the texture sheet for this icon (usually /terrain.png or /gui/items.png)
*
* See also the {@link #setRenderingIcon(Icon)} for the icon itself
*
* @param textureSheet
* @return the liquid stack
*/
public LiquidStack setTextureSheet(String textureSheet)
{
this.textureSheet = textureSheet;
return this;
}
@SideOnly(CLIENT)
private Icon renderingIcon;
/**
* Get the rendering icon for this liquid stack, for presentation in the world or in GUIs.
* Defaults to handling water and lava, and returns the set rendering icon otherwise.
*
* See {@link #getTextureSheet()} to get the texture sheet this icon is associated with
*
* @return The icon for rendering this liquid
*/
@SideOnly(CLIENT)
public Icon getRenderingIcon()
{
if (itemID == Block.waterStill.blockID)
{
return BlockFluid.func_94424_b("water");
}
else if (itemID == Block.lavaStill.blockID)
{
return BlockFluid.func_94424_b("lava");
}
return renderingIcon;
}
/**
* Set the icon for rendering this liquid
* It should be refreshed whenever textures are refreshed.
*
* See also {@link #setTextureSheet(String)} for setting the sheet this icon is associated with
*
* @param icon The icon to render
* @return The liquid stack
*/
@SideOnly(CLIENT)
public LiquidStack setRenderingIcon(Icon icon)
{
this.renderingIcon = icon;
return this;
}
@Override
public final int hashCode()
{
return 31 * itemMeta + itemID;
}
@Override
public final boolean equals(Object ob)
{
if (ob instanceof LiquidStack)
{
LiquidStack ls = (LiquidStack)ob;
return ls.itemID == itemID && ls.itemMeta == itemMeta && (extra == null ? ls.extra == null : extra.equals(ls.extra));
}
return false;
}
/**
* Get the canonical version of this liquid stack (will contain things like icons and texturesheets)
* @return The canonical liquidstack
*/
public LiquidStack canonical()
{
return LiquidDictionary.getCanonicalLiquid(this);
}
}

View file

@ -0,0 +1,181 @@
package net.minecraftforge.liquids;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
/**
* Reference implementation of ILiquidTank. Use this or implement your own.
*/
@Deprecated //See new net.minecraftforge.fluids
public class LiquidTank implements ILiquidTank {
private LiquidStack liquid;
private int capacity;
private int tankPressure;
private TileEntity tile;
public LiquidTank(int capacity)
{
this(null, capacity);
}
public LiquidTank(int liquidId, int quantity, int capacity)
{
this(new LiquidStack(liquidId, quantity), capacity);
}
public LiquidTank(int liquidId, int quantity, int capacity, TileEntity tile)
{
this(liquidId, quantity, capacity);
this.tile = tile;
}
public LiquidTank(LiquidStack liquid, int capacity)
{
this.liquid = liquid;
this.capacity = capacity;
}
public LiquidTank(LiquidStack liquid, int capacity, TileEntity tile)
{
this(liquid, capacity);
this.tile = tile;
}
@Override
public LiquidStack getLiquid()
{
return this.liquid;
}
@Override
public int getCapacity()
{
return this.capacity;
}
public void setLiquid(LiquidStack liquid)
{
this.liquid = liquid;
}
public void setCapacity(int capacity)
{
this.capacity = capacity;
}
@Override
public int fill(LiquidStack resource, boolean doFill)
{
if (resource == null || resource.itemID <= 0) return 0;
if (liquid == null || liquid.itemID <= 0)
{
if (resource.amount <= capacity)
{
if (doFill) this.liquid = resource.copy();
return resource.amount;
}
else
{
if (doFill)
{
this.liquid = resource.copy();
this.liquid.amount = capacity;
if (tile != null)
LiquidEvent.fireEvent(new LiquidEvent.LiquidFillingEvent(liquid, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this));
}
return capacity;
}
}
if (!liquid.isLiquidEqual(resource)) return 0;
int space = capacity - liquid.amount;
if (resource.amount <= space)
{
if (doFill) this.liquid.amount += resource.amount;
return resource.amount;
}
else
{
if (doFill) this.liquid.amount = capacity;
return space;
}
}
@Override
public LiquidStack drain(int maxDrain, boolean doDrain)
{
if (liquid == null || liquid.itemID <= 0) return null;
if (liquid.amount <= 0) return null;
int used = maxDrain;
if (liquid.amount < used) used = liquid.amount;
if (doDrain)
{
liquid.amount -= used;
}
LiquidStack drained = new LiquidStack(liquid.itemID, used, liquid.itemMeta);
// Reset liquid if emptied
if (liquid.amount <= 0) liquid = null;
if (doDrain && tile != null)
LiquidEvent.fireEvent(new LiquidEvent.LiquidDrainingEvent(drained, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord, this));
return drained;
}
@Override
public int getTankPressure()
{
return tankPressure;
}
public void setTankPressure(int pressure)
{
this.tankPressure = pressure;
}
public String getLiquidName()
{
return liquid!= null ? LiquidDictionary.findLiquidName(liquid) : null;
}
public boolean containsValidLiquid()
{
return LiquidDictionary.findLiquidName(liquid) != null;
}
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
{
if (containsValidLiquid())
{
liquid.writeToNBT(nbt);
}
else
{
nbt.setString("emptyTank", "");
}
return nbt;
}
public LiquidTank readFromNBT(NBTTagCompound nbt)
{
if (!nbt.hasKey("emptyTank"))
{
LiquidStack liquid = LiquidStack.loadLiquidStackFromNBT(nbt);
if (liquid != null)
{
setLiquid(liquid);
}
}
return this;
}
}