Advertisement
jayhillx

[Advanced Combat] EnchantmentItem

Jan 2nd, 2022
1,856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.96 KB | None | 0 0
  1. package com.advancedcombat.common.item;
  2.  
  3. import net.minecraft.client.resources.I18n;
  4. import net.minecraft.client.util.ITooltipFlag;
  5. import net.minecraft.enchantment.Enchantment;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.util.text.ITextComponent;
  8. import net.minecraft.world.World;
  9. import net.minecraftforge.api.distmarker.Dist;
  10. import net.minecraftforge.api.distmarker.OnlyIn;
  11.  
  12. import javax.annotation.Nonnull;
  13. import java.util.List;
  14.  
  15. /** Enchantment upgrade item, used for both normal & elite items. */
  16. public class EnchantmentItem extends ItemBase {
  17.     public static final int TIER_COUNT = 2;
  18.     public Enchantment enchant;
  19.     public boolean single;
  20.  
  21.     public EnchantmentItem(Enchantment enchantment, boolean isSingle) {
  22.         super(isSingle ? 1 : TIER_COUNT, true, false);
  23.         this.enchant = enchantment;
  24.         this.single = isSingle;
  25.     }
  26.  
  27.     public EnchantmentItem(Enchantment enchantment) {
  28.         this(enchantment, false);
  29.     }
  30.  
  31.     /** Sets items name without large lang file. */
  32.     @Override
  33.     public @Nonnull ITextComponent getName(ItemStack stack) {
  34.         String enchantment = I18n.get(this.enchant.getDescriptionId());
  35.  
  36.         return ITextComponent.nullToEmpty((stack.getDamageValue() > 0 ? "Elite " + enchantment : enchantment) + " Upgrade");
  37.     }
  38.  
  39.     @OnlyIn(Dist.CLIENT)
  40.     @Override
  41.     public void appendHoverText(ItemStack stack, World world, List<ITextComponent> components, @Nonnull ITooltipFlag flag) {
  42.         int tier = stack.getDamageValue();
  43.  
  44.         components.add(ITextComponent.nullToEmpty("Upgrades to " + I18n.get(this.enchant.getDescriptionId())));
  45.  
  46.         if (!single) {
  47.             components.add(ITextComponent.nullToEmpty("Tiers " + (tier * this.enchant.getMaxLevel() + 1) + " - " + (tier + 1) * this.enchant.getMaxLevel()));
  48.         }
  49.     }
  50.  
  51.     /** Get the enchantment this upgrade represents. */
  52.     public Enchantment getEnchantment() {
  53.         return this.enchant;
  54.     }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement