Axolotl .java

net.minecraft.world.entity.animal.axolotl.Axolotl (class, 678 lines): members: PLAYER_REGEN_DETECTION_RANGE, AXOLOTL_TOTAL_AIR_SUPPLY, RARE_VARIANT_CHANCE.

net.minecraft.world.entity.animal.axolotlclass678 linescommonextends Animal22.7 KB

Implements

API Surface (56)

float getWalkTargetValue(final BlockPos pos, final LevelReader level)
void defineSynchedData(final SynchedEntityData.Builder entityData)
void addAdditionalSaveData(final ValueOutput output)
void readAdditionalSaveData(final ValueInput input)
void playAmbientSound()
SpawnGroupData finalizeSpawn(final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, @Nullable SpawnGroupData groupData)
void baseTick()
void handleAirSupply(final ServerLevel level, final int preTickAirSupply)
void rehydrate()
int getMaxAirSupply()
Axolotl.Variant getVariant()
void applyImplicitComponents(final DataComponentGetter components)
<T> boolean applyImplicitComponent(final DataComponentType<T> type, final T value)
boolean checkSpawnObstruction(final LevelReader level)
boolean isPushedByFluid()
void setPlayingDead(final boolean playingDead)
boolean isPlayingDead()
boolean fromBucket()
void setFromBucket(final boolean fromBucket)
boolean isFood(final ItemStack itemStack)
boolean canBeLeashed()
void customServerAiStep(final ServerLevel level)
AttributeSupplier.Builder createAttributes()
PathNavigation createNavigation(final Level level)
void playAttackSound()
boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage)
int getMaxHeadXRot()
int getMaxHeadYRot()
InteractionResult mobInteract(final Player player, final InteractionHand hand)
void saveToBucketTag(final ItemStack bucket)
void loadFromBucketTag(final CompoundTag tag)
ItemStack getBucketItemStack()
SoundEvent getPickupSound()
boolean canBeSeenAsEnemy()
void onStopAttacking(final ServerLevel level, final Axolotl body, final LivingEntity target)
void applySupportingEffects(final Player player)
boolean requiresCustomPersistence()
SoundEvent getHurtSound(final DamageSource source)
SoundEvent getSwimSplashSound()
SoundEvent getSwimSound()
Brain<Axolotl> makeBrain(final Brain.Packed packedBrain)
Brain<Axolotl> getBrain()
void travelInWater(final Vec3 input, final double baseGravity, final boolean isFalling, final double oldY)
void usePlayerItem(final Player player, final InteractionHand hand, final ItemStack itemStack)
boolean removeWhenFarAway(final double distSqr)
boolean checkAxolotlSpawnRules(final EntityType<? extends LivingEntity> type, final ServerLevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random)
EntityDimensions getDefaultDimensions(final Pose pose)
Axolotl.Variant getVariant(final RandomSource random)
void tick()
void tick()
int getId()
String getName()
String getSerializedName()
Axolotl.Variant byId(final int id)
Axolotl.Variant getCommonSpawnVariant(final RandomSource random)
Axolotl.Variant getRareSpawnVariant(final RandomSource random)

Fields & Constants (31)

TOTAL_PLAYDEAD_TIME
POSE_ANIMATION_TICKS
BRAIN_PROVIDER
DATA_VARIANT
DATA_PLAYING_DEAD
FROM_BUCKET
PLAYER_REGEN_DETECTION_RANGE
RARE_VARIANT_CHANCE
AXOLOTL_TOTAL_AIR_SUPPLY
VARIANT_TAG
REHYDRATE_AIR_SUPPLY
REGEN_BUFF_MAX_DURATION
DEFAULT_FROM_BUCKET
BABY_DIMENSIONS
REGEN_BUFF_BASE_DURATION
playingDeadAnimator
inWaterAnimator
onGroundAnimator
movingAnimator
swimAnimationState
walkAnimationState
walkUnderWaterAnimationState
idleUnderWaterAnimationState
idleUnderWaterOnGroundAnimationState
idleOnGroundAnimationState
playDeadAnimationState
ALL_ANIMATIONS
spawnReason
type
level
pos

String literals (11)

"Variant"
"FromBucket"
"axolotlBrain"
"axolotlActivityUpdate"
"AgeLocked"
"HuntingCooldown"
"lucy"
"wild"
"gold"
"cyan"
"blue"

Code Graph: Dependencies (67)

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

Full Source

Axolotl.java678 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.animal.axolotl;
2
3
import com.google.common.collect.ImmutableList;
4
import com.mojang.serialization.Codec;
5
import io.netty.buffer.ByteBuf;
6
import java.util.Arrays;
7
import java.util.List;
8
import java.util.Optional;
9
import java.util.function.IntFunction;
10
import net.minecraft.core.BlockPos;
11
import net.minecraft.core.component.DataComponentGetter;
12
import net.minecraft.core.component.DataComponentType;
13
import net.minecraft.core.component.DataComponents;
14
import net.minecraft.nbt.CompoundTag;
15
import net.minecraft.network.codec.ByteBufCodecs;
16
import net.minecraft.network.codec.StreamCodec;
17
import net.minecraft.network.syncher.EntityDataAccessor;
18
import net.minecraft.network.syncher.EntityDataSerializers;
19
import net.minecraft.network.syncher.SynchedEntityData;
20
import net.minecraft.server.level.ServerLevel;
21
import net.minecraft.sounds.SoundEvent;
22
import net.minecraft.sounds.SoundEvents;
23
import net.minecraft.tags.BlockTags;
24
import net.minecraft.tags.ItemTags;
25
import net.minecraft.util.BinaryAnimator;
26
import net.minecraft.util.ByIdMap;
27
import net.minecraft.util.EasingType;
28
import net.minecraft.util.RandomSource;
29
import net.minecraft.util.StringRepresentable;
30
import net.minecraft.util.Util;
31
import net.minecraft.util.profiling.Profiler;
32
import net.minecraft.util.profiling.ProfilerFiller;
33
import net.minecraft.world.DifficultyInstance;
34
import net.minecraft.world.InteractionHand;
35
import net.minecraft.world.InteractionResult;
36
import net.minecraft.world.damagesource.DamageSource;
37
import net.minecraft.world.effect.MobEffectInstance;
38
import net.minecraft.world.effect.MobEffects;
39
import net.minecraft.world.entity.AgeableMob;
40
import net.minecraft.world.entity.AnimationState;
41
import net.minecraft.world.entity.Bucketable;
42
import net.minecraft.world.entity.EntityAttachment;
43
import net.minecraft.world.entity.EntityAttachments;
44
import net.minecraft.world.entity.EntityDimensions;
45
import net.minecraft.world.entity.EntitySpawnReason;
46
import net.minecraft.world.entity.EntityType;
47
import net.minecraft.world.entity.EntityTypes;
48
import net.minecraft.world.entity.LivingEntity;
49
import net.minecraft.world.entity.MoverType;
50
import net.minecraft.world.entity.Pose;
51
import net.minecraft.world.entity.SpawnGroupData;
52
import net.minecraft.world.entity.ai.Brain;
53
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
54
import net.minecraft.world.entity.ai.attributes.Attributes;
55
import net.minecraft.world.entity.ai.control.SmoothSwimmingLookControl;
56
import net.minecraft.world.entity.ai.control.SmoothSwimmingMoveControl;
57
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
58
import net.minecraft.world.entity.ai.navigation.AmphibiousPathNavigation;
59
import net.minecraft.world.entity.ai.navigation.PathNavigation;
60
import net.minecraft.world.entity.ai.sensing.SensorType;
61
import net.minecraft.world.entity.animal.Animal;
62
import net.minecraft.world.entity.player.Player;
63
import net.minecraft.world.item.ItemStack;
64
import net.minecraft.world.item.ItemUtils;
65
import net.minecraft.world.item.Items;
66
import net.minecraft.world.item.component.CustomData;
67
import net.minecraft.world.level.Level;
68
import net.minecraft.world.level.LevelReader;
69
import net.minecraft.world.level.ServerLevelAccessor;
70
import net.minecraft.world.level.pathfinder.PathType;
71
import net.minecraft.world.level.storage.ValueInput;
72
import net.minecraft.world.level.storage.ValueOutput;
73
import net.minecraft.world.phys.Vec3;
74
import org.jspecify.annotations.Nullable;
75
76
public class Axolotl extends Animal implements Bucketable {
77
	public static final int TOTAL_PLAYDEAD_TIME = 200;
78
	private static final int POSE_ANIMATION_TICKS = 10;
79
	private static final Brain.Provider<Axolotl> BRAIN_PROVIDER = Brain.provider(
80
		List.of(SensorType.NEAREST_LIVING_ENTITIES, SensorType.NEAREST_ADULT, SensorType.HURT_BY, SensorType.AXOLOTL_ATTACKABLES, SensorType.FOOD_TEMPTATIONS),
81
		var0 -> AxolotlAi.getActivities()
82
	);
83
	private static final EntityDataAccessor<Integer> DATA_VARIANT = SynchedEntityData.defineId(Axolotl.class, EntityDataSerializers.INT);
84
	private static final EntityDataAccessor<Boolean> DATA_PLAYING_DEAD = SynchedEntityData.defineId(Axolotl.class, EntityDataSerializers.BOOLEAN);
85
	private static final EntityDataAccessor<Boolean> FROM_BUCKET = SynchedEntityData.defineId(Axolotl.class, EntityDataSerializers.BOOLEAN);
86
	public static final double PLAYER_REGEN_DETECTION_RANGE = 20.0;
87
	public static final int RARE_VARIANT_CHANCE = 1200;
88
	private static final int AXOLOTL_TOTAL_AIR_SUPPLY = 6000;
89
	public static final String VARIANT_TAG = "Variant";
90
	private static final int REHYDRATE_AIR_SUPPLY = 1800;
91
	private static final int REGEN_BUFF_MAX_DURATION = 2400;
92
	private static final boolean DEFAULT_FROM_BUCKET = false;
93
	public final BinaryAnimator playingDeadAnimator = new BinaryAnimator(10, EasingType.IN_OUT_SINE);
94
	public final BinaryAnimator inWaterAnimator = new BinaryAnimator(10, EasingType.IN_OUT_SINE);
95
	public final BinaryAnimator onGroundAnimator = new BinaryAnimator(10, EasingType.IN_OUT_SINE);
96
	public final BinaryAnimator movingAnimator = new BinaryAnimator(10, EasingType.IN_OUT_SINE);
97
	public final AnimationState swimAnimationState = new AnimationState();
98
	public final AnimationState walkAnimationState = new AnimationState();
99
	public final AnimationState walkUnderWaterAnimationState = new AnimationState();
100
	public final AnimationState idleUnderWaterAnimationState = new AnimationState();
101
	public final AnimationState idleUnderWaterOnGroundAnimationState = new AnimationState();
102
	public final AnimationState idleOnGroundAnimationState = new AnimationState();
103
	public final AnimationState playDeadAnimationState = new AnimationState();
104
	private final ImmutableList<AnimationState> ALL_ANIMATIONS = ImmutableList.of(
105
		this.swimAnimationState,
106
		this.walkAnimationState,
107
		this.walkUnderWaterAnimationState,
108
		this.idleUnderWaterAnimationState,
109
		this.idleUnderWaterOnGroundAnimationState,
110
		this.idleOnGroundAnimationState,
111
		this.playDeadAnimationState
112
	);
113
	private static final EntityDimensions BABY_DIMENSIONS = EntityDimensions.scalable(0.375F, 0.21F)
114
		.withEyeHeight(0.09375F)
115
		.withAttachments(EntityAttachments.builder().attach(EntityAttachment.PASSENGER, 0.0F, 0.1875F, 0.0F));
116
	private static final int REGEN_BUFF_BASE_DURATION = 100;
117
118
	public Axolotl(final EntityType<? extends Axolotl> type, final Level level) {
119
		super(type, level);
120
		this.setPathfindingMalus(PathType.WATER, 0.0F);
121
		this.moveControl = new Axolotl.AxolotlMoveControl<>(this);
122
		this.lookControl = new Axolotl.AxolotlLookControl(this, 20);
123
	}
124
125
	@Override
126
	public float getWalkTargetValue(final BlockPos pos, final LevelReader level) {
127
		return 0.0F;
128
	}
129
130
	@Override
131
	protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
132
		super.defineSynchedData(entityData);
133
		entityData.define(DATA_VARIANT, 0);
134
		entityData.define(DATA_PLAYING_DEAD, false);
135
		entityData.define(FROM_BUCKET, false);
136
	}
137
138
	@Override
139
	protected void addAdditionalSaveData(final ValueOutput output) {
140
		super.addAdditionalSaveData(output);
141
		output.store("Variant", Axolotl.Variant.LEGACY_CODEC, this.getVariant());
142
		output.putBoolean("FromBucket", this.fromBucket());
143
	}
144
145
	@Override
146
	protected void readAdditionalSaveData(final ValueInput input) {
147
		super.readAdditionalSaveData(input);
148
		this.setVariant(input.read("Variant", Axolotl.Variant.LEGACY_CODEC).orElse(Axolotl.Variant.DEFAULT));
149
		this.setFromBucket(input.getBooleanOr("FromBucket", false));
150
	}
151
152
	@Override
153
	public void playAmbientSound() {
154
		if (!this.isPlayingDead()) {
155
			super.playAmbientSound();
156
		}
157
	}
158
159
	@Override
160
	public SpawnGroupData finalizeSpawn(
161
		final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, @Nullable SpawnGroupData groupData
162
	) {
163
		boolean isBaby = false;
164
		if (spawnReason == EntitySpawnReason.BUCKET) {
165
			return groupData;
166
		}
167
168
		RandomSource random = level.getRandom();
169
		if (groupData instanceof Axolotl.AxolotlGroupData) {
170
			if (((Axolotl.AxolotlGroupData)groupData).getGroupSize() >= 2) {
171
				isBaby = true;
172
			}
173
		} else {
174
			groupData = new Axolotl.AxolotlGroupData(Axolotl.Variant.getCommonSpawnVariant(random), Axolotl.Variant.getCommonSpawnVariant(random));
175
		}
176
177
		this.setVariant(((Axolotl.AxolotlGroupData)groupData).getVariant(random));
178
		if (isBaby) {
179
			this.setAge(-24000);
180
		}
181
182
		return super.finalizeSpawn(level, difficulty, spawnReason, groupData);
183
	}
184
185
	@Override
186
	public void baseTick() {
187
		int airSupply = this.getAirSupply();
188
		super.baseTick();
189
		if (!this.isNoAi() && this.level() instanceof ServerLevel serverLevel) {
190
			this.handleAirSupply(serverLevel, airSupply);
191
		}
192
193
		if (this.level().isClientSide()) {
194
			if (this.isBaby()) {
195
				this.tickBabyAnimations();
196
			} else {
197
				this.tickAdultAnimations();
198
			}
199
		}
200
	}
201
202
	private void tickBabyAnimations() {
203
		boolean isPlayingDead = this.isPlayingDead();
204
		boolean isInWater = this.isInWater();
205
		boolean onGround = this.onGround();
206
		boolean isMoving = this.walkAnimation.isMoving() || this.getXRot() != this.xRotO || this.getYRot() != this.yRotO;
207
		this.movingAnimator.tick(isMoving);
208
		if (isPlayingDead) {
209
			this.soloAnimation(this.playDeadAnimationState);
210
		} else {
211
			if (isMoving) {
212
				if (isInWater && !onGround) {
213
					this.soloAnimation(this.swimAnimationState);
214
				} else if (!isInWater && onGround) {
215
					this.soloAnimation(this.walkAnimationState);
216
				} else {
217
					this.soloAnimation(this.walkUnderWaterAnimationState);
218
				}
219
			} else if (isInWater && !onGround) {
220
				this.soloAnimation(this.idleUnderWaterAnimationState);
221
			} else if (isInWater && onGround) {
222
				this.soloAnimation(this.idleUnderWaterOnGroundAnimationState);
223
			} else {
224
				this.soloAnimation(this.idleOnGroundAnimationState);
225
			}
226
		}
227
	}
228
229
	private void soloAnimation(final AnimationState toStart) {
230
		for (AnimationState animation : this.ALL_ANIMATIONS) {
231
			if (animation == toStart) {
232
				animation.startIfStopped(this.tickCount);
233
			} else {
234
				animation.stop();
235
			}
236
		}
237
	}
238
239
	private void tickAdultAnimations() {
240
		Axolotl.AxolotlAnimationState animationState;
241
		if (this.isPlayingDead()) {
242
			animationState = Axolotl.AxolotlAnimationState.PLAYING_DEAD;
243
		} else if (this.isInWater()) {
244
			animationState = Axolotl.AxolotlAnimationState.IN_WATER;
245
		} else if (this.onGround()) {
246
			animationState = Axolotl.AxolotlAnimationState.ON_GROUND;
247
		} else {
248
			animationState = Axolotl.AxolotlAnimationState.IN_AIR;
249
		}
250
251
		this.playingDeadAnimator.tick(animationState == Axolotl.AxolotlAnimationState.PLAYING_DEAD);
252
		this.inWaterAnimator.tick(animationState == Axolotl.AxolotlAnimationState.IN_WATER);
253
		this.onGroundAnimator.tick(animationState == Axolotl.AxolotlAnimationState.ON_GROUND);
254
		boolean isMoving = this.walkAnimation.isMoving() || this.getXRot() != this.xRotO || this.getYRot() != this.yRotO;
255
		this.movingAnimator.tick(isMoving);
256
	}
257
258
	protected void handleAirSupply(final ServerLevel level, final int preTickAirSupply) {
259
		if (this.isAlive() && !this.isInWaterOrRain()) {
260
			this.setAirSupply(preTickAirSupply - 1);
261
			if (this.shouldTakeDrowningDamage()) {
262
				this.setAirSupply(0);
263
				this.hurtServer(level, this.damageSources().dryOut(), 2.0F);
264
			}
265
		} else {
266
			this.setAirSupply(this.getMaxAirSupply());
267
		}
268
	}
269
270
	public void rehydrate() {
271
		int newAirSupply = this.getAirSupply() + 1800;
272
		this.setAirSupply(Math.min(newAirSupply, this.getMaxAirSupply()));
273
	}
274
275
	@Override
276
	public int getMaxAirSupply() {
277
		return 6000;
278
	}
279
280
	public Axolotl.Variant getVariant() {
281
		return Axolotl.Variant.byId(this.entityData.get(DATA_VARIANT));
282
	}
283
284
	private void setVariant(final Axolotl.Variant variant) {
285
		this.entityData.set(DATA_VARIANT, variant.getId());
286
	}
287
288
	@Override
289
	public <T> @Nullable T get(final DataComponentType<? extends T> type) {
290
		return type == DataComponents.AXOLOTL_VARIANT ? castComponentValue((DataComponentType<T>)type, this.getVariant()) : super.get(type);
291
	}
292
293
	@Override
294
	protected void applyImplicitComponents(final DataComponentGetter components) {
295
		this.applyImplicitComponentIfPresent(components, DataComponents.AXOLOTL_VARIANT);
296
		super.applyImplicitComponents(components);
297
	}
298
299
	@Override
300
	protected <T> boolean applyImplicitComponent(final DataComponentType<T> type, final T value) {
301
		if (type == DataComponents.AXOLOTL_VARIANT) {
302
			this.setVariant(castComponentValue(DataComponents.AXOLOTL_VARIANT, value));
303
			return true;
304
		} else {
305
			return super.applyImplicitComponent(type, value);
306
		}
307
	}
308
309
	private static boolean useRareVariant(final RandomSource random) {
310
		return random.nextInt(1200) == 0;
311
	}
312
313
	@Override
314
	public boolean checkSpawnObstruction(final LevelReader level) {
315
		return level.isUnobstructed(this);
316
	}
317
318
	@Override
319
	public boolean isPushedByFluid() {
320
		return false;
321
	}
322
323
	public void setPlayingDead(final boolean playingDead) {
324
		this.entityData.set(DATA_PLAYING_DEAD, playingDead);
325
	}
326
327
	public boolean isPlayingDead() {
328
		return this.entityData.get(DATA_PLAYING_DEAD);
329
	}
330
331
	@Override
332
	public boolean fromBucket() {
333
		return this.entityData.get(FROM_BUCKET);
334
	}
335
336
	@Override
337
	public void setFromBucket(final boolean fromBucket) {
338
		this.entityData.set(FROM_BUCKET, fromBucket);
339
	}
340
341
	@Override
342
	public @Nullable AgeableMob getBreedOffspring(final ServerLevel level, final AgeableMob partner) {
343
		Axolotl baby = EntityTypes.AXOLOTL.create(level, EntitySpawnReason.BREEDING);
344
		if (baby != null) {
345
			Axolotl.Variant variant;
346
			if (useRareVariant(this.random)) {
347
				variant = Axolotl.Variant.getRareSpawnVariant(this.random);
348
			} else {
349
				variant = this.random.nextBoolean() ? this.getVariant() : ((Axolotl)partner).getVariant();
350
			}
351
352
			baby.setVariant(variant);
353
			baby.setPersistenceRequired();
354
		}
355
356
		return baby;
357
	}
358
359
	@Override
360
	public boolean isFood(final ItemStack itemStack) {
361
		return itemStack.is(ItemTags.AXOLOTL_FOOD);
362
	}
363
364
	@Override
365
	public boolean canBeLeashed() {
366
		return true;
367
	}
368
369
	@Override
370
	protected void customServerAiStep(final ServerLevel level) {
371
		ProfilerFiller profiler = Profiler.get();
372
		profiler.push("axolotlBrain");
373
		this.getBrain().tick(level, this);
374
		profiler.pop();
375
		profiler.push("axolotlActivityUpdate");
376
		AxolotlAi.updateActivity(this);
377
		profiler.pop();
378
		if (!this.isNoAi()) {
379
			Optional<Integer> playDeadTicks = this.getBrain().getMemory(MemoryModuleType.PLAY_DEAD_TICKS);
380
			this.setPlayingDead(playDeadTicks.isPresent() && playDeadTicks.get() > 0);
381
		}
382
	}
383
384
	public static AttributeSupplier.Builder createAttributes() {
385
		return Animal.createAnimalAttributes()
386
			.add(Attributes.MAX_HEALTH, 14.0)
387
			.add(Attributes.MOVEMENT_SPEED, 1.0)
388
			.add(Attributes.ATTACK_DAMAGE, 2.0)
389
			.add(Attributes.STEP_HEIGHT, 1.0);
390
	}
391
392
	@Override
393
	protected PathNavigation createNavigation(final Level level) {
394
		return new AmphibiousPathNavigation(this, level);
395
	}
396
397
	@Override
398
	public void playAttackSound() {
399
		this.playSound(SoundEvents.AXOLOTL_ATTACK, 1.0F, 1.0F);
400
	}
401
402
	@Override
403
	public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
404
		float currentHealth = this.getHealth();
405
		if (!this.isNoAi()
406
			&& this.random.nextInt(3) == 0
407
			&& (this.random.nextInt(3) < damage || currentHealth / this.getMaxHealth() < 0.5F)
408
			&& damage < currentHealth
409
			&& this.isInWater()
410
			&& (source.getEntity() != null || source.getDirectEntity() != null)
411
			&& !this.isPlayingDead()) {
412
			this.brain.setMemory(MemoryModuleType.PLAY_DEAD_TICKS, 200);
413
		}
414
415
		return super.hurtServer(level, source, damage);
416
	}
417
418
	@Override
419
	public int getMaxHeadXRot() {
420
		return 1;
421
	}
422
423
	@Override
424
	public int getMaxHeadYRot() {
425
		return 1;
426
	}
427
428
	@Override
429
	public InteractionResult mobInteract(final Player player, final InteractionHand hand) {
430
		return Bucketable.bucketMobPickup(player, hand, this).orElse(super.mobInteract(player, hand));
431
	}
432
433
	@Override
434
	public void saveToBucketTag(final ItemStack bucket) {
435
		Bucketable.saveDefaultDataToBucketTag(this, bucket);
436
		bucket.copyFrom(DataComponents.AXOLOTL_VARIANT, this);
437
		CustomData.update(DataComponents.BUCKET_ENTITY_DATA, bucket, tag -> {
438
			tag.putInt("Age", this.getAge());
439
			tag.putBoolean("AgeLocked", this.isAgeLocked());
440
			Brain<?> brain = this.getBrain();
441
			if (brain.hasMemoryValue(MemoryModuleType.HAS_HUNTING_COOLDOWN)) {
442
				tag.putLong("HuntingCooldown", brain.getTimeUntilExpiry(MemoryModuleType.HAS_HUNTING_COOLDOWN));
443
			}
444
		});
445
	}
446
447
	@Override
448
	public void loadFromBucketTag(final CompoundTag tag) {
449
		Bucketable.loadDefaultDataFromBucketTag(this, tag);
450
		this.setAge(tag.getIntOr("Age", 0));
451
		this.setAgeLocked(tag.getBooleanOr("AgeLocked", false));
452
		tag.getLong("HuntingCooldown")
453
			.ifPresentOrElse(
454
				huntingCooldown -> this.getBrain().setMemoryWithExpiry(MemoryModuleType.HAS_HUNTING_COOLDOWN, true, tag.getLongOr("HuntingCooldown", 0L)),
455
				() -> this.getBrain().setMemory(MemoryModuleType.HAS_HUNTING_COOLDOWN, Optional.empty())
456
			);
457
	}
458
459
	@Override
460
	public ItemStack getBucketItemStack() {
461
		return new ItemStack(Items.AXOLOTL_BUCKET);
462
	}
463
464
	@Override
465
	public SoundEvent getPickupSound() {
466
		return SoundEvents.BUCKET_FILL_AXOLOTL;
467
	}
468
469
	@Override
470
	public boolean canBeSeenAsEnemy() {
471
		return !this.isPlayingDead() && super.canBeSeenAsEnemy();
472
	}
473
474
	public static void onStopAttacking(final ServerLevel level, final Axolotl body, final LivingEntity target) {
475
		if (target.isDeadOrDying()) {
476
			DamageSource lastDamageSource = target.getLastDamageSource();
477
			if (lastDamageSource != null && lastDamageSource.getEntity() instanceof Player player) {
478
				List<Player> playersInRange = level.getEntitiesOfClass(Player.class, body.getBoundingBox().inflate(20.0));
479
				if (playersInRange.contains(player)) {
480
					body.applySupportingEffects(player);
481
				}
482
			}
483
		}
484
	}
485
486
	public void applySupportingEffects(final Player player) {
487
		MobEffectInstance regenEffect = player.getEffect(MobEffects.REGENERATION);
488
		if (regenEffect == null || regenEffect.endsWithin(2399)) {
489
			int previousDuration = regenEffect != null ? regenEffect.getDuration() : 0;
490
			int regenDuration = Math.min(2400, 100 + previousDuration);
491
			player.addEffect(new MobEffectInstance(MobEffects.REGENERATION, regenDuration, 0), this);
492
		}
493
494
		player.removeEffect(MobEffects.MINING_FATIGUE);
495
	}
496
497
	@Override
498
	public boolean requiresCustomPersistence() {
499
		return super.requiresCustomPersistence() || this.fromBucket();
500
	}
501
502
	@Override
503
	protected SoundEvent getHurtSound(final DamageSource source) {
504
		return SoundEvents.AXOLOTL_HURT;
505
	}
506
507
	@Override
508
	protected @Nullable SoundEvent getDeathSound() {
509
		return SoundEvents.AXOLOTL_DEATH;
510
	}
511
512
	@Override
513
	protected @Nullable SoundEvent getAmbientSound() {
514
		return this.isInWater() ? SoundEvents.AXOLOTL_IDLE_WATER : SoundEvents.AXOLOTL_IDLE_AIR;
515
	}
516
517
	@Override
518
	protected SoundEvent getSwimSplashSound() {
519
		return SoundEvents.AXOLOTL_SPLASH;
520
	}
521
522
	@Override
523
	protected SoundEvent getSwimSound() {
524
		return SoundEvents.AXOLOTL_SWIM;
525
	}
526
527
	@Override
528
	protected Brain<Axolotl> makeBrain(final Brain.Packed packedBrain) {
529
		return BRAIN_PROVIDER.makeBrain(this, packedBrain);
530
	}
531
532
	@Override
533
	public Brain<Axolotl> getBrain() {
534
		return super.getBrain();
535
	}
536
537
	@Override
538
	protected void travelInWater(final Vec3 input, final double baseGravity, final boolean isFalling, final double oldY) {
539
		this.moveRelative(this.getSpeed(), input);
540
		this.move(MoverType.SELF, this.getDeltaMovement());
541
		this.setDeltaMovement(this.getDeltaMovement().scale(0.9));
542
	}
543
544
	@Override
545
	protected void usePlayerItem(final Player player, final InteractionHand hand, final ItemStack itemStack) {
546
		if (itemStack.is(Items.TROPICAL_FISH_BUCKET)) {
547
			player.setItemInHand(hand, ItemUtils.createFilledResult(itemStack, player, new ItemStack(Items.WATER_BUCKET)));
548
		} else {
549
			super.usePlayerItem(player, hand, itemStack);
550
		}
551
	}
552
553
	@Override
554
	public boolean removeWhenFarAway(final double distSqr) {
555
		return !this.fromBucket() && !this.hasCustomName();
556
	}
557
558
	@Override
559
	public @Nullable LivingEntity getTarget() {
560
		return this.getTargetFromBrain();
561
	}
562
563
	public static boolean checkAxolotlSpawnRules(
564
		final EntityType<? extends LivingEntity> type,
565
		final ServerLevelAccessor level,
566
		final EntitySpawnReason spawnReason,
567
		final BlockPos pos,
568
		final RandomSource random
569
	) {
570
		return level.getBlockState(pos.below()).is(BlockTags.AXOLOTLS_SPAWNABLE_ON);
571
	}
572
573
	@Override
574
	public EntityDimensions getDefaultDimensions(final Pose pose) {
575
		return this.isBaby() ? BABY_DIMENSIONS : super.getDefaultDimensions(pose);
576
	}
577
578
	public enum AxolotlAnimationState {
579
		PLAYING_DEAD,
580
		IN_WATER,
581
		ON_GROUND,
582
		IN_AIR;
583
	}
584
585
	public static class AxolotlGroupData extends AgeableMob.AgeableMobGroupData {
586
		public final Axolotl.Variant[] types;
587
588
		public AxolotlGroupData(final Axolotl.Variant... types) {
589
			super(false);
590
			this.types = types;
591
		}
592
593
		public Axolotl.Variant getVariant(final RandomSource random) {
594
			return this.types[random.nextInt(this.types.length)];
595
		}
596
	}
597
598
	private class AxolotlLookControl extends SmoothSwimmingLookControl {
599
		public AxolotlLookControl(final Axolotl axolotl, final int maxYRotFromCenter) {
600
			super(axolotl, maxYRotFromCenter);
601
		}
602
603
		@Override
604
		public void tick() {
605
			if (!Axolotl.this.isPlayingDead()) {
606
				super.tick();
607
			}
608
		}
609
	}
610
611
	private static class AxolotlMoveControl<T extends Axolotl> extends SmoothSwimmingMoveControl<T> {
612
		public AxolotlMoveControl(final T axolotl) {
613
			super(axolotl, 85, 10, 0.1F, 0.5F, false);
614
		}
615
616
		@Override
617
		public void tick() {
618
			if (!this.mob.isPlayingDead()) {
619
				super.tick();
620
			}
621
		}
622
	}
623
624
	public enum Variant implements StringRepresentable {
625
		LUCY(0, "lucy", true),
626
		WILD(1, "wild", true),
627
		GOLD(2, "gold", true),
628
		CYAN(3, "cyan", true),
629
		BLUE(4, "blue", false);
630
631
		public static final Axolotl.Variant DEFAULT = LUCY;
632
		private static final IntFunction<Axolotl.Variant> BY_ID = ByIdMap.continuous(Axolotl.Variant::getId, values(), ByIdMap.OutOfBoundsStrategy.ZERO);
633
		public static final StreamCodec<ByteBuf, Axolotl.Variant> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, Axolotl.Variant::getId);
634
		public static final Codec<Axolotl.Variant> CODEC = StringRepresentable.fromEnum(Axolotl.Variant::values);
635
		@Deprecated
636
		public static final Codec<Axolotl.Variant> LEGACY_CODEC = Codec.INT.xmap(BY_ID::apply, Axolotl.Variant::getId);
637
		private final int id;
638
		private final String name;
639
		private final boolean common;
640
641
		Variant(final int id, final String name, final boolean common) {
642
			this.id = id;
643
			this.name = name;
644
			this.common = common;
645
		}
646
647
		public int getId() {
648
			return this.id;
649
		}
650
651
		public String getName() {
652
			return this.name;
653
		}
654
655
		@Override
656
		public String getSerializedName() {
657
			return this.name;
658
		}
659
660
		public static Axolotl.Variant byId(final int id) {
661
			return BY_ID.apply(id);
662
		}
663
664
		public static Axolotl.Variant getCommonSpawnVariant(final RandomSource random) {
665
			return getSpawnVariant(random, true);
666
		}
667
668
		public static Axolotl.Variant getRareSpawnVariant(final RandomSource random) {
669
			return getSpawnVariant(random, false);
670
		}
671
672
		private static Axolotl.Variant getSpawnVariant(final RandomSource random, final boolean common) {
673
			Axolotl.Variant[] validVariants = Arrays.stream(values()).filter(v -> v.common == common).toArray(Axolotl.Variant[]::new);
674
			return Util.getRandom(validVariants, random);
675
		}
676
	}
677
}
678

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