Java Code Examples for net.minecraft.entity.EntityLivingBase#renderBrokenItemStack()

The following examples show how to use net.minecraft.entity.EntityLivingBase#renderBrokenItemStack() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemEnderSword.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private boolean addToolDamage(ItemStack stack, int amount, EntityLivingBase living1, EntityLivingBase living2)
{
    if (this.isToolBroken(stack))
    {
        return false;
    }

    amount = Math.min(amount, this.getMaxDamage(stack) - stack.getItemDamage());
    stack.damageItem(amount, living2);

    // Tool just broke
    if (this.isToolBroken(stack))
    {
        living1.renderBrokenItemStack(stack);
    }

    return true;
}
 
Example 2
Source File: ItemEnderSword.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase livingBase)
{
    if (state.getBlockHardness(world, pos) != 0.0f && this.isToolBroken(stack) == false)
    {
        int amount = Math.min(2, this.getMaxDamage(stack) - stack.getItemDamage());
        stack.damageItem(amount, livingBase);

        // Tool just broke
        if (this.isToolBroken(stack))
        {
            livingBase.renderBrokenItemStack(stack);
        }

        return true;
    }

    return false;
}
 
Example 3
Source File: ItemVoidPickaxe.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean addToolDamage(ItemStack stack, int amount, EntityLivingBase living1, EntityLivingBase living2)
{
    //System.out.println("addToolDamage(): living1: " + living1 + " living2: " + living2 + " remote: " + living2.worldObj.isRemote);
    if (this.isToolBroken(stack))
    {
        return false;
    }

    if (amount > 0)
    {
        int unbreakingLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.getEnchantmentByLocation("unbreaking"), stack);
        int amountNegated = 0;

        for (int i = 0; unbreakingLevel > 0 && i < amount; i++)
        {
            if (itemRand.nextInt(amount + 1) > 0)
            {
                amountNegated++;
            }
        }

        amount -= amountNegated;

        if (amount <= 0)
        {
            return false;
        }
    }

    int damage = this.getDamage(stack);
    damage = Math.min(damage + amount, this.material.getMaxUses());

    if (living1.getEntityWorld().isRemote == false)
    {
        this.setDamage(stack, damage);
    }

    // Tool just broke
    if (damage == this.material.getMaxUses())
    {
        //System.out.printf("tool broke @ %s\n", living1.getEntityWorld().isRemote ? "client" : "server");
        living1.renderBrokenItemStack(stack);
    }

    return true;
}
 
Example 4
Source File: ItemEnderTool.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean addToolDamage(ItemStack stack, int amount, EntityLivingBase living1, EntityLivingBase living2)
{
    //System.out.println("addToolDamage(): living1: " + living1 + " living2: " + living2 + " remote: " + living2.worldObj.isRemote);
    if (this.isToolBroken(stack))
    {
        return false;
    }

    if (amount > 0)
    {
        int unbreakingLevel = EnchantmentHelper.getEnchantmentLevel(Enchantment.getEnchantmentByLocation("unbreaking"), stack);
        int amountNegated = 0;

        for (int i = 0; unbreakingLevel > 0 && i < amount; i++)
        {
            if (itemRand.nextInt(amount + 1) > 0)
            {
                amountNegated++;
            }
        }

        amount -= amountNegated;

        if (amount <= 0)
        {
            return false;
        }
    }

    int damage = this.getDamage(stack);
    damage = Math.min(damage + amount, this.material.getMaxUses());
    this.setDamage(stack, damage);

    // Tool just broke
    if (damage == this.material.getMaxUses())
    {
        living1.renderBrokenItemStack(stack);
    }

    return true;
}