Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.advancedcombat.common.item;
- import net.minecraft.client.resources.I18n;
- import net.minecraft.client.util.ITooltipFlag;
- import net.minecraft.enchantment.Enchantment;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.text.ITextComponent;
- import net.minecraft.world.World;
- import net.minecraftforge.api.distmarker.Dist;
- import net.minecraftforge.api.distmarker.OnlyIn;
- import javax.annotation.Nonnull;
- import java.util.List;
- /** Enchantment upgrade item, used for both normal & elite items. */
- public class EnchantmentItem extends ItemBase {
- public static final int TIER_COUNT = 2;
- public Enchantment enchant;
- public boolean single;
- public EnchantmentItem(Enchantment enchantment, boolean isSingle) {
- super(isSingle ? 1 : TIER_COUNT, true, false);
- this.enchant = enchantment;
- this.single = isSingle;
- }
- public EnchantmentItem(Enchantment enchantment) {
- this(enchantment, false);
- }
- /** Sets items name without large lang file. */
- @Override
- public @Nonnull ITextComponent getName(ItemStack stack) {
- String enchantment = I18n.get(this.enchant.getDescriptionId());
- return ITextComponent.nullToEmpty((stack.getDamageValue() > 0 ? "Elite " + enchantment : enchantment) + " Upgrade");
- }
- @OnlyIn(Dist.CLIENT)
- @Override
- public void appendHoverText(ItemStack stack, World world, List<ITextComponent> components, @Nonnull ITooltipFlag flag) {
- int tier = stack.getDamageValue();
- components.add(ITextComponent.nullToEmpty("Upgrades to " + I18n.get(this.enchant.getDescriptionId())));
- if (!single) {
- components.add(ITextComponent.nullToEmpty("Tiers " + (tier * this.enchant.getMaxLevel() + 1) + " - " + (tier + 1) * this.enchant.getMaxLevel()));
- }
- }
- /** Get the enchantment this upgrade represents. */
- public Enchantment getEnchantment() {
- return this.enchant;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement