Husk .java

net.minecraft.world.entity.monster.zombie.Husk (class): members: HuskGroupData, convertsToWhenDrowning, getConversionSound, isSunSensitive, getStepSound.

net.minecraft.world.entity.monster.zombieclass148 linescommonextends Zombie5.1 KB

API Surface (9)

boolean isSunSensitive()
SoundEvent getAmbientSound()
SoundEvent getHurtSound(final DamageSource source)
SoundEvent getDeathSound()
SoundEvent getStepSound()
boolean doHurtTarget(final ServerLevel level, final Entity target)
boolean convertsInWater()
EntityType<? extends Zombie> convertsToWhenDrowning()
EntityDimensions getDefaultDimensions(final Pose pose)

Fields & Constants (2)

BABY_DIMENSIONS
spawnReason

Full Source

Husk.java148 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.monster.zombie;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.server.level.ServerLevel;
5
import net.minecraft.sounds.SoundEvent;
6
import net.minecraft.sounds.SoundEvents;
7
import net.minecraft.util.RandomSource;
8
import net.minecraft.world.DifficultyInstance;
9
import net.minecraft.world.damagesource.DamageSource;
10
import net.minecraft.world.effect.MobEffectInstance;
11
import net.minecraft.world.effect.MobEffects;
12
import net.minecraft.world.entity.Entity;
13
import net.minecraft.world.entity.EntityAttachment;
14
import net.minecraft.world.entity.EntityAttachments;
15
import net.minecraft.world.entity.EntityDimensions;
16
import net.minecraft.world.entity.EntitySpawnReason;
17
import net.minecraft.world.entity.EntityType;
18
import net.minecraft.world.entity.EntityTypes;
19
import net.minecraft.world.entity.EquipmentSlot;
20
import net.minecraft.world.entity.LivingEntity;
21
import net.minecraft.world.entity.Pose;
22
import net.minecraft.world.entity.SpawnGroupData;
23
import net.minecraft.world.entity.animal.camel.CamelHusk;
24
import net.minecraft.world.entity.monster.skeleton.Parched;
25
import net.minecraft.world.item.ItemStack;
26
import net.minecraft.world.item.Items;
27
import net.minecraft.world.level.Level;
28
import net.minecraft.world.level.ServerLevelAccessor;
29
import net.minecraft.world.level.block.LevelEvent;
30
import org.jspecify.annotations.Nullable;
31
32
public class Husk extends Zombie {
33
	private static final EntityDimensions BABY_DIMENSIONS = EntityDimensions.scalable(0.49F, 0.98F)
34
		.withEyeHeight(0.825F)
35
		.withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, 0.0F, 0.1875F, 0.0F));
36
37
	public Husk(final EntityType<? extends Husk> type, final Level level) {
38
		super(type, level);
39
	}
40
41
	@Override
42
	protected boolean isSunSensitive() {
43
		return false;
44
	}
45
46
	@Override
47
	protected SoundEvent getAmbientSound() {
48
		return SoundEvents.HUSK_AMBIENT;
49
	}
50
51
	@Override
52
	protected SoundEvent getHurtSound(final DamageSource source) {
53
		return SoundEvents.HUSK_HURT;
54
	}
55
56
	@Override
57
	protected SoundEvent getDeathSound() {
58
		return SoundEvents.HUSK_DEATH;
59
	}
60
61
	@Override
62
	protected SoundEvent getStepSound() {
63
		return SoundEvents.HUSK_STEP;
64
	}
65
66
	@Override
67
	public boolean doHurtTarget(final ServerLevel level, final Entity target) {
68
		boolean result = super.doHurtTarget(level, target);
69
		if (result && this.getMainHandItem().isEmpty() && target instanceof LivingEntity livingEntity) {
70
			float difficulty = level.getCurrentDifficultyAt(this.blockPosition()).getEffectiveDifficulty();
71
			livingEntity.addEffect(new MobEffectInstance(MobEffects.HUNGER, 140 * (int)difficulty), this);
72
		}
73
74
		return result;
75
	}
76
77
	@Override
78
	protected boolean convertsInWater() {
79
		return true;
80
	}
81
82
	@Override
83
	protected @LevelEvent.Value int getConversionSound() {
84
		return 1041;
85
	}
86
87
	@Override
88
	protected EntityType<? extends Zombie> convertsToWhenDrowning() {
89
		return EntityTypes.ZOMBIE;
90
	}
91
92
	@Override
93
	public @Nullable SpawnGroupData finalizeSpawn(
94
		final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, @Nullable SpawnGroupData groupData
95
	) {
96
		RandomSource random = level.getRandom();
97
		groupData = super.finalizeSpawn(level, difficulty, spawnReason, groupData);
98
		float difficultyModifier = difficulty.getSpecialMultiplier();
99
		if (spawnReason != EntitySpawnReason.CONVERSION) {
100
			this.setCanPickUpLoot(random.nextFloat() < 0.55F * difficultyModifier);
101
		}
102
103
		if (groupData != null) {
104
			groupData = new Husk.HuskGroupData((Zombie.ZombieGroupData)groupData);
105
			((Husk.HuskGroupData)groupData).triedToSpawnCamelHusk = spawnReason != EntitySpawnReason.NATURAL;
106
		}
107
108
		if (groupData instanceof Husk.HuskGroupData huskGroupData && !huskGroupData.triedToSpawnCamelHusk) {
109
			BlockPos pos = this.blockPosition();
110
			if (level.noCollision(EntityTypes.CAMEL_HUSK.getSpawnAABB(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5))) {
111
				huskGroupData.triedToSpawnCamelHusk = true;
112
				if (random.nextFloat() < 0.1F) {
113
					this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SPEAR));
114
					CamelHusk camelHusk = EntityTypes.CAMEL_HUSK.create(this.level(), EntitySpawnReason.NATURAL);
115
					if (camelHusk != null) {
116
						camelHusk.setPos(this.getX(), this.getY(), this.getZ());
117
						camelHusk.finalizeSpawn(level, difficulty, spawnReason, null);
118
						this.startRiding(camelHusk, true, true);
119
						level.addFreshEntity(camelHusk);
120
						Parched parched = EntityTypes.PARCHED.create(this.level(), EntitySpawnReason.NATURAL);
121
						if (parched != null) {
122
							parched.snapTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), 0.0F);
123
							parched.finalizeSpawn(level, difficulty, spawnReason, null);
124
							parched.startRiding(camelHusk, false, false);
125
							level.addFreshEntityWithPassengers(parched);
126
						}
127
					}
128
				}
129
			}
130
		}
131
132
		return groupData;
133
	}
134
135
	@Override
136
	public EntityDimensions getDefaultDimensions(final Pose pose) {
137
		return this.isBaby() ? BABY_DIMENSIONS : super.getDefaultDimensions(pose);
138
	}
139
140
	public static class HuskGroupData extends Zombie.ZombieGroupData {
141
		public boolean triedToSpawnCamelHusk = false;
142
143
		public HuskGroupData(final Zombie.ZombieGroupData groupData) {
144
			super(groupData.isBaby, groupData.canSpawnJockey);
145
		}
146
	}
147
}
148

Decompiled Minecraft 26.3 source of Husk (net/minecraft/world/entity/monster/zombie/Husk.java) with Mojang official mappings, stored verbatim on the site.