2012-11-11 02:23:16 +00:00
|
|
|
package net.minecraftforge.liquids;
|
|
|
|
|
2013-03-07 01:54:24 +00:00
|
|
|
import static cpw.mods.fml.relauncher.Side.CLIENT;
|
2013-03-12 20:07:52 +00:00
|
|
|
|
|
|
|
import com.google.common.base.Objects;
|
|
|
|
|
2013-03-07 01:54:24 +00:00
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2012-12-13 05:58:35 +00:00
|
|
|
import net.minecraft.block.Block;
|
2013-03-12 20:07:52 +00:00
|
|
|
import net.minecraft.block.BlockFluid;
|
2013-03-07 01:54:24 +00:00
|
|
|
import net.minecraft.client.renderer.texture.TextureManager;
|
2012-12-13 05:58:35 +00:00
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-03-07 01:54:24 +00:00
|
|
|
import net.minecraft.util.Icon;
|
2012-11-11 02:23:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ItemStack substitute for liquids
|
|
|
|
* @author SirSengir
|
|
|
|
*/
|
2013-01-02 04:57:45 +00:00
|
|
|
public class LiquidStack
|
|
|
|
{
|
|
|
|
public int itemID;
|
|
|
|
public int amount;
|
|
|
|
public int itemMeta;
|
|
|
|
|
|
|
|
private LiquidStack(){}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-22 02:56:04 +00:00
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound nbt)
|
2013-01-02 04:57:45 +00:00
|
|
|
{
|
|
|
|
nbt.setInteger("Amount", amount);
|
2013-03-28 12:04:56 +00:00
|
|
|
nbt.setShort("Id", (short)itemID);
|
2013-01-02 04:57:45 +00:00
|
|
|
nbt.setShort("Meta", (short)itemMeta);
|
2013-03-27 23:09:57 +00:00
|
|
|
nbt.setString("LiquidName", LiquidDictionary.findLiquidName(this));
|
2013-01-02 04:57:45 +00:00
|
|
|
return nbt;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void readFromNBT(NBTTagCompound nbt)
|
|
|
|
{
|
2013-03-27 23:09:57 +00:00
|
|
|
String liquidName = nbt.getString("LiquidName");
|
2013-03-28 09:47:31 +00:00
|
|
|
itemID = nbt.getShort("Id");
|
|
|
|
itemMeta = nbt.getShort("Meta");
|
2013-03-28 12:04:56 +00:00
|
|
|
LiquidStack liquid = LiquidDictionary.getCanonicalLiquid(liquidName);
|
|
|
|
if(liquid != null) {
|
|
|
|
itemID = liquid.itemID;
|
|
|
|
itemMeta = liquid.itemMeta;
|
2013-03-27 23:09:57 +00:00
|
|
|
}
|
2013-01-02 04:57:45 +00:00
|
|
|
amount = nbt.getInteger("Amount");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return A copy of this LiquidStack
|
|
|
|
*/
|
|
|
|
public LiquidStack copy()
|
|
|
|
{
|
|
|
|
return new LiquidStack(itemID, amount, itemMeta);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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)
|
|
|
|
{
|
2013-02-15 12:00:46 +00:00
|
|
|
if (other == null)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemID == other.itemID && itemMeta == other.getItemDamage())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-07 01:54:24 +00:00
|
|
|
|
2013-02-15 12:00:46 +00:00
|
|
|
return isLiquidEqual(LiquidContainerRegistry.getLiquidForFilledItem(other));
|
2013-01-02 04:57:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return ItemStack representation of this LiquidStack
|
|
|
|
*/
|
|
|
|
public ItemStack asItemStack()
|
|
|
|
{
|
|
|
|
return new ItemStack(itemID, 1, itemMeta);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads a liquid stack from the passed nbttagcompound and returns it.
|
|
|
|
*
|
|
|
|
* @param nbt
|
2013-01-22 02:56:04 +00:00
|
|
|
* @return the liquid stack
|
2013-01-02 04:57:45 +00:00
|
|
|
*/
|
|
|
|
public static LiquidStack loadLiquidStackFromNBT(NBTTagCompound nbt)
|
|
|
|
{
|
|
|
|
LiquidStack liquidstack = new LiquidStack();
|
|
|
|
liquidstack.readFromNBT(nbt);
|
|
|
|
return liquidstack.itemID == 0 ? null : liquidstack;
|
|
|
|
}
|
2013-03-07 01:54:24 +00:00
|
|
|
|
|
|
|
@SideOnly(CLIENT)
|
|
|
|
private Icon renderingIcon;
|
|
|
|
|
|
|
|
@SideOnly(CLIENT)
|
|
|
|
public Icon getRenderingIcon()
|
|
|
|
{
|
2013-03-12 20:07:52 +00:00
|
|
|
if (itemID == Block.waterStill.blockID)
|
|
|
|
{
|
|
|
|
return BlockFluid.func_94424_b("water");
|
|
|
|
}
|
|
|
|
else if (itemID == Block.lavaStill.blockID)
|
|
|
|
{
|
|
|
|
return BlockFluid.func_94424_b("lava");
|
|
|
|
}
|
2013-03-07 01:54:24 +00:00
|
|
|
return renderingIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(CLIENT)
|
|
|
|
public void setRenderingIcon(Icon icon)
|
|
|
|
{
|
|
|
|
this.renderingIcon = icon;
|
|
|
|
}
|
2013-03-12 20:07:52 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public final int hashCode()
|
|
|
|
{
|
2013-03-27 23:27:00 +00:00
|
|
|
return 31 * itemID + itemMeta;
|
2013-03-12 20:07:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final boolean equals(Object ob)
|
|
|
|
{
|
|
|
|
return ob instanceof LiquidStack && Objects.equal(((LiquidStack)ob).itemID, itemID) && Objects.equal(((LiquidStack)ob).itemMeta, itemMeta);
|
|
|
|
}
|
2012-11-11 02:23:16 +00:00
|
|
|
}
|