package net.minecraft.world.item.enchantment;

import net.minecraft.world.entity.Entity;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.Util;
import net.minecraft.world.entity.MobType;
import net.minecraft.world.damagesource.DamageSource;
import com.google.common.collect.Maps;
import net.minecraft.world.item.ItemStack;
import java.util.Map;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.core.Registry;
import javax.annotation.Nullable;
import net.minecraft.world.entity.EquipmentSlot;

public abstract class Enchantment {
    private final EquipmentSlot[] slots;
    private final Rarity rarity;
    @Nullable
    public EnchantmentCategory category;
    @Nullable
    protected String descriptionId;
    
    @Nullable
    public static Enchantment byId(final int integer) {
        return Registry.ENCHANTMENT.byId(integer);
    }
    
    protected Enchantment(final Rarity a, final EnchantmentCategory bhy, final EquipmentSlot[] arr) {
        this.rarity = a;
        this.category = bhy;
        this.slots = arr;
    }
    
    public Map<EquipmentSlot, ItemStack> getSlotItems(final LivingEntity akz) {
        final Map<EquipmentSlot, ItemStack> map3 = Maps.newEnumMap(EquipmentSlot.class);
        for (final EquipmentSlot akv7 : this.slots) {
            final ItemStack ben8 = akz.getItemBySlot(akv7);
            if (!ben8.isEmpty()) {
                map3.put(akv7, ben8);
            }
        }
        return map3;
    }
    
    public Rarity getRarity() {
        return this.rarity;
    }
    
    public int getMinLevel() {
        return 1;
    }
    
    public int getMaxLevel() {
        return 1;
    }
    
    public int getMinCost(final int integer) {
        return 1 + integer * 10;
    }
    
    public int getMaxCost(final int integer) {
        return this.getMinCost(integer) + 5;
    }
    
    public int getDamageProtection(final int integer, final DamageSource ajz) {
        return 0;
    }
    
    public float getDamageBonus(final int integer, final MobType ald) {
        return 0.0f;
    }
    
    public final boolean isCompatibleWith(final Enchantment bhx) {
        return this.checkCompatibility(bhx) && bhx.checkCompatibility(this);
    }
    
    protected boolean checkCompatibility(final Enchantment bhx) {
        return this != bhx;
    }
    
    protected String getOrCreateDescriptionId() {
        if (this.descriptionId == null) {
            this.descriptionId = Util.makeDescriptionId("enchantment", Registry.ENCHANTMENT.getKey(this));
        }
        return this.descriptionId;
    }
    
    public String getDescriptionId() {
        return this.getOrCreateDescriptionId();
    }
    
    public Component getFullname(final int integer) {
        final Component lf3 = new TranslatableComponent(this.getDescriptionId(), new Object[0]);
        if (this.isCurse()) {
            lf3.withStyle(ChatFormatting.RED);
        }
        else {
            lf3.withStyle(ChatFormatting.GRAY);
        }
        if (integer != 1 || this.getMaxLevel() != 1) {
            lf3.append(" ").append(new TranslatableComponent("enchantment.level." + integer, new Object[0]));
        }
        return lf3;
    }
    
    public boolean canEnchant(final ItemStack ben) {
        return this.category.canEnchant(ben.getItem());
    }
    
    public void doPostAttack(final LivingEntity akz, final Entity akq, final int integer) {
    }
    
    public void doPostHurt(final LivingEntity akz, final Entity akq, final int integer) {
    }
    
    public boolean isTreasureOnly() {
        return false;
    }
    
    public boolean isCurse() {
        return false;
    }
    
    public enum Rarity {
        COMMON(10), 
        UNCOMMON(5), 
        RARE(2), 
        VERY_RARE(1);
        
        private final int weight;
        
        private Rarity(final int integer3) {
            this.weight = integer3;
        }
        
        public int getWeight() {
            return this.weight;
        }
    }
}
