Jump to content

entity.hurt not working when call player.getCapability


Recommended Posts

I created a capability to store player's mana. This mana is used to control the player of casting items. In a method inside an item class I call the mana capability to verify if the player have the amount of mana required to cast the item. But, when I tried to use in game, the item went into recharge(cooldown) but the entity that I punched was not hurt. When I remove the line code of the capability, everything works.

The method:

    public boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity) {
        ManaCapability manaCapability = player.getCapability(ModCapabilities.MANA_CAPABILITY).orElse(null);
        if (!player.getCooldowns().isOnCooldown(this)) {
            if (manaCapability.getMana() >= this.manaCost) {
                player.getCooldowns().addCooldown(this, this.getPlayerCooldown(player));

                double dano = player.getAttributeValue(ModAttributes.MAGIC_DAMAGE.get());

                DamageSource damage = ModDamageSources.playerMagicAttack(player, player, DirectEntityDamageSource.Type.DAGGER);

                entity.hurt(damage, (float) (dano * multiplier));

        return true;



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.