BloodMagic/src/main/java/WayofTime/bloodmagic/item/soul/ItemMonsterSoul.java

123 lines
3.6 KiB
Java
Raw Normal View History

package WayofTime.bloodmagic.item.soul;
import WayofTime.bloodmagic.apibutnotreally.Constants;
import WayofTime.bloodmagic.apibutnotreally.soul.EnumDemonWillType;
import WayofTime.bloodmagic.apibutnotreally.soul.IDemonWill;
import WayofTime.bloodmagic.apibutnotreally.util.helper.NBTHelper;
import WayofTime.bloodmagic.core.RegistrarBloodMagicItems;
import WayofTime.bloodmagic.item.ItemEnum;
import WayofTime.bloodmagic.item.types.ISubItem;
import WayofTime.bloodmagic.util.helper.TextHelper;
2017-08-15 20:21:54 -07:00
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
2017-08-15 20:21:54 -07:00
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
import java.util.List;
import java.util.Locale;
public class ItemMonsterSoul extends ItemEnum.Variant<ItemMonsterSoul.WillType> implements IDemonWill {
2017-08-15 21:30:48 -07:00
public ItemMonsterSoul() {
super(WillType.class, "monster_soul");
setMaxStackSize(1);
}
@Override
@SideOnly(Side.CLIENT)
2017-08-15 21:30:48 -07:00
public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag flag) {
if (!stack.hasTagCompound())
return;
2017-01-02 01:18:29 -08:00
tooltip.add(TextHelper.localize("tooltip.bloodmagic.will", getWill(getType(stack), stack)));
2017-08-15 20:21:54 -07:00
super.addInformation(stack, world, tooltip, flag);
}
@Override
2017-08-15 21:30:48 -07:00
public EnumDemonWillType getType(ItemStack stack) {
return EnumDemonWillType.values()[stack.getItemDamage() % 5];
}
@Override
2017-08-15 21:30:48 -07:00
public double getWill(EnumDemonWillType type, ItemStack soulStack) {
if (type != this.getType(soulStack)) {
return 0;
}
NBTHelper.checkNBT(soulStack);
NBTTagCompound tag = soulStack.getTagCompound();
return tag.getDouble(Constants.NBT.SOULS);
}
@Override
2017-08-15 21:30:48 -07:00
public void setWill(EnumDemonWillType type, ItemStack soulStack, double souls) {
NBTHelper.checkNBT(soulStack);
NBTTagCompound tag = soulStack.getTagCompound();
soulStack.setItemDamage(type.ordinal());
tag.setDouble(Constants.NBT.SOULS, souls);
}
@Override
2017-08-15 21:30:48 -07:00
public double drainWill(EnumDemonWillType type, ItemStack soulStack, double drainAmount) {
double souls = getWill(type, soulStack);
double soulsDrained = Math.min(drainAmount, souls);
setWill(type, soulStack, souls - soulsDrained);
return soulsDrained;
}
@Override
2017-08-15 21:30:48 -07:00
public ItemStack createWill(int meta, double number) {
ItemStack soulStack = new ItemStack(this, 1, meta % 5);
setWill(getType(soulStack), soulStack, number);
return soulStack;
}
2016-03-16 01:10:33 -07:00
@Override
2017-08-15 21:30:48 -07:00
public double getWill(ItemStack willStack) {
return this.getWill(EnumDemonWillType.DEFAULT, willStack);
}
@Override
2017-08-15 21:30:48 -07:00
public void setWill(ItemStack willStack, double will) {
this.setWill(EnumDemonWillType.DEFAULT, willStack, will);
}
@Override
2017-08-15 21:30:48 -07:00
public double drainWill(ItemStack willStack, double drainAmount) {
return this.drainWill(EnumDemonWillType.DEFAULT, willStack, drainAmount);
}
public enum WillType implements ISubItem {
RAW,
CORROSIVE,
DESTRUCTIVE,
VENGEFUL,
STEADFAST,
;
@Nonnull
@Override
public String getInternalName() {
return name().toLowerCase(Locale.ROOT);
}
@Nonnull
@Override
public ItemStack getStack(int count) {
return new ItemStack(RegistrarBloodMagicItems.MONSTER_SOUL, count, ordinal());
}
}
}