Wolf .java

net.minecraft.world.entity.animal.wolf.Wolf (class): members: WolfAvoidEntityGoal, checkWolfSpawnRules, DATA_INTERESTED_ID, DEFAULT_TAIL_ANGLE, shakeAnimO.

net.minecraft.world.entity.animal.wolfclass704 linescommonextends TamableAnimal26.5 KB

Implements

API Surface (46)

void registerGoals()
Identifier getTexture()
void applyImplicitComponents(final DataComponentGetter components)
<T> boolean applyImplicitComponent(final DataComponentType<T> type, final T value)
AttributeSupplier.Builder createAttributes()
void defineSynchedData(final SynchedEntityData.Builder entityData)
void playStepSound(final BlockPos pos, final BlockState blockState)
void addAdditionalSaveData(final ValueOutput output)
void readAdditionalSaveData(final ValueInput input)
SoundEvent getAmbientSound()
SoundEvent getHurtSound(final DamageSource source)
SoundEvent getDeathSound()
float getSoundVolume()
void aiStep()
void tick()
void die(final DamageSource source)
float getWetShade(final float a)
float getShakeAnim(final float a)
float getHeadRollAngle(final float a)
int getMaxHeadXRot()
boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage)
void actuallyHurt(final ServerLevel level, final DamageSource source, final float damage)
void applyTamingSideEffects()
void hurtArmor(final DamageSource damageSource, final float damage)
boolean canShearEquipment(final Player player)
InteractionResult mobInteract(final Player player, final InteractionHand hand)
void handleEntityEvent(final @EntityEvent.Value byte id)
float getTailAngle()
boolean isFood(final ItemStack itemStack)
int getMaxSpawnClusterSize()
long getPersistentAngerEndTime()
void setPersistentAngerEndTime(final long endTime)
void startPersistentAngerTimer()
void setPersistentAngerTarget(final @Nullable EntityReference<LivingEntity> persistentAngerTarget)
DyeColor getCollarColor()
EntityDimensions getDefaultDimensions(final Pose pose)
void setIsInterested(final boolean value)
boolean canMate(final Animal partner)
boolean isInterested()
boolean wantsToAttack(final LivingEntity target, final LivingEntity owner)
boolean canBeLeashed()
Vec3 getLeashOffset()
boolean checkWolfSpawnRules(final EntityType<Wolf> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random)
boolean canUse()
void start()
void tick()

Fields & Constants (22)

DATA_INTERESTED_ID
DATA_COLLAR_COLOR
DATA_ANGER_END_TIME
DATA_VARIANT_ID
DATA_SOUND_VARIANT_ID
PREY_SELECTOR
BABY_DIMENSIONS
START_HEALTH
TAME_HEALTH
ARMOR_REPAIR_UNIT
DEFAULT_TAIL_ANGLE
DEFAULT_COLLAR_COLOR
PERSISTENT_ANGER_TIME
interestedAngle
interestedAngleO
isWet
isShaking
shakeAnim
shakeAnimO
persistentAngerTarget
spawnReason
pos

String literals (2)

"CollarColor"
"sound_variant"

Code Graph: Dependencies (80)

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

Full Source

Wolf.java704 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.animal.wolf;
2
3
import java.util.Optional;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.Holder;
6
import net.minecraft.core.Registry;
7
import net.minecraft.core.component.DataComponentGetter;
8
import net.minecraft.core.component.DataComponentType;
9
import net.minecraft.core.component.DataComponents;
10
import net.minecraft.core.particles.ItemParticleOption;
11
import net.minecraft.core.particles.ParticleTypes;
12
import net.minecraft.core.registries.Registries;
13
import net.minecraft.network.syncher.EntityDataAccessor;
14
import net.minecraft.network.syncher.EntityDataSerializers;
15
import net.minecraft.network.syncher.SynchedEntityData;
16
import net.minecraft.resources.Identifier;
17
import net.minecraft.resources.ResourceKey;
18
import net.minecraft.server.level.ServerLevel;
19
import net.minecraft.sounds.SoundEvent;
20
import net.minecraft.sounds.SoundEvents;
21
import net.minecraft.tags.BlockTags;
22
import net.minecraft.tags.DamageTypeTags;
23
import net.minecraft.tags.ItemTags;
24
import net.minecraft.util.Mth;
25
import net.minecraft.util.RandomSource;
26
import net.minecraft.util.TimeUtil;
27
import net.minecraft.util.valueproviders.UniformInt;
28
import net.minecraft.world.DifficultyInstance;
29
import net.minecraft.world.InteractionHand;
30
import net.minecraft.world.InteractionResult;
31
import net.minecraft.world.damagesource.DamageSource;
32
import net.minecraft.world.entity.AgeableMob;
33
import net.minecraft.world.entity.Crackiness;
34
import net.minecraft.world.entity.EntityAttachment;
35
import net.minecraft.world.entity.EntityAttachments;
36
import net.minecraft.world.entity.EntityDimensions;
37
import net.minecraft.world.entity.EntityEvent;
38
import net.minecraft.world.entity.EntityReference;
39
import net.minecraft.world.entity.EntitySpawnReason;
40
import net.minecraft.world.entity.EntityType;
41
import net.minecraft.world.entity.EntityTypes;
42
import net.minecraft.world.entity.EquipmentSlot;
43
import net.minecraft.world.entity.LivingEntity;
44
import net.minecraft.world.entity.NeutralMob;
45
import net.minecraft.world.entity.Pose;
46
import net.minecraft.world.entity.SpawnGroupData;
47
import net.minecraft.world.entity.TamableAnimal;
48
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
49
import net.minecraft.world.entity.ai.attributes.Attributes;
50
import net.minecraft.world.entity.ai.goal.AvoidEntityGoal;
51
import net.minecraft.world.entity.ai.goal.BegGoal;
52
import net.minecraft.world.entity.ai.goal.BreedGoal;
53
import net.minecraft.world.entity.ai.goal.FloatGoal;
54
import net.minecraft.world.entity.ai.goal.FollowOwnerGoal;
55
import net.minecraft.world.entity.ai.goal.LeapAtTargetGoal;
56
import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
57
import net.minecraft.world.entity.ai.goal.MeleeAttackGoal;
58
import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
59
import net.minecraft.world.entity.ai.goal.SitWhenOrderedToGoal;
60
import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal;
61
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal;
62
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
63
import net.minecraft.world.entity.ai.goal.target.NonTameRandomTargetGoal;
64
import net.minecraft.world.entity.ai.goal.target.OwnerHurtByTargetGoal;
65
import net.minecraft.world.entity.ai.goal.target.OwnerHurtTargetGoal;
66
import net.minecraft.world.entity.ai.goal.target.ResetUniversalAngerTargetGoal;
67
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
68
import net.minecraft.world.entity.animal.Animal;
69
import net.minecraft.world.entity.animal.equine.AbstractHorse;
70
import net.minecraft.world.entity.animal.equine.Llama;
71
import net.minecraft.world.entity.animal.turtle.Turtle;
72
import net.minecraft.world.entity.decoration.ArmorStand;
73
import net.minecraft.world.entity.monster.Creeper;
74
import net.minecraft.world.entity.monster.Ghast;
75
import net.minecraft.world.entity.monster.skeleton.AbstractSkeleton;
76
import net.minecraft.world.entity.player.Player;
77
import net.minecraft.world.entity.variant.SpawnContext;
78
import net.minecraft.world.entity.variant.VariantUtils;
79
import net.minecraft.world.item.DyeColor;
80
import net.minecraft.world.item.ItemStack;
81
import net.minecraft.world.item.Items;
82
import net.minecraft.world.level.Level;
83
import net.minecraft.world.level.LevelAccessor;
84
import net.minecraft.world.level.ServerLevelAccessor;
85
import net.minecraft.world.level.block.state.BlockState;
86
import net.minecraft.world.level.gameevent.GameEvent;
87
import net.minecraft.world.level.pathfinder.PathType;
88
import net.minecraft.world.level.storage.ValueInput;
89
import net.minecraft.world.level.storage.ValueOutput;
90
import net.minecraft.world.phys.Vec3;
91
import org.jspecify.annotations.Nullable;
92
93
public class Wolf extends TamableAnimal implements NeutralMob {
94
	private static final EntityDataAccessor<Boolean> DATA_INTERESTED_ID = SynchedEntityData.defineId(Wolf.class, EntityDataSerializers.BOOLEAN);
95
	private static final EntityDataAccessor<Integer> DATA_COLLAR_COLOR = SynchedEntityData.defineId(Wolf.class, EntityDataSerializers.INT);
96
	private static final EntityDataAccessor<Long> DATA_ANGER_END_TIME = SynchedEntityData.defineId(Wolf.class, EntityDataSerializers.LONG);
97
	private static final EntityDataAccessor<Holder<WolfVariant>> DATA_VARIANT_ID = SynchedEntityData.defineId(Wolf.class, EntityDataSerializers.WOLF_VARIANT);
98
	private static final EntityDataAccessor<Holder<WolfSoundVariant>> DATA_SOUND_VARIANT_ID = SynchedEntityData.defineId(
99
		Wolf.class, EntityDataSerializers.WOLF_SOUND_VARIANT
100
	);
101
	public static final TargetingConditions.Selector PREY_SELECTOR = (target, level) -> target.is(EntityTypes.SHEEP)
102
		|| target.is(EntityTypes.RABBIT)
103
		|| target.is(EntityTypes.FOX);
104
	private static final EntityDimensions BABY_DIMENSIONS = EntityDimensions.scalable(0.3F, 0.425F)
105
		.withEyeHeight(0.34375F)
106
		.withAttachments(EntityAttachments.builder().attach(EntityAttachment.PASSENGER, 0.0F, 0.4375F, 0.0F));
107
	private static final float START_HEALTH = 8.0F;
108
	private static final float TAME_HEALTH = 40.0F;
109
	private static final float ARMOR_REPAIR_UNIT = 0.125F;
110
	public static final float DEFAULT_TAIL_ANGLE = (float) (Math.PI / 5);
111
	private static final DyeColor DEFAULT_COLLAR_COLOR = DyeColor.RED;
112
	private float interestedAngle;
113
	private float interestedAngleO;
114
	private boolean isWet;
115
	private boolean isShaking;
116
	private float shakeAnim;
117
	private float shakeAnimO;
118
	private static final UniformInt PERSISTENT_ANGER_TIME = TimeUtil.rangeOfSeconds(20, 39);
119
	private @Nullable EntityReference<LivingEntity> persistentAngerTarget;
120
121
	public Wolf(final EntityType<? extends Wolf> type, final Level level) {
122
		super(type, level);
123
		this.setTame(false, false);
124
		this.setPathfindingMalus(PathType.POWDER_SNOW, -1.0F);
125
		this.setPathfindingMalus(PathType.ON_TOP_OF_POWDER_SNOW, -1.0F);
126
	}
127
128
	@Override
129
	protected void registerGoals() {
130
		this.goalSelector.addGoal(1, new FloatGoal(this));
131
		this.goalSelector.addGoal(1, new TamableAnimal.TamableAnimalPanicGoal(1.5, DamageTypeTags.PANIC_ENVIRONMENTAL_CAUSES));
132
		this.goalSelector.addGoal(2, new SitWhenOrderedToGoal(this));
133
		this.goalSelector.addGoal(3, new Wolf.WolfAvoidEntityGoal<>(this, Llama.class, 24.0F, 1.5, 1.5));
134
		this.goalSelector.addGoal(4, new LeapAtTargetGoal(this, 0.4F));
135
		this.goalSelector.addGoal(5, new MeleeAttackGoal(this, 1.0, true));
136
		this.goalSelector.addGoal(6, new FollowOwnerGoal(this, 1.0, 10.0F, 2.0F));
137
		this.goalSelector.addGoal(7, new BreedGoal(this, 1.0));
138
		this.goalSelector.addGoal(8, new WaterAvoidingRandomStrollGoal(this, 1.0));
139
		this.goalSelector.addGoal(9, new BegGoal(this, 8.0F));
140
		this.goalSelector.addGoal(10, new LookAtPlayerGoal(this, Player.class, 8.0F));
141
		this.goalSelector.addGoal(10, new RandomLookAroundGoal(this));
142
		this.targetSelector.addGoal(1, new OwnerHurtByTargetGoal(this));
143
		this.targetSelector.addGoal(2, new OwnerHurtTargetGoal(this));
144
		this.targetSelector.addGoal(3, new HurtByTargetGoal(this).setAlertOthers());
145
		this.targetSelector.addGoal(4, new NearestAttackableTargetGoal<>(this, Player.class, 10, true, false, this::isAngryAt));
146
		this.targetSelector.addGoal(5, new NonTameRandomTargetGoal<>(this, Animal.class, false, PREY_SELECTOR));
147
		this.targetSelector.addGoal(6, new NonTameRandomTargetGoal<>(this, Turtle.class, false, Turtle.BABY_ON_LAND_SELECTOR));
148
		this.targetSelector.addGoal(7, new NearestAttackableTargetGoal<>(this, AbstractSkeleton.class, false));
149
		this.targetSelector.addGoal(8, new ResetUniversalAngerTargetGoal<>(this, true));
150
	}
151
152
	public Identifier getTexture() {
153
		WolfVariant variant = this.getVariant().value();
154
		WolfVariant.AssetInfo assetInfo = this.isBaby() ? variant.babyInfo() : variant.adultInfo();
155
		if (this.isTame()) {
156
			return assetInfo.tame().texturePath();
157
		} else {
158
			return this.isAngry() ? assetInfo.angry().texturePath() : assetInfo.wild().texturePath();
159
		}
160
	}
161
162
	private Holder<WolfVariant> getVariant() {
163
		return this.entityData.get(DATA_VARIANT_ID);
164
	}
165
166
	private void setVariant(final Holder<WolfVariant> variant) {
167
		this.entityData.set(DATA_VARIANT_ID, variant);
168
	}
169
170
	private Holder<WolfSoundVariant> getSoundVariant() {
171
		return this.entityData.get(DATA_SOUND_VARIANT_ID);
172
	}
173
174
	private WolfSoundVariant.WolfSoundSet getSoundSet() {
175
		return this.isBaby() ? this.getSoundVariant().value().babySounds() : this.getSoundVariant().value().adultSounds();
176
	}
177
178
	private void setSoundVariant(final Holder<WolfSoundVariant> soundVariant) {
179
		this.entityData.set(DATA_SOUND_VARIANT_ID, soundVariant);
180
	}
181
182
	@Override
183
	public <T> @Nullable T get(final DataComponentType<? extends T> type) {
184
		if (type == DataComponents.WOLF_VARIANT) {
185
			return castComponentValue((DataComponentType<T>)type, this.getVariant());
186
		} else if (type == DataComponents.WOLF_SOUND_VARIANT) {
187
			return castComponentValue((DataComponentType<T>)type, this.getSoundVariant());
188
		} else {
189
			return type == DataComponents.WOLF_COLLAR ? castComponentValue((DataComponentType<T>)type, this.getCollarColor()) : super.get(type);
190
		}
191
	}
192
193
	@Override
194
	protected void applyImplicitComponents(final DataComponentGetter components) {
195
		this.applyImplicitComponentIfPresent(components, DataComponents.WOLF_VARIANT);
196
		this.applyImplicitComponentIfPresent(components, DataComponents.WOLF_SOUND_VARIANT);
197
		this.applyImplicitComponentIfPresent(components, DataComponents.WOLF_COLLAR);
198
		super.applyImplicitComponents(components);
199
	}
200
201
	@Override
202
	protected <T> boolean applyImplicitComponent(final DataComponentType<T> type, final T value) {
203
		if (type == DataComponents.WOLF_VARIANT) {
204
			this.setVariant(castComponentValue(DataComponents.WOLF_VARIANT, value));
205
			return true;
206
		} else if (type == DataComponents.WOLF_SOUND_VARIANT) {
207
			this.setSoundVariant(castComponentValue(DataComponents.WOLF_SOUND_VARIANT, value));
208
			return true;
209
		} else if (type == DataComponents.WOLF_COLLAR) {
210
			this.setCollarColor(castComponentValue(DataComponents.WOLF_COLLAR, value));
211
			return true;
212
		} else {
213
			return super.applyImplicitComponent(type, value);
214
		}
215
	}
216
217
	public static AttributeSupplier.Builder createAttributes() {
218
		return Animal.createAnimalAttributes().add(Attributes.MOVEMENT_SPEED, 0.3F).add(Attributes.MAX_HEALTH, 8.0).add(Attributes.ATTACK_DAMAGE, 4.0);
219
	}
220
221
	@Override
222
	protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
223
		super.defineSynchedData(entityData);
224
		Registry<WolfSoundVariant> wolfSoundVariants = this.registryAccess().lookupOrThrow(Registries.WOLF_SOUND_VARIANT);
225
		entityData.define(DATA_VARIANT_ID, VariantUtils.getDefaultOrAny(this.registryAccess(), WolfVariants.DEFAULT));
226
		entityData.define(DATA_SOUND_VARIANT_ID, wolfSoundVariants.get(WolfSoundVariants.CLASSIC).or(wolfSoundVariants::getAny).orElseThrow());
227
		entityData.define(DATA_INTERESTED_ID, false);
228
		entityData.define(DATA_COLLAR_COLOR, DEFAULT_COLLAR_COLOR.getId());
229
		entityData.define(DATA_ANGER_END_TIME, -1L);
230
	}
231
232
	@Override
233
	protected void playStepSound(final BlockPos pos, final BlockState blockState) {
234
		this.playSound(this.getSoundSet().stepSound().value(), 0.15F, 1.0F);
235
	}
236
237
	@Override
238
	protected void addAdditionalSaveData(final ValueOutput output) {
239
		super.addAdditionalSaveData(output);
240
		output.store("CollarColor", DyeColor.LEGACY_ID_CODEC, this.getCollarColor());
241
		VariantUtils.writeVariant(output, this.getVariant());
242
		this.addPersistentAngerSaveData(output);
243
		this.getSoundVariant()
244
			.unwrapKey()
245
			.ifPresent(soundVariant -> output.store("sound_variant", ResourceKey.codec(Registries.WOLF_SOUND_VARIANT), (ResourceKey<WolfSoundVariant>)soundVariant));
246
	}
247
248
	@Override
249
	protected void readAdditionalSaveData(final ValueInput input) {
250
		super.readAdditionalSaveData(input);
251
		VariantUtils.readVariant(input, Registries.WOLF_VARIANT).ifPresent(this::setVariant);
252
		this.setCollarColor(input.read("CollarColor", DyeColor.LEGACY_ID_CODEC).orElse(DEFAULT_COLLAR_COLOR));
253
		this.readPersistentAngerSaveData(this.level(), input);
254
		input.read("sound_variant", ResourceKey.codec(Registries.WOLF_SOUND_VARIANT))
255
			.flatMap(soundVariant -> this.registryAccess().lookupOrThrow(Registries.WOLF_SOUND_VARIANT).get((ResourceKey<WolfSoundVariant>)soundVariant))
256
			.ifPresent(this::setSoundVariant);
257
	}
258
259
	@Override
260
	public @Nullable SpawnGroupData finalizeSpawn(
261
		final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, @Nullable SpawnGroupData groupData
262
	) {
263
		if (groupData instanceof Wolf.WolfPackData wolfGroupData) {
264
			this.setVariant(wolfGroupData.type);
265
		} else {
266
			Optional<? extends Holder<WolfVariant>> selectedVariant = VariantUtils.selectVariantToSpawn(
267
				SpawnContext.create(level, this.blockPosition()), Registries.WOLF_VARIANT
268
			);
269
			if (selectedVariant.isPresent()) {
270
				this.setVariant((Holder<WolfVariant>)selectedVariant.get());
271
				groupData = new Wolf.WolfPackData((Holder<WolfVariant>)selectedVariant.get());
272
			}
273
		}
274
275
		this.setSoundVariant(WolfSoundVariants.pickRandomSoundVariant(this.registryAccess(), level.getRandom()));
276
		return super.finalizeSpawn(level, difficulty, spawnReason, groupData);
277
	}
278
279
	@Override
280
	protected SoundEvent getAmbientSound() {
281
		if (this.isAngry()) {
282
			return this.getSoundSet().growlSound().value();
283
		} else if (this.random.nextInt(3) == 0) {
284
			return this.isTame() && this.getHealth() < 20.0F ? this.getSoundSet().whineSound().value() : this.getSoundSet().pantSound().value();
285
		} else {
286
			return this.getSoundSet().ambientSound().value();
287
		}
288
	}
289
290
	@Override
291
	protected SoundEvent getHurtSound(final DamageSource source) {
292
		return this.canArmorAbsorb(source) ? SoundEvents.WOLF_ARMOR_DAMAGE : this.getSoundSet().hurtSound().value();
293
	}
294
295
	@Override
296
	protected SoundEvent getDeathSound() {
297
		return this.getSoundSet().deathSound().value();
298
	}
299
300
	@Override
301
	protected float getSoundVolume() {
302
		return 0.4F;
303
	}
304
305
	@Override
306
	public void aiStep() {
307
		super.aiStep();
308
		if (!this.level().isClientSide() && this.isWet && !this.isShaking && !this.isPathFinding() && this.onGround()) {
309
			this.isShaking = true;
310
			this.shakeAnim = 0.0F;
311
			this.shakeAnimO = 0.0F;
312
			this.level().broadcastEntityEvent(this, (byte)8);
313
		}
314
315
		if (!this.level().isClientSide()) {
316
			this.updatePersistentAnger((ServerLevel)this.level(), true);
317
		}
318
	}
319
320
	@Override
321
	public void tick() {
322
		super.tick();
323
		if (this.isAlive()) {
324
			this.interestedAngleO = this.interestedAngle;
325
			if (this.isInterested()) {
326
				this.interestedAngle = this.interestedAngle + (1.0F - this.interestedAngle) * 0.4F;
327
			} else {
328
				this.interestedAngle = this.interestedAngle + (0.0F - this.interestedAngle) * 0.4F;
329
			}
330
331
			if (this.isInWaterOrRain()) {
332
				this.isWet = true;
333
				if (this.isShaking && !this.level().isClientSide()) {
334
					this.level().broadcastEntityEvent(this, (byte)56);
335
					this.cancelShake();
336
				}
337
			} else if ((this.isWet || this.isShaking) && this.isShaking) {
338
				if (this.shakeAnim == 0.0F) {
339
					this.playSound(SoundEvents.WOLF_SHAKE, this.getSoundVolume(), (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F);
340
					this.gameEvent(GameEvent.ENTITY_ACTION);
341
				}
342
343
				this.shakeAnimO = this.shakeAnim;
344
				this.shakeAnim += 0.05F;
345
				if (this.shakeAnimO >= 2.0F) {
346
					this.isWet = false;
347
					this.isShaking = false;
348
					this.shakeAnimO = 0.0F;
349
					this.shakeAnim = 0.0F;
350
				}
351
352
				if (this.shakeAnim > 0.4F) {
353
					float yt = (float)this.getY();
354
					int shakeCount = (int)(Mth.sin((this.shakeAnim - 0.4F) * (float) Math.PI) * 7.0F);
355
					Vec3 movement = this.getDeltaMovement();
356
357
					for (int i = 0; i < shakeCount; i++) {
358
						float xo = (this.random.nextFloat() * 2.0F - 1.0F) * this.getBbWidth() * 0.5F;
359
						float zo = (this.random.nextFloat() * 2.0F - 1.0F) * this.getBbWidth() * 0.5F;
360
						this.level().addParticle(ParticleTypes.SPLASH, this.getX() + xo, yt + 0.8F, this.getZ() + zo, movement.x, movement.y, movement.z);
361
					}
362
				}
363
			}
364
		}
365
	}
366
367
	private void cancelShake() {
368
		this.isShaking = false;
369
		this.shakeAnim = 0.0F;
370
		this.shakeAnimO = 0.0F;
371
	}
372
373
	@Override
374
	public void die(final DamageSource source) {
375
		this.isWet = false;
376
		this.isShaking = false;
377
		this.shakeAnimO = 0.0F;
378
		this.shakeAnim = 0.0F;
379
		super.die(source);
380
	}
381
382
	public float getWetShade(final float a) {
383
		return !this.isWet ? 1.0F : Math.min(0.75F + Mth.lerp(a, this.shakeAnimO, this.shakeAnim) / 2.0F * 0.25F, 1.0F);
384
	}
385
386
	public float getShakeAnim(final float a) {
387
		return Mth.lerp(a, this.shakeAnimO, this.shakeAnim);
388
	}
389
390
	public float getHeadRollAngle(final float a) {
391
		return Mth.lerp(a, this.interestedAngleO, this.interestedAngle) * 0.15F * (float) Math.PI;
392
	}
393
394
	@Override
395
	public int getMaxHeadXRot() {
396
		return this.isInSittingPose() ? 20 : super.getMaxHeadXRot();
397
	}
398
399
	@Override
400
	public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
401
		if (this.isInvulnerableTo(level, source)) {
402
			return false;
403
		}
404
405
		this.setOrderedToSit(false);
406
		return super.hurtServer(level, source, damage);
407
	}
408
409
	@Override
410
	protected void actuallyHurt(final ServerLevel level, final DamageSource source, final float damage) {
411
		if (!this.canArmorAbsorb(source)) {
412
			super.actuallyHurt(level, source, damage);
413
		} else {
414
			ItemStack armorBefore = this.getBodyArmorItem();
415
			int damageBefore = armorBefore.getDamageValue();
416
			int maxDamage = armorBefore.getMaxDamage();
417
			armorBefore.hurtAndBreak(Mth.ceil(damage), this, EquipmentSlot.BODY);
418
			if (Crackiness.WOLF_ARMOR.byDamage(damageBefore, maxDamage) != Crackiness.WOLF_ARMOR.byDamage(this.getBodyArmorItem())) {
419
				this.playSound(SoundEvents.WOLF_ARMOR_CRACK);
420
				level.sendParticles(new ItemParticleOption(ParticleTypes.ITEM, Items.ARMADILLO_SCUTE), this.getX(), this.getY() + 1.0, this.getZ(), 20, 0.2, 0.1, 0.2, 0.1);
421
			}
422
		}
423
	}
424
425
	private boolean canArmorAbsorb(final DamageSource source) {
426
		return this.getBodyArmorItem().is(Items.WOLF_ARMOR) && !source.is(DamageTypeTags.BYPASSES_WOLF_ARMOR);
427
	}
428
429
	@Override
430
	protected void applyTamingSideEffects() {
431
		if (this.isTame()) {
432
			this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(40.0);
433
			this.setHealth(40.0F);
434
		} else {
435
			this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(8.0);
436
		}
437
	}
438
439
	@Override
440
	protected void hurtArmor(final DamageSource damageSource, final float damage) {
441
		this.doHurtEquipment(damageSource, damage, EquipmentSlot.BODY);
442
	}
443
444
	@Override
445
	protected boolean canShearEquipment(final Player player) {
446
		return this.isOwnedBy(player);
447
	}
448
449
	@Override
450
	public InteractionResult mobInteract(final Player player, final InteractionHand hand) {
451
		ItemStack itemStack = player.getItemInHand(hand);
452
		if (this.isTame()) {
453
			if (this.isFood(itemStack) && this.getHealth() < this.getMaxHealth()) {
454
				this.feed(player, hand, itemStack, 2.0F, 2.0F);
455
				return InteractionResult.SUCCESS;
456
			}
457
458
			if (!itemStack.is(ItemTags.WOLF_COLLAR_DYES) || !this.isOwnedBy(player)) {
459
				if (this.isEquippableInSlot(itemStack, EquipmentSlot.BODY) && !this.isWearingBodyArmor() && this.isOwnedBy(player) && !this.isBaby()) {
460
					this.setItemSlotAndDropWhenKilled(EquipmentSlot.BODY, itemStack.copyWithCount(1));
461
					itemStack.consume(1, player);
462
					return InteractionResult.SUCCESS;
463
				}
464
465
				if (this.isInSittingPose()
466
					&& this.isWearingBodyArmor()
467
					&& this.isOwnedBy(player)
468
					&& this.getBodyArmorItem().isDamaged()
469
					&& this.getBodyArmorItem().isValidRepairItem(itemStack)) {
470
					itemStack.shrink(1);
471
					this.playSound(SoundEvents.WOLF_ARMOR_REPAIR);
472
					ItemStack armor = this.getBodyArmorItem();
473
					int repairUnit = (int)(armor.getMaxDamage() * 0.125F);
474
					armor.setDamageValue(Math.max(0, armor.getDamageValue() - repairUnit));
475
					return InteractionResult.SUCCESS;
476
				}
477
478
				InteractionResult interactionResult = super.mobInteract(player, hand);
479
				if (!interactionResult.consumesAction() && this.isOwnedBy(player)) {
480
					this.setOrderedToSit(!this.isOrderedToSit());
481
					this.jumping = false;
482
					this.navigation.stop();
483
					this.setTarget(null);
484
					return InteractionResult.SUCCESS.withoutItem();
485
				}
486
487
				return interactionResult;
488
			}
489
490
			DyeColor color = itemStack.get(DataComponents.DYE);
491
			if (color != null && color != this.getCollarColor()) {
492
				this.setCollarColor(color);
493
				itemStack.consume(1, player);
494
				return InteractionResult.SUCCESS;
495
			}
496
		} else if (!this.level().isClientSide() && itemStack.is(Items.BONE) && !this.isAngry()) {
497
			itemStack.consume(1, player);
498
			this.tryToTame(player);
499
			return InteractionResult.SUCCESS_SERVER;
500
		}
501
502
		return super.mobInteract(player, hand);
503
	}
504
505
	private void tryToTame(final Player player) {
506
		if (this.random.nextInt(3) == 0) {
507
			this.tame(player);
508
			this.navigation.stop();
509
			this.setTarget(null);
510
			this.setOrderedToSit(true);
511
			this.level().broadcastEntityEvent(this, (byte)7);
512
		} else {
513
			this.level().broadcastEntityEvent(this, (byte)6);
514
		}
515
	}
516
517
	@Override
518
	public void handleEntityEvent(final @EntityEvent.Value byte id) {
519
		if (id == 8) {
520
			this.isShaking = true;
521
			this.shakeAnim = 0.0F;
522
			this.shakeAnimO = 0.0F;
523
		} else if (id == 56) {
524
			this.cancelShake();
525
		} else {
526
			super.handleEntityEvent(id);
527
		}
528
	}
529
530
	public float getTailAngle() {
531
		if (this.isAngry()) {
532
			return 1.5393804F;
533
		} else if (this.isTame()) {
534
			float maxHealth = this.getMaxHealth();
535
			float damageRatio = (maxHealth - this.getHealth()) / maxHealth;
536
			return (0.55F - damageRatio * 0.4F) * (float) Math.PI;
537
		} else {
538
			return (float) (Math.PI / 5);
539
		}
540
	}
541
542
	@Override
543
	public boolean isFood(final ItemStack itemStack) {
544
		return itemStack.is(ItemTags.WOLF_FOOD);
545
	}
546
547
	@Override
548
	public int getMaxSpawnClusterSize() {
549
		return 8;
550
	}
551
552
	@Override
553
	public long getPersistentAngerEndTime() {
554
		return this.entityData.get(DATA_ANGER_END_TIME);
555
	}
556
557
	@Override
558
	public void setPersistentAngerEndTime(final long endTime) {
559
		this.entityData.set(DATA_ANGER_END_TIME, endTime);
560
	}
561
562
	@Override
563
	public void startPersistentAngerTimer() {
564
		this.setTimeToRemainAngry(PERSISTENT_ANGER_TIME.sample(this.random));
565
	}
566
567
	@Override
568
	public @Nullable EntityReference<LivingEntity> getPersistentAngerTarget() {
569
		return this.persistentAngerTarget;
570
	}
571
572
	@Override
573
	public void setPersistentAngerTarget(final @Nullable EntityReference<LivingEntity> persistentAngerTarget) {
574
		this.persistentAngerTarget = persistentAngerTarget;
575
	}
576
577
	public DyeColor getCollarColor() {
578
		return DyeColor.byId(this.entityData.get(DATA_COLLAR_COLOR));
579
	}
580
581
	private void setCollarColor(final DyeColor color) {
582
		this.entityData.set(DATA_COLLAR_COLOR, color.getId());
583
	}
584
585
	@Override
586
	public EntityDimensions getDefaultDimensions(final Pose pose) {
587
		return this.isBaby() ? BABY_DIMENSIONS : super.getDefaultDimensions(pose);
588
	}
589
590
	public @Nullable Wolf getBreedOffspring(final ServerLevel level, final AgeableMob partner) {
591
		Wolf baby = EntityTypes.WOLF.create(level, EntitySpawnReason.BREEDING);
592
		if (baby != null && partner instanceof Wolf partnerWolf) {
593
			if (this.random.nextBoolean()) {
594
				baby.setVariant(this.getVariant());
595
			} else {
596
				baby.setVariant(partnerWolf.getVariant());
597
			}
598
599
			if (this.isTame()) {
600
				baby.setOwnerReference(this.getOwnerReference());
601
				baby.setTame(true, true);
602
				DyeColor parent1CollarColor = this.getCollarColor();
603
				DyeColor parent2CollarColor = partnerWolf.getCollarColor();
604
				baby.setCollarColor(DyeColor.getMixedColor(level, parent1CollarColor, parent2CollarColor));
605
			}
606
607
			baby.setSoundVariant(WolfSoundVariants.pickRandomSoundVariant(this.registryAccess(), this.random));
608
		}
609
610
		return baby;
611
	}
612
613
	public void setIsInterested(final boolean value) {
614
		this.entityData.set(DATA_INTERESTED_ID, value);
615
	}
616
617
	@Override
618
	public boolean canMate(final Animal partner) {
619
		if (partner == this) {
620
			return false;
621
		} else if (!this.isTame()) {
622
			return false;
623
		} else if (!(partner instanceof Wolf wolf)) {
624
			return false;
625
		} else if (!wolf.isTame()) {
626
			return false;
627
		} else {
628
			return wolf.isInSittingPose() ? false : this.isInLove() && wolf.isInLove();
629
		}
630
	}
631
632
	public boolean isInterested() {
633
		return this.entityData.get(DATA_INTERESTED_ID);
634
	}
635
636
	@Override
637
	public boolean wantsToAttack(final LivingEntity target, final LivingEntity owner) {
638
		if (target instanceof Creeper || target instanceof Ghast || target instanceof ArmorStand) {
639
			return false;
640
		} else if (target instanceof Wolf wolfTarget) {
641
			return !wolfTarget.isTame() || wolfTarget.getOwner() != owner;
642
		} else if (target instanceof Player playerTarget && owner instanceof Player playerOwner && !playerOwner.canHarmPlayer(playerTarget)) {
643
			return false;
644
		} else {
645
			return target instanceof AbstractHorse horse && horse.isTamed() ? false : !(target instanceof TamableAnimal animal && animal.isTame());
646
		}
647
	}
648
649
	@Override
650
	public boolean canBeLeashed() {
651
		return !this.isAngry();
652
	}
653
654
	@Override
655
	public Vec3 getLeashOffset() {
656
		return new Vec3(0.0, 0.6F * this.getEyeHeight(), this.getBbWidth() * 0.4F);
657
	}
658
659
	public static boolean checkWolfSpawnRules(
660
		final EntityType<Wolf> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random
661
	) {
662
		return level.getBlockState(pos.below()).is(BlockTags.WOLVES_SPAWNABLE_ON) && isBrightEnoughToSpawn(level, pos);
663
	}
664
665
	private class WolfAvoidEntityGoal<T extends LivingEntity> extends AvoidEntityGoal<T> {
666
		private final Wolf wolf;
667
668
		public WolfAvoidEntityGoal(final Wolf wolf, final Class<T> avoidClass, final float maxDist, final double walkSpeedModifier, final double sprintSpeedModifier) {
669
			super(wolf, avoidClass, maxDist, walkSpeedModifier, sprintSpeedModifier);
670
			this.wolf = wolf;
671
		}
672
673
		@Override
674
		public boolean canUse() {
675
			return super.canUse() && this.toAvoid instanceof Llama ? !this.wolf.isTame() && this.avoidLlama((Llama)this.toAvoid) : false;
676
		}
677
678
		private boolean avoidLlama(final Llama llama) {
679
			return llama.getStrength() >= Wolf.this.random.nextInt(5);
680
		}
681
682
		@Override
683
		public void start() {
684
			Wolf.this.setTarget(null);
685
			super.start();
686
		}
687
688
		@Override
689
		public void tick() {
690
			Wolf.this.setTarget(null);
691
			super.tick();
692
		}
693
	}
694
695
	public static class WolfPackData extends AgeableMob.AgeableMobGroupData {
696
		public final Holder<WolfVariant> type;
697
698
		public WolfPackData(final Holder<WolfVariant> type) {
699
			super(false);
700
			this.type = type;
701
		}
702
	}
703
}
704

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