Topic category: Help with Minecraft modding (Java Edition)

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.
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.