/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Apr 24, 2014, 2:55:28 PM (GMT)]
*/
package vazkii.botania.common.item.equipment.bauble;
import java.util.List;
import javax.annotation.Nonnull;
import baubles.api.BaubleType;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import vazkii.botania.api.mana.IManaItem;
import vazkii.botania.api.mana.IManaTooltipDisplay;
import vazkii.botania.common.core.helper.ItemNBTHelper;
import vazkii.botania.common.lib.LibItemNames;
public class ItemManaRing extends ItemBauble implements IManaItem, IManaTooltipDisplay {
protected static final int MAX_MANA = 500000;
private static final String TAG_MANA = "mana";
public ItemManaRing() {
this(LibItemNames.MANA_RING);
}
public ItemManaRing(String name) {
super(name);
}
@Override
public BaubleType getBaubleType(ItemStack itemstack) {
return BaubleType.RING;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(@Nonnull Item item, CreativeTabs tab, NonNullList<ItemStack> stacks) {
stacks.add(new ItemStack(item));
ItemStack full = new ItemStack(item);
setMana(full, getMaxMana(full));
stacks.add(full);
}
@Override
public int getEntityLifespan(ItemStack itemStack, World world) {
return Integer.MAX_VALUE;
}
public static void setMana(ItemStack stack, int mana) {
ItemNBTHelper.setInt(stack, TAG_MANA, mana);
}
@Override
public int getMana(ItemStack stack) {
return ItemNBTHelper.getInt(stack, TAG_MANA, 0);
}
@Override
public int getMaxMana(ItemStack stack) {
return MAX_MANA;
}
@Override
public void addMana(ItemStack stack, int mana) {
setMana(stack, Math.min(getMana(stack) + mana, getMaxMana(stack)));
}
@Override
public boolean canReceiveManaFromPool(ItemStack stack, TileEntity pool) {
return true;
}
@Override
public boolean canReceiveManaFromItem(ItemStack stack, ItemStack otherStack) {
return true;
}
@Override
public boolean canExportManaToPool(ItemStack stack, TileEntity pool) {
return true;
}
@Override
public boolean canExportManaToItem(ItemStack stack, ItemStack otherStack) {
return true;
}
@Override
public boolean isNoExport(ItemStack stack) {
return false;
}
@Override
public float getManaFractionForDisplay(ItemStack stack) {
return (float) getMana(stack) / (float) getMaxMana(stack);
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return true;
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
return 1.0 - getManaFractionForDisplay(stack);
}
@Override
public int getRGBDurabilityForDisplay(ItemStack stack) {
return MathHelper.hsvToRGB(getManaFractionForDisplay(stack) / 3.0F, 1.0F, 1.0F);
}
}