minecraft-src/net/minecraft/world/entity/monster/Husk.java
2025-07-04 02:00:41 +03:00

84 lines
2.4 KiB
Java

package net.minecraft.world.entity.monster;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.RandomSource;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
public class Husk extends Zombie {
public Husk(EntityType<? extends Husk> entityType, Level level) {
super(entityType, level);
}
public static boolean checkHuskSpawnRules(
EntityType<Husk> entityType, ServerLevelAccessor serverLevelAccessor, EntitySpawnReason entitySpawnReason, BlockPos blockPos, RandomSource randomSource
) {
return checkMonsterSpawnRules(entityType, serverLevelAccessor, entitySpawnReason, blockPos, randomSource)
&& (EntitySpawnReason.isSpawner(entitySpawnReason) || serverLevelAccessor.canSeeSky(blockPos));
}
@Override
protected boolean isSunSensitive() {
return false;
}
@Override
protected SoundEvent getAmbientSound() {
return SoundEvents.HUSK_AMBIENT;
}
@Override
protected SoundEvent getHurtSound(DamageSource damageSource) {
return SoundEvents.HUSK_HURT;
}
@Override
protected SoundEvent getDeathSound() {
return SoundEvents.HUSK_DEATH;
}
@Override
protected SoundEvent getStepSound() {
return SoundEvents.HUSK_STEP;
}
@Override
public boolean doHurtTarget(ServerLevel serverLevel, Entity entity) {
boolean bl = super.doHurtTarget(serverLevel, entity);
if (bl && this.getMainHandItem().isEmpty() && entity instanceof LivingEntity) {
float f = this.level().getCurrentDifficultyAt(this.blockPosition()).getEffectiveDifficulty();
((LivingEntity)entity).addEffect(new MobEffectInstance(MobEffects.HUNGER, 140 * (int)f), this);
}
return bl;
}
@Override
protected boolean convertsInWater() {
return true;
}
@Override
protected void doUnderWaterConversion() {
this.convertToZombieType(EntityType.ZOMBIE);
if (!this.isSilent()) {
this.level().levelEvent(null, 1041, this.blockPosition(), 0);
}
}
@Override
protected ItemStack getSkull() {
return ItemStack.EMPTY;
}
}