2016-05-04 19:25:42 -04:00
|
|
|
package WayofTime.bloodmagic.item.alchemy;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
|
|
|
import WayofTime.bloodmagic.api.iface.ICustomAlchemyConsumable;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
|
|
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
|
|
|
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
|
|
|
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
2017-08-15 20:21:54 -07:00
|
|
|
import net.minecraft.client.util.ITooltipFlag;
|
2016-05-04 19:25:42 -04:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2017-01-01 22:26:42 -08:00
|
|
|
import net.minecraft.util.NonNullList;
|
2017-08-15 20:21:54 -07:00
|
|
|
import net.minecraft.world.World;
|
2016-05-04 19:25:42 -04:00
|
|
|
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;
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2016-05-04 19:25:42 -04:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public class ItemCuttingFluid extends Item implements IVariantProvider, ICustomAlchemyConsumable {
|
2016-05-04 19:25:42 -04:00
|
|
|
public static final String BASIC = "basicCuttingFluid";
|
2016-05-05 15:46:09 -04:00
|
|
|
public static final String EXPLOSIVE = "explosive";
|
2017-08-15 21:30:48 -07:00
|
|
|
private static ArrayList<String> names = new ArrayList<String>();
|
2016-05-04 19:25:42 -04:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public ItemCuttingFluid() {
|
2016-05-04 19:25:42 -04:00
|
|
|
super();
|
|
|
|
|
2017-08-14 20:53:42 -07:00
|
|
|
setUnlocalizedName(BloodMagic.MODID + ".cuttingFluid.");
|
2016-05-04 19:25:42 -04:00
|
|
|
setHasSubtypes(true);
|
2017-08-14 20:53:42 -07:00
|
|
|
setCreativeTab(BloodMagic.TAB_BM);
|
2016-05-04 19:25:42 -04:00
|
|
|
setMaxStackSize(1);
|
|
|
|
|
|
|
|
buildItemList();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2017-08-15 21:30:48 -07:00
|
|
|
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
|
2016-09-06 18:55:32 -07:00
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
return;
|
2016-05-04 19:25:42 -04:00
|
|
|
int max = getMaxUsesForFluid(stack);
|
2017-01-02 01:18:29 -08:00
|
|
|
tooltip.add(TextHelper.localize("tooltip.bloodmagic.cuttingFluidRatio", max - getDamageOfFluid(stack), max));
|
2016-05-04 19:25:42 -04:00
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
private void buildItemList() {
|
2016-05-04 19:25:42 -04:00
|
|
|
names.add(0, BASIC);
|
2016-05-05 15:46:09 -04:00
|
|
|
names.add(1, EXPLOSIVE);
|
2016-05-04 19:25:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public String getUnlocalizedName(ItemStack stack) {
|
2016-05-04 19:25:42 -04:00
|
|
|
return super.getUnlocalizedName(stack) + names.get(stack.getItemDamage());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2017-08-15 21:30:48 -07:00
|
|
|
public void getSubItems(CreativeTabs creativeTab, NonNullList<ItemStack> list) {
|
2017-08-15 20:21:54 -07:00
|
|
|
if (!isInCreativeTab(creativeTab))
|
|
|
|
return;
|
|
|
|
|
2016-05-04 19:25:42 -04:00
|
|
|
for (int i = 0; i < names.size(); i++)
|
2017-08-15 20:21:54 -07:00
|
|
|
list.add(new ItemStack(this, 1, i));
|
2016-05-04 19:25:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public List<Pair<Integer, String>> getVariants() {
|
2016-05-04 19:25:42 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public int getDamageOfFluid(ItemStack stack) {
|
2016-05-04 19:25:42 -04:00
|
|
|
NBTHelper.checkNBT(stack);
|
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
|
|
|
|
return tag.getInteger("used");
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public void applyDamageToFluid(ItemStack stack) {
|
2016-05-04 19:25:42 -04:00
|
|
|
int damage = Math.min(getDamageOfFluid(stack) + 1, getMaxUsesForFluid(stack));
|
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
|
|
|
|
tag.setInteger("used", damage);
|
|
|
|
}
|
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public int getMaxUsesForFluid(ItemStack stack) {
|
|
|
|
switch (stack.getMetadata()) {
|
|
|
|
case 0:
|
|
|
|
return 16;
|
|
|
|
case 1:
|
|
|
|
return 64;
|
|
|
|
default:
|
|
|
|
return 1;
|
2016-05-04 19:25:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public double getDurabilityForDisplay(ItemStack stack) {
|
2016-05-04 19:25:42 -04:00
|
|
|
return (double) (getDamageOfFluid(stack)) / (double) (getMaxUsesForFluid(stack));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public boolean showDurabilityBar(ItemStack stack) {
|
2016-05-04 19:25:42 -04:00
|
|
|
return getDamageOfFluid(stack) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-15 21:30:48 -07:00
|
|
|
public ItemStack drainUseOnAlchemyCraft(ItemStack stack) {
|
2016-05-04 19:25:42 -04:00
|
|
|
applyDamageToFluid(stack);
|
2017-08-15 21:30:48 -07:00
|
|
|
if (getDamageOfFluid(stack) >= getMaxUsesForFluid(stack)) {
|
2017-03-05 10:44:55 -08:00
|
|
|
return ItemStack.EMPTY;
|
2016-05-04 19:25:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
}
|
2017-08-15 20:21:54 -07:00
|
|
|
|
2017-08-15 21:30:48 -07:00
|
|
|
public static ItemStack getStack(String name) {
|
|
|
|
return new ItemStack(RegistrarBloodMagicItems.CUTTING_FLUID, 1, names.indexOf(name));
|
|
|
|
}
|
|
|
|
|
2017-08-15 20:21:54 -07:00
|
|
|
public static ArrayList<String> getNames() {
|
|
|
|
return names;
|
|
|
|
}
|
2016-05-04 19:25:42 -04:00
|
|
|
}
|