Zombie .java

net.minecraft.world.entity.monster.zombie.Zombie (class): members: ZOMBIE_REINFORCEMENT_CALLEE_CHARGE, convertVillagerToZombieVillager, canBreakDoors.

net.minecraft.world.entity.monster.zombieclass559 linescommonextends Monster22.1 KB

API Surface (41)

void registerGoals()
void addBehaviourGoals()
AttributeSupplier.Builder createAttributes()
void defineSynchedData(final SynchedEntityData.Builder entityData)
boolean isUnderWaterConverting()
boolean canBreakDoors()
void setCanBreakDoors(final boolean canBreakDoors)
boolean isBaby()
int getBaseExperienceReward(final ServerLevel level)
void setBaby(final boolean baby)
void onSyncedDataUpdated(final EntityDataAccessor<?> accessor)
boolean convertsInWater()
void tick()
boolean convertVillagerToZombieVillager(final ServerLevel level, final Villager villager)
boolean isSunSensitive()
boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage)
boolean doHurtTarget(final ServerLevel level, final Entity target)
SoundEvent getAmbientSound()
SoundEvent getHurtSound(final DamageSource source)
SoundEvent getDeathSound()
SoundEvent getStepSound()
EntityType<? extends Zombie> convertsToWhenDrowning()
void playStepSound(final BlockPos pos, final BlockState blockState)
EntityType<? extends Zombie> getType()
boolean canSpawnInLiquids()
void populateDefaultEquipmentSlots(final RandomSource random, final DifficultyInstance difficulty)
void addAdditionalSaveData(final ValueOutput output)
void readAdditionalSaveData(final ValueInput input)
boolean killedEntity(final ServerLevel level, final LivingEntity entity, final DamageSource source)
EntityDimensions getDefaultDimensions(final Pose pose)
boolean canHoldItem(final ItemStack itemStack)
boolean wantsToPickUp(final ServerLevel level, final ItemStack itemStack)
void onOffspringSpawnedFromEgg(final Player spawner, final Mob offspring)
void setInWaterTime(final int inWaterTime)
void setConversionTime(final int conversionTime)
boolean getSpawnAsBabyOdds(final RandomSource random)
void handleAttributes(final float difficultyModifier, final EntitySpawnReason spawnReason)
void randomizeReinforcementsChance()
void playDestroyProgressSound(final LevelAccessor level, final BlockPos pos)
void playBreakSound(final Level level, final BlockPos pos)
double acceptedDistance()

Fields & Constants (22)

SPEED_MODIFIER_BABY_ID
SPEED_MODIFIER_BABY
REINFORCEMENT_CALLER_CHARGE_ID
ZOMBIE_REINFORCEMENT_CALLEE_CHARGE
LEADER_ZOMBIE_BONUS_ID
ZOMBIE_RANDOM_SPAWN_BONUS_ID
DATA_BABY_ID
DATA_SPECIAL_TYPE_ID
DATA_DROWNED_CONVERSION_ID
ZOMBIE_LEADER_CHANCE
REINFORCEMENT_ATTEMPTS
REINFORCEMENT_RANGE_MAX
REINFORCEMENT_RANGE_MIN
BABY_DIMENSIONS
BREAK_DOOR_CHANCE
DOOR_BREAKING_PREDICATE
DEFAULT_BABY
DEFAULT_CAN_BREAK_DOORS
breakDoorGoal
canBreakDoors
drowningTracker
spawnReason

String literals (9)

"baby"
"reinforcement_caller_charge"
"reinforcement_callee_charge"
"leader_zombie_bonus"
"zombie_random_spawn_bonus"
"InWaterTime"
"DrownedConversionTime"
"IsBaby"
"CanBreakDoors"

Code Graph: Dependencies (65)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

Zombie.java559 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.monster.zombie;
2
3
import com.google.common.annotations.VisibleForTesting;
4
import java.util.List;
5
import java.util.function.Predicate;
6
import net.minecraft.core.BlockPos;
7
import net.minecraft.network.syncher.EntityDataAccessor;
8
import net.minecraft.network.syncher.EntityDataSerializers;
9
import net.minecraft.network.syncher.SynchedEntityData;
10
import net.minecraft.resources.Identifier;
11
import net.minecraft.server.level.ServerLevel;
12
import net.minecraft.sounds.SoundEvent;
13
import net.minecraft.sounds.SoundEvents;
14
import net.minecraft.sounds.SoundSource;
15
import net.minecraft.tags.FluidTags;
16
import net.minecraft.tags.ItemTags;
17
import net.minecraft.util.Mth;
18
import net.minecraft.util.RandomSource;
19
import net.minecraft.util.SpecialDates;
20
import net.minecraft.world.Difficulty;
21
import net.minecraft.world.DifficultyInstance;
22
import net.minecraft.world.damagesource.DamageSource;
23
import net.minecraft.world.entity.ConversionParams;
24
import net.minecraft.world.entity.ConversionTracker;
25
import net.minecraft.world.entity.Entity;
26
import net.minecraft.world.entity.EntityAttachment;
27
import net.minecraft.world.entity.EntityAttachments;
28
import net.minecraft.world.entity.EntityDimensions;
29
import net.minecraft.world.entity.EntitySelector;
30
import net.minecraft.world.entity.EntitySpawnReason;
31
import net.minecraft.world.entity.EntityType;
32
import net.minecraft.world.entity.EntityTypes;
33
import net.minecraft.world.entity.EquipmentSlot;
34
import net.minecraft.world.entity.LivingEntity;
35
import net.minecraft.world.entity.Mob;
36
import net.minecraft.world.entity.PathfinderMob;
37
import net.minecraft.world.entity.Pose;
38
import net.minecraft.world.entity.SpawnGroupData;
39
import net.minecraft.world.entity.SpawnPlacements;
40
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
41
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
42
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
43
import net.minecraft.world.entity.ai.attributes.Attributes;
44
import net.minecraft.world.entity.ai.goal.BreakDoorGoal;
45
import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
46
import net.minecraft.world.entity.ai.goal.MoveThroughVillageGoal;
47
import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
48
import net.minecraft.world.entity.ai.goal.RemoveBlockGoal;
49
import net.minecraft.world.entity.ai.goal.SpearUseGoal;
50
import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal;
51
import net.minecraft.world.entity.ai.goal.ZombieAttackGoal;
52
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
53
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
54
import net.minecraft.world.entity.animal.chicken.Chicken;
55
import net.minecraft.world.entity.animal.golem.IronGolem;
56
import net.minecraft.world.entity.animal.turtle.Turtle;
57
import net.minecraft.world.entity.monster.Monster;
58
import net.minecraft.world.entity.npc.villager.AbstractVillager;
59
import net.minecraft.world.entity.npc.villager.Villager;
60
import net.minecraft.world.entity.player.Player;
61
import net.minecraft.world.item.ItemStack;
62
import net.minecraft.world.item.Items;
63
import net.minecraft.world.level.Level;
64
import net.minecraft.world.level.LevelAccessor;
65
import net.minecraft.world.level.ServerLevelAccessor;
66
import net.minecraft.world.level.block.Blocks;
67
import net.minecraft.world.level.block.LevelEvent;
68
import net.minecraft.world.level.block.state.BlockState;
69
import net.minecraft.world.level.storage.ValueInput;
70
import net.minecraft.world.level.storage.ValueOutput;
71
import org.jspecify.annotations.Nullable;
72
73
public class Zombie extends Monster {
74
	private static final Identifier SPEED_MODIFIER_BABY_ID = Identifier.withDefaultNamespace("baby");
75
	private static final AttributeModifier SPEED_MODIFIER_BABY = new AttributeModifier(
76
		SPEED_MODIFIER_BABY_ID, 0.5, AttributeModifier.Operation.ADD_MULTIPLIED_BASE
77
	);
78
	private static final Identifier REINFORCEMENT_CALLER_CHARGE_ID = Identifier.withDefaultNamespace("reinforcement_caller_charge");
79
	private static final AttributeModifier ZOMBIE_REINFORCEMENT_CALLEE_CHARGE = new AttributeModifier(
80
		Identifier.withDefaultNamespace("reinforcement_callee_charge"), -0.05F, AttributeModifier.Operation.ADD_VALUE
81
	);
82
	private static final Identifier LEADER_ZOMBIE_BONUS_ID = Identifier.withDefaultNamespace("leader_zombie_bonus");
83
	private static final Identifier ZOMBIE_RANDOM_SPAWN_BONUS_ID = Identifier.withDefaultNamespace("zombie_random_spawn_bonus");
84
	private static final EntityDataAccessor<Boolean> DATA_BABY_ID = SynchedEntityData.defineId(Zombie.class, EntityDataSerializers.BOOLEAN);
85
	private static final EntityDataAccessor<Integer> DATA_SPECIAL_TYPE_ID = SynchedEntityData.defineId(Zombie.class, EntityDataSerializers.INT);
86
	private static final EntityDataAccessor<Boolean> DATA_DROWNED_CONVERSION_ID = SynchedEntityData.defineId(Zombie.class, EntityDataSerializers.BOOLEAN);
87
	public static final float ZOMBIE_LEADER_CHANCE = 0.05F;
88
	public static final int REINFORCEMENT_ATTEMPTS = 50;
89
	public static final int REINFORCEMENT_RANGE_MAX = 40;
90
	public static final int REINFORCEMENT_RANGE_MIN = 7;
91
	private static final EntityDimensions BABY_DIMENSIONS = EntityDimensions.scalable(0.49F, 0.98F)
92
		.withEyeHeight(0.775F)
93
		.withAttachments(EntityAttachments.builder().attach(EntityAttachment.VEHICLE, 0.0F, 0.1875F, 0.0F));
94
	private static final float BREAK_DOOR_CHANCE = 0.1F;
95
	private static final Predicate<Difficulty> DOOR_BREAKING_PREDICATE = d -> d == Difficulty.HARD;
96
	private static final boolean DEFAULT_BABY = false;
97
	private static final boolean DEFAULT_CAN_BREAK_DOORS = false;
98
	private final BreakDoorGoal breakDoorGoal = new BreakDoorGoal(this, DOOR_BREAKING_PREDICATE);
99
	private boolean canBreakDoors = false;
100
	private final ConversionTracker<Zombie> drowningTracker = new ConversionTracker<>(
101
		this,
102
		DATA_DROWNED_CONVERSION_ID,
103
		this::convertsToWhenDrowning,
104
		this::getConversionSound,
105
		() -> this.isEyeInFluid(FluidTags.WATER),
106
		"InWaterTime",
107
		600,
108
		"DrownedConversionTime",
109
		300,
110
		(converted, serverLevel) -> converted.handleAttributes(
111
			serverLevel.getCurrentDifficultyAt(converted.blockPosition()).getSpecialMultiplier(), EntitySpawnReason.CONVERSION
112
		)
113
	);
114
115
	public Zombie(final EntityType<? extends Zombie> type, final Level level) {
116
		super(type, level);
117
	}
118
119
	public Zombie(final Level level) {
120
		this(EntityTypes.ZOMBIE, level);
121
	}
122
123
	@Override
124
	protected void registerGoals() {
125
		this.goalSelector.addGoal(4, new Zombie.ZombieAttackTurtleEggGoal(this, 1.0, 3));
126
		this.goalSelector.addGoal(8, new LookAtPlayerGoal(this, Player.class, 8.0F));
127
		this.goalSelector.addGoal(8, new RandomLookAroundGoal(this));
128
		this.addBehaviourGoals();
129
	}
130
131
	protected void addBehaviourGoals() {
132
		this.goalSelector.addGoal(2, new SpearUseGoal<>(this, 1.0, 1.0, 10.0F, 2.0F));
133
		this.goalSelector.addGoal(3, new ZombieAttackGoal(this, 1.0, false));
134
		this.goalSelector.addGoal(6, new MoveThroughVillageGoal(this, 1.0, true, 4, this::canBreakDoors));
135
		this.goalSelector.addGoal(7, new WaterAvoidingRandomStrollGoal(this, 1.0));
136
		this.targetSelector.addGoal(1, new HurtByTargetGoal(this).setAlertOthers(ZombifiedPiglin.class));
137
		this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, Player.class, true));
138
		this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, AbstractVillager.class, false));
139
		this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, IronGolem.class, true));
140
		this.targetSelector.addGoal(5, new NearestAttackableTargetGoal<>(this, Turtle.class, 10, true, false, Turtle.BABY_ON_LAND_SELECTOR));
141
	}
142
143
	public static AttributeSupplier.Builder createAttributes() {
144
		return Monster.createMonsterAttributes()
145
			.add(Attributes.FOLLOW_RANGE, 35.0)
146
			.add(Attributes.MOVEMENT_SPEED, 0.23F)
147
			.add(Attributes.ATTACK_DAMAGE, 3.0)
148
			.add(Attributes.ARMOR, 2.0)
149
			.add(Attributes.SPAWN_REINFORCEMENTS_CHANCE);
150
	}
151
152
	@Override
153
	protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
154
		super.defineSynchedData(entityData);
155
		entityData.define(DATA_BABY_ID, false);
156
		entityData.define(DATA_SPECIAL_TYPE_ID, 0);
157
		entityData.define(DATA_DROWNED_CONVERSION_ID, false);
158
	}
159
160
	public boolean isUnderWaterConverting() {
161
		return this.drowningTracker.isConverting();
162
	}
163
164
	public boolean canBreakDoors() {
165
		return this.canBreakDoors;
166
	}
167
168
	public void setCanBreakDoors(final boolean canBreakDoors) {
169
		if (this.navigation.canNavigateGround()) {
170
			if (this.canBreakDoors != canBreakDoors) {
171
				this.canBreakDoors = canBreakDoors;
172
				this.navigation.setCanOpenDoors(canBreakDoors);
173
				if (canBreakDoors) {
174
					this.goalSelector.addGoal(1, this.breakDoorGoal);
175
				} else {
176
					this.goalSelector.removeGoal(this.breakDoorGoal);
177
				}
178
			}
179
		} else if (this.canBreakDoors) {
180
			this.goalSelector.removeGoal(this.breakDoorGoal);
181
			this.canBreakDoors = false;
182
		}
183
	}
184
185
	@Override
186
	public boolean isBaby() {
187
		return this.getEntityData().get(DATA_BABY_ID);
188
	}
189
190
	@Override
191
	protected int getBaseExperienceReward(final ServerLevel level) {
192
		if (this.isBaby()) {
193
			this.xpReward = (int)(this.xpReward * 2.5);
194
		}
195
196
		return super.getBaseExperienceReward(level);
197
	}
198
199
	@Override
200
	public void setBaby(final boolean baby) {
201
		this.getEntityData().set(DATA_BABY_ID, baby);
202
		if (this.level() != null && !this.level().isClientSide()) {
203
			AttributeInstance speed = this.getAttribute(Attributes.MOVEMENT_SPEED);
204
			speed.removeModifier(SPEED_MODIFIER_BABY_ID);
205
			if (baby) {
206
				speed.addTransientModifier(SPEED_MODIFIER_BABY);
207
			}
208
		}
209
	}
210
211
	@Override
212
	public void onSyncedDataUpdated(final EntityDataAccessor<?> accessor) {
213
		if (DATA_BABY_ID.equals(accessor)) {
214
			this.refreshDimensions();
215
		}
216
217
		super.onSyncedDataUpdated(accessor);
218
	}
219
220
	protected boolean convertsInWater() {
221
		return true;
222
	}
223
224
	@Override
225
	public void tick() {
226
		super.tick();
227
		if (this.convertsInWater()) {
228
			this.drowningTracker.tick();
229
		}
230
	}
231
232
	@VisibleForTesting
233
	public boolean convertVillagerToZombieVillager(final ServerLevel level, final Villager villager) {
234
		ZombieVillager zombieVillager = villager.convertTo(EntityTypes.ZOMBIE_VILLAGER, ConversionParams.single(villager, true, true), zombie -> {
235
			zombie.setVillagerDataFinalized(villager.getVillagerDataFinalized());
236
			zombie.finalizeSpawn(level, level.getCurrentDifficultyAt(zombie.blockPosition()), EntitySpawnReason.CONVERSION, new Zombie.ZombieGroupData(false, true));
237
			zombie.setVillagerData(villager.getVillagerData());
238
			zombie.setGossips(villager.getGossips().copy());
239
			zombie.setTradeOffers(villager.getOffers().copy());
240
			zombie.setVillagerXp(villager.getVillagerXp());
241
			if (!this.isSilent()) {
242
				level.levelEvent(null, 1026, this.blockPosition(), 0);
243
			}
244
		});
245
		return zombieVillager != null;
246
	}
247
248
	protected boolean isSunSensitive() {
249
		return true;
250
	}
251
252
	@Override
253
	public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
254
		if (!super.hurtServer(level, source, damage)) {
255
			return false;
256
		}
257
258
		LivingEntity target = this.getTarget();
259
		if (target == null && source.getEntity() instanceof LivingEntity) {
260
			target = (LivingEntity)source.getEntity();
261
		}
262
263
		if (target != null
264
			&& level.getDifficulty() == Difficulty.HARD
265
			&& this.random.nextFloat() < this.getAttributeValue(Attributes.SPAWN_REINFORCEMENTS_CHANCE)
266
			&& level.isSpawningMonsters()) {
267
			int x = Mth.floor(this.getX());
268
			int y = Mth.floor(this.getY());
269
			int z = Mth.floor(this.getZ());
270
			EntityType<? extends Zombie> type = this.getType();
271
			Zombie reinforcement = type.create(level, EntitySpawnReason.REINFORCEMENT);
272
			if (reinforcement == null) {
273
				return true;
274
			}
275
276
			for (int i = 0; i < 50; i++) {
277
				int xt = x + Mth.nextInt(this.random, 7, 40) * Mth.nextInt(this.random, -1, 1);
278
				int yt = y + Mth.nextInt(this.random, 7, 40) * Mth.nextInt(this.random, -1, 1);
279
				int zt = z + Mth.nextInt(this.random, 7, 40) * Mth.nextInt(this.random, -1, 1);
280
				BlockPos spawnPos = new BlockPos(xt, yt, zt);
281
				if (SpawnPlacements.isSpawnPositionOk(type, level, spawnPos)
282
					&& SpawnPlacements.checkSpawnRules(type, level, EntitySpawnReason.REINFORCEMENT, spawnPos, level.getRandom())) {
283
					reinforcement.setPos(xt, yt, zt);
284
					if (!level.hasNearbyAlivePlayer(xt, yt, zt, 7.0)
285
						&& level.isUnobstructed(reinforcement)
286
						&& level.noCollision(reinforcement)
287
						&& (reinforcement.canSpawnInLiquids() || !level.containsAnyLiquid(reinforcement.getBoundingBox()))) {
288
						reinforcement.setTarget(target);
289
						reinforcement.finalizeSpawn(level, level.getCurrentDifficultyAt(reinforcement.blockPosition()), EntitySpawnReason.REINFORCEMENT, null);
290
						level.addFreshEntityWithPassengers(reinforcement);
291
						AttributeInstance attribute = this.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE);
292
						AttributeModifier modifier = attribute.getModifier(REINFORCEMENT_CALLER_CHARGE_ID);
293
						double existingAmount = modifier != null ? modifier.amount() : 0.0;
294
						attribute.removeModifier(REINFORCEMENT_CALLER_CHARGE_ID);
295
						attribute.addPermanentModifier(new AttributeModifier(REINFORCEMENT_CALLER_CHARGE_ID, existingAmount - 0.05, AttributeModifier.Operation.ADD_VALUE));
296
						reinforcement.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE).addPermanentModifier(ZOMBIE_REINFORCEMENT_CALLEE_CHARGE);
297
						break;
298
					}
299
				}
300
			}
301
		}
302
303
		return true;
304
	}
305
306
	@Override
307
	public boolean doHurtTarget(final ServerLevel level, final Entity target) {
308
		boolean result = super.doHurtTarget(level, target);
309
		if (result) {
310
			float difficulty = level.getCurrentDifficultyAt(this.blockPosition()).getEffectiveDifficulty();
311
			if (this.getMainHandItem().isEmpty() && this.isOnFire() && this.random.nextFloat() < difficulty * 0.3F) {
312
				target.igniteForSeconds(2 * (int)difficulty);
313
			}
314
		}
315
316
		return result;
317
	}
318
319
	@Override
320
	protected SoundEvent getAmbientSound() {
321
		return SoundEvents.ZOMBIE_AMBIENT;
322
	}
323
324
	@Override
325
	protected SoundEvent getHurtSound(final DamageSource source) {
326
		return SoundEvents.ZOMBIE_HURT;
327
	}
328
329
	@Override
330
	protected SoundEvent getDeathSound() {
331
		return SoundEvents.ZOMBIE_DEATH;
332
	}
333
334
	protected SoundEvent getStepSound() {
335
		return SoundEvents.ZOMBIE_STEP;
336
	}
337
338
	protected @LevelEvent.Value int getConversionSound() {
339
		return 1040;
340
	}
341
342
	protected EntityType<? extends Zombie> convertsToWhenDrowning() {
343
		return EntityTypes.DROWNED;
344
	}
345
346
	@Override
347
	protected void playStepSound(final BlockPos pos, final BlockState blockState) {
348
		this.playSound(this.getStepSound(), 0.15F, 1.0F);
349
	}
350
351
	@Override
352
	public EntityType<? extends Zombie> getType() {
353
		return (EntityType<? extends Zombie>)super.getType();
354
	}
355
356
	protected boolean canSpawnInLiquids() {
357
		return false;
358
	}
359
360
	@Override
361
	protected void populateDefaultEquipmentSlots(final RandomSource random, final DifficultyInstance difficulty) {
362
		super.populateDefaultEquipmentSlots(random, difficulty);
363
		if (random.nextFloat() < (this.level().getDifficulty() == Difficulty.HARD ? 0.05F : 0.01F)) {
364
			int rand = random.nextInt(6);
365
			if (rand == 0) {
366
				this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SWORD));
367
			} else if (rand == 1) {
368
				this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SPEAR));
369
			} else {
370
				this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SHOVEL));
371
			}
372
		}
373
	}
374
375
	@Override
376
	protected void addAdditionalSaveData(final ValueOutput output) {
377
		super.addAdditionalSaveData(output);
378
		output.putBoolean("IsBaby", this.isBaby());
379
		output.putBoolean("CanBreakDoors", this.canBreakDoors());
380
		this.drowningTracker.addAdditionalSaveData(output);
381
	}
382
383
	@Override
384
	protected void readAdditionalSaveData(final ValueInput input) {
385
		super.readAdditionalSaveData(input);
386
		this.setBaby(input.getBooleanOr("IsBaby", false));
387
		this.setCanBreakDoors(input.getBooleanOr("CanBreakDoors", false));
388
		this.drowningTracker.readAdditionalSaveData(input);
389
	}
390
391
	@Override
392
	public boolean killedEntity(final ServerLevel level, final LivingEntity entity, final DamageSource source) {
393
		boolean perished = super.killedEntity(level, entity, source);
394
		if ((level.getDifficulty() == Difficulty.NORMAL || level.getDifficulty() == Difficulty.HARD) && entity instanceof Villager villager) {
395
			if (level.getDifficulty() != Difficulty.HARD && this.random.nextBoolean()) {
396
				return perished;
397
			}
398
399
			if (this.convertVillagerToZombieVillager(level, villager)) {
400
				perished = false;
401
			}
402
		}
403
404
		return perished;
405
	}
406
407
	@Override
408
	public EntityDimensions getDefaultDimensions(final Pose pose) {
409
		return this.isBaby() ? BABY_DIMENSIONS : super.getDefaultDimensions(pose);
410
	}
411
412
	@Override
413
	public boolean canHoldItem(final ItemStack itemStack) {
414
		return itemStack.is(ItemTags.EGGS) && this.isBaby() && this.isPassenger() ? false : super.canHoldItem(itemStack);
415
	}
416
417
	@Override
418
	public boolean wantsToPickUp(final ServerLevel level, final ItemStack itemStack) {
419
		return itemStack.is(Items.GLOW_INK_SAC) ? false : super.wantsToPickUp(level, itemStack);
420
	}
421
422
	@Override
423
	public @Nullable SpawnGroupData finalizeSpawn(
424
		final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, @Nullable SpawnGroupData groupData
425
	) {
426
		RandomSource random = level.getRandom();
427
		groupData = super.finalizeSpawn(level, difficulty, spawnReason, groupData);
428
		float difficultyModifier = difficulty.getSpecialMultiplier();
429
		if (spawnReason != EntitySpawnReason.CONVERSION) {
430
			this.setCanPickUpLoot(random.nextFloat() < 0.55F * difficultyModifier);
431
		}
432
433
		if (groupData == null) {
434
			groupData = new Zombie.ZombieGroupData(getSpawnAsBabyOdds(random), true);
435
		}
436
437
		if (groupData instanceof Zombie.ZombieGroupData zombieData) {
438
			if (zombieData.isBaby) {
439
				this.setBaby(true);
440
				if (zombieData.canSpawnJockey) {
441
					if (random.nextFloat() < 0.05) {
442
						List<Chicken> chickens = level.getEntitiesOfClass(Chicken.class, this.getBoundingBox().inflate(5.0, 3.0, 5.0), EntitySelector.ENTITY_NOT_BEING_RIDDEN);
443
						if (!chickens.isEmpty()) {
444
							Chicken chicken = chickens.get(0);
445
							chicken.setChickenJockey(true);
446
							this.startRiding(chicken, false, false);
447
						}
448
					} else if (random.nextFloat() < 0.05) {
449
						Chicken chicken = EntityTypes.CHICKEN.create(this.level(), EntitySpawnReason.JOCKEY);
450
						if (chicken != null) {
451
							chicken.snapTo(this.getX(), this.getY(), this.getZ(), this.getYRot(), 0.0F);
452
							chicken.finalizeSpawn(level, difficulty, EntitySpawnReason.JOCKEY, null);
453
							chicken.setChickenJockey(true);
454
							this.startRiding(chicken, false, false);
455
							level.addFreshEntity(chicken);
456
						}
457
					}
458
				}
459
			}
460
461
			this.setCanBreakDoors(random.nextFloat() < difficultyModifier * 0.1F);
462
			if (spawnReason != EntitySpawnReason.CONVERSION) {
463
				this.populateDefaultEquipmentSlots(random, difficulty);
464
				this.populateDefaultEquipmentEnchantments(level, random, difficulty);
465
			}
466
		}
467
468
		if (this.getItemBySlot(EquipmentSlot.HEAD).isEmpty() && SpecialDates.isHalloween() && random.nextFloat() < 0.25F) {
469
			this.setItemSlot(EquipmentSlot.HEAD, new ItemStack(random.nextFloat() < 0.1F ? Blocks.JACK_O_LANTERN : Blocks.CARVED_PUMPKIN));
470
			this.setDropChance(EquipmentSlot.HEAD, 0.0F);
471
		}
472
473
		this.handleAttributes(difficultyModifier, spawnReason);
474
		return groupData;
475
	}
476
477
	@Override
478
	protected void onOffspringSpawnedFromEgg(final Player spawner, final Mob offspring) {
479
		if (this.level() instanceof ServerLevel serverLevel) {
480
			float difficultyModifier = serverLevel.getCurrentDifficultyAt(offspring.blockPosition()).getSpecialMultiplier();
481
			offspring.setCanPickUpLoot(this.random.nextFloat() < 0.55F * difficultyModifier);
482
		}
483
	}
484
485
	@VisibleForTesting
486
	public void setInWaterTime(final int inWaterTime) {
487
		this.drowningTracker.setAfflictionTime(inWaterTime);
488
	}
489
490
	@VisibleForTesting
491
	public void setConversionTime(final int conversionTime) {
492
		this.drowningTracker.setConversionTime(conversionTime);
493
	}
494
495
	public static boolean getSpawnAsBabyOdds(final RandomSource random) {
496
		return random.nextFloat() < 0.05F;
497
	}
498
499
	protected void handleAttributes(final float difficultyModifier, final EntitySpawnReason spawnReason) {
500
		this.randomizeReinforcementsChance();
501
		this.getAttribute(Attributes.KNOCKBACK_RESISTANCE)
502
			.addOrReplacePermanentModifier(new AttributeModifier(RANDOM_SPAWN_BONUS_ID, this.random.nextDouble() * 0.05F, AttributeModifier.Operation.ADD_VALUE));
503
		double followRangeModifier = this.random.nextDouble() * 1.5 * difficultyModifier;
504
		if (followRangeModifier > 1.0) {
505
			this.getAttribute(Attributes.FOLLOW_RANGE)
506
				.addOrReplacePermanentModifier(new AttributeModifier(ZOMBIE_RANDOM_SPAWN_BONUS_ID, followRangeModifier, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL));
507
		}
508
509
		if (this.random.nextFloat() < difficultyModifier * 0.05F) {
510
			this.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE)
511
				.addOrReplacePermanentModifier(new AttributeModifier(LEADER_ZOMBIE_BONUS_ID, this.random.nextDouble() * 0.25 + 0.5, AttributeModifier.Operation.ADD_VALUE));
512
			this.getAttribute(Attributes.MAX_HEALTH)
513
				.addOrReplacePermanentModifier(
514
					new AttributeModifier(LEADER_ZOMBIE_BONUS_ID, this.random.nextDouble() * 3.0 + 1.0, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL)
515
				);
516
			if (spawnReason != EntitySpawnReason.CONVERSION && spawnReason != EntitySpawnReason.LOAD && spawnReason != EntitySpawnReason.DIMENSION_TRAVEL) {
517
				this.setHealth(this.getMaxHealth());
518
			}
519
520
			this.setCanBreakDoors(true);
521
		}
522
	}
523
524
	protected void randomizeReinforcementsChance() {
525
		this.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE).setBaseValue(this.random.nextDouble() * 0.1F);
526
	}
527
528
	private class ZombieAttackTurtleEggGoal extends RemoveBlockGoal {
529
		public ZombieAttackTurtleEggGoal(final PathfinderMob mob, final double speedModifier, final int verticalSearchRange) {
530
			super(Blocks.TURTLE_EGG, mob, speedModifier, verticalSearchRange);
531
		}
532
533
		@Override
534
		public void playDestroyProgressSound(final LevelAccessor level, final BlockPos pos) {
535
			level.playSound(null, pos, SoundEvents.ZOMBIE_DESTROY_EGG, SoundSource.HOSTILE, 0.5F, 0.9F + Zombie.this.random.nextFloat() * 0.2F);
536
		}
537
538
		@Override
539
		public void playBreakSound(final Level level, final BlockPos pos) {
540
			level.playSound(null, pos, SoundEvents.TURTLE_EGG_BREAK, SoundSource.BLOCKS, 0.7F, 0.9F + level.getRandom().nextFloat() * 0.2F);
541
		}
542
543
		@Override
544
		public double acceptedDistance() {
545
			return 1.14;
546
		}
547
	}
548
549
	public static class ZombieGroupData implements SpawnGroupData {
550
		public final boolean isBaby;
551
		public final boolean canSpawnJockey;
552
553
		public ZombieGroupData(final boolean baby, final boolean canSpawnJockey) {
554
			this.isBaby = baby;
555
			this.canSpawnJockey = canSpawnJockey;
556
		}
557
	}
558
}
559

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