[add] Hedgehog hurt attacker

This commit is contained in:
2026-09-25 22:11:53 +02:00
parent 35e0461c62
commit af67b3d212
@@ -3,11 +3,10 @@ package ovh.glitchlabs.masterwild.entity.custom;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.AgeableMob; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.AnimationState; import net.minecraft.world.entity.*;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.*; import net.minecraft.world.entity.ai.goal.*;
@@ -54,6 +53,19 @@ public class HedgehogEntity extends Animal {
this.goalSelector.addGoal(6, new RandomLookAroundGoal(this)); this.goalSelector.addGoal(6, new RandomLookAroundGoal(this));
} }
@Override
public boolean hurt(DamageSource damageSource, float amount) {
boolean hurt = super.hurt(damageSource, amount);
if (hurt && !this.level().isClientSide() && !this.isDeadOrDying()) {
if (damageSource.getDirectEntity() instanceof LivingEntity attacker
&& !damageSource.is(DamageTypes.THORNS)
&& !damageSource.is(DamageTypeTags.IS_PROJECTILE)) {
attacker.hurt(this.damageSources().thorns(this), 1.0F);
}
}
return hurt;
}
@Nullable @Nullable
@Override @Override
public AgeableMob getBreedOffspring(ServerLevel level, AgeableMob partner) { public AgeableMob getBreedOffspring(ServerLevel level, AgeableMob partner) {