Why isn't my damage handling procedure working?

Started by aRllX on

Topic category: Help with Minecraft modding (Java Edition)

Joined Oct 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Why isn't my damage handling procedure working?



 

public class HSPFProcedure {

    public static void execute(LevelAccessor world, Entity entity, Entity sourceentity, ItemStack itemstack) {

        if (entity == null || sourceentity == null)

            return;

        if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SHARPNESS, itemstack) != 0) {

            entity.hurt(new DamageSource(world.registryAccess().registryOrThrow(Registries.DAMAGE_TYPE).getHolderOrThrow(DamageTypes.PLAYER_ATTACK), sourceentity), itemstack.getEnchantmentLevel(Enchantments.SHARPNESS) * 1);

            Mod.LOGGER.info((entity instanceof LivingEntity _livEnt ? _livEnt.getMaxHealth() : -1) - (entity instanceof LivingEntity _livEnt ? _livEnt.getHealth() : -1));

            Mod.LOGGER.info(EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SHARPNESS, itemstack) != 0);

        }

    }

}


When living entity is hit with tool triggers

I found that changing the Event/target entity to the Source entity, or setting the value to 10, made it work correctly.

Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
In that trigger the target…
Wed, 10/29/2025 - 05:46

In that trigger the target is the mob that is attacked, while the source is the mob that deals the damage with the tool, if you've solved this issue it's recommended you put [SOLVED] in your forum title.