package common.entity.projectile;

import common.enchantment.EnchantmentHelper;
import common.item.ItemStack;
import common.rng.Random;
import common.rng.RngItem;

public class RngFishable extends RngItem
{
    private final ItemStack returnStack;
    private float maxDamagePercent;
    private boolean enchantable;

    public RngFishable(ItemStack returnStackIn, int itemWeightIn)
    {
        super(itemWeightIn);
        this.returnStack = returnStackIn;
    }

    public ItemStack getItemStack(Random random)
    {
        ItemStack itemstack = this.returnStack.copy();

        if (this.maxDamagePercent > 0.0F)
        {
            int i = (int)(this.maxDamagePercent * (float)this.returnStack.getMaxDamage());
            int j = itemstack.getMaxDamage() - random.zrange(random.zrange(i) + 1);

            if (j > i)
            {
                j = i;
            }

            if (j < 1)
            {
                j = 1;
            }

            itemstack.setItemDamage(j);
        }

        if (this.enchantable)
        {
            EnchantmentHelper.addRandomEnchantment(random, itemstack, 30);
        }

        return itemstack;
    }

    public RngFishable setMaxDamagePercent(float maxDamagePercentIn)
    {
        this.maxDamagePercent = maxDamagePercentIn;
        return this;
    }

    public RngFishable setEnchantable()
    {
        this.enchantable = true;
        return this;
    }
}
