@SubscribeEvent
public static void onLivingHurt(LivingHurtEvent event) {
if(event.getEntity().canAttack((LivingEntity) event.getSource().getEntity())){
if(event.getSource().getEntity() instanceof Player player && player.getMainHandItem().getItem() == Items.IRON_SWORD) {
event.getEntity().hurt(DamageSource.GENERIC, event.getAmount() * 0.5F);
}
}
}
@Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
if (target instanceof MobEntity) {
target.hurt(DamageSource.MAGIC, 20);
return super.hurtEnemy(stack, target, attacker);
}
return super.hurtEnemy(stack, target, attacker);
}
у тебя return есть и в if, и за if. Просто убери тот, что в if, ведь они ничем не отличаются.Может можно лучше сделать?
почему бы и нет, если код работает так как нужно, даже наверное будет более актуальным решением чем моеСпасибо, но мне нужно не так в классе SwordITem есть метод hurtEnemy и я в нем проверяю моб ли это если да то наношу урон? Может можно лучше сделать?
Excalibur.java:@Override public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { if (target instanceof MobEntity) { target.hurt(DamageSource.MAGIC, 20); return super.hurtEnemy(stack, target, attacker); } return super.hurtEnemy(stack, target, attacker); }