diff --git a/src/main/java/ovh/glitchlabs/masterwild/entity/custom/HedgehogEntity.java b/src/main/java/ovh/glitchlabs/masterwild/entity/custom/HedgehogEntity.java index 9cc533f..116aedb 100644 --- a/src/main/java/ovh/glitchlabs/masterwild/entity/custom/HedgehogEntity.java +++ b/src/main/java/ovh/glitchlabs/masterwild/entity/custom/HedgehogEntity.java @@ -3,11 +3,10 @@ package ovh.glitchlabs.masterwild.entity.custom; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; +import net.minecraft.tags.DamageTypeTags; import net.minecraft.world.damagesource.DamageSource; -import net.minecraft.world.entity.AgeableMob; -import net.minecraft.world.entity.AnimationState; -import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.Mob; +import net.minecraft.world.damagesource.DamageTypes; +import net.minecraft.world.entity.*; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.goal.*; @@ -54,6 +53,19 @@ public class HedgehogEntity extends Animal { 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 @Override public AgeableMob getBreedOffspring(ServerLevel level, AgeableMob partner) {