BloodMagic/src/main/java/WayofTime/bloodmagic/item/alchemy/ItemCuttingFluid.java
Nicholas Ignoffo ddaadfbe52 Swap the API packages
The new one is now built for the api jar and the old one is now internal.
It will slowly be moved around to sane places within the internal code. Most
of the features provided in the old "api" are addon specific features which
will generally rely on the main jar anyways. The new API will be specific
to compatibility features, such as blacklists, recipes, and value modification.
2018-02-05 17:04:46 -08:00

129 lines
4 KiB
Java

package WayofTime.bloodmagic.item.alchemy;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.apibutnotreally.iface.ICustomAlchemyConsumable;
import WayofTime.bloodmagic.apibutnotreally.util.helper.NBTHelper;
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.util.helper.TextHelper;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.List;
public class ItemCuttingFluid extends Item implements IVariantProvider, ICustomAlchemyConsumable {
public static final String BASIC = "basicCuttingFluid";
public static final String EXPLOSIVE = "explosive";
private static ArrayList<String> names = new ArrayList<String>();
public ItemCuttingFluid() {
super();
setUnlocalizedName(BloodMagic.MODID + ".cuttingFluid.");
setHasSubtypes(true);
setCreativeTab(BloodMagic.TAB_BM);
setMaxStackSize(1);
buildItemList();
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
if (!stack.hasTagCompound())
return;
int max = getMaxUsesForFluid(stack);
tooltip.add(TextHelper.localize("tooltip.bloodmagic.cuttingFluidRatio", max - getDamageOfFluid(stack), max));
}
private void buildItemList() {
names.add(0, BASIC);
names.add(1, EXPLOSIVE);
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return super.getUnlocalizedName(stack) + names.get(stack.getItemDamage());
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(CreativeTabs creativeTab, NonNullList<ItemStack> list) {
if (!isInCreativeTab(creativeTab))
return;
for (int i = 0; i < names.size(); i++)
list.add(new ItemStack(this, 1, i));
}
@Override
public List<Pair<Integer, String>> getVariants() {
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
for (String name : names)
ret.add(new ImmutablePair<Integer, String>(names.indexOf(name), "type=" + name));
return ret;
}
public int getDamageOfFluid(ItemStack stack) {
NBTHelper.checkNBT(stack);
NBTTagCompound tag = stack.getTagCompound();
return tag.getInteger("used");
}
public void applyDamageToFluid(ItemStack stack) {
int damage = Math.min(getDamageOfFluid(stack) + 1, getMaxUsesForFluid(stack));
NBTTagCompound tag = stack.getTagCompound();
tag.setInteger("used", damage);
}
public int getMaxUsesForFluid(ItemStack stack) {
switch (stack.getMetadata()) {
case 0:
return 16;
case 1:
return 64;
default:
return 1;
}
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
return (double) (getDamageOfFluid(stack)) / (double) (getMaxUsesForFluid(stack));
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return getDamageOfFluid(stack) > 0;
}
@Override
public ItemStack drainUseOnAlchemyCraft(ItemStack stack) {
applyDamageToFluid(stack);
if (getDamageOfFluid(stack) >= getMaxUsesForFluid(stack)) {
return ItemStack.EMPTY;
}
return stack;
}
public static ItemStack getStack(String name) {
return new ItemStack(RegistrarBloodMagicItems.CUTTING_FLUID, 1, names.indexOf(name));
}
public static ArrayList<String> getNames() {
return names;
}
}