AbstractHorse .java

net.minecraft.world.entity.animal.equine.AbstractHorse (class, 1046 lines): members: BACKWARDS_MOVE_SPEED_FACTOR, SIDEWAYS_MOVE_SPEED_FACTOR, isBred.

net.minecraft.world.entity.animal.equineclass1,046 linescommonextends Animal33.2 KB

Implements

API Surface (88)

void registerGoals()
void addBehaviourGoals()
void defineSynchedData(final SynchedEntityData.Builder entityData)
boolean getFlag(final int flag)
void setFlag(final int flag, final boolean value)
boolean isTamed()
void setOwner(final @Nullable LivingEntity owner)
void setTamed(final boolean flag)
void onElasticLeashPull()
boolean supportQuadLeash()
Vec3[] getQuadLeashOffsets()
boolean isEating()
boolean isStanding()
boolean isBred()
void setBred(final boolean flag)
boolean canUseSlot(final EquipmentSlot slot)
void equipBodyArmor(final Player player, final ItemStack itemStack)
boolean canDispenserEquipIntoSlot(final EquipmentSlot slot)
int getTemper()
void setTemper(final int temper)
int modifyTemper(final int amount)
boolean isPushable()
boolean causeFallDamage(final double fallDistance, final float damageModifier, final DamageSource damageSource)
int getInventorySize()
void createInventory()
Holder<SoundEvent> getEquipSound(final EquipmentSlot slot, final ItemStack stack, final Equippable equippable)
boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage)
boolean canPerformRearing()
void playStepSound(final BlockPos pos, final BlockState blockState)
void playGallopSound(final SoundType soundType)
AttributeSupplier.Builder createBaseHorseAttributes()
int getMaxSpawnClusterSize()
int getMaxTemper()
float getSoundVolume()
int getAmbientSoundInterval()
void openCustomInventoryScreen(final Player player)
InteractionResult fedFood(final Player player, final ItemStack itemStack)
boolean handleEating(final Player player, final ItemStack itemStack)
void doPlayerRide(final Player player)
boolean isImmobile()
boolean isFood(final ItemStack itemStack)
void dropEquipment(final ServerLevel level)
void aiStep()
void followMommy(final ServerLevel level)
boolean canEatGrass()
void tick()
InteractionResult mobInteract(final Player player, final InteractionHand hand)
void setEating(final boolean flag)
void setStanding(final int ticks)
void clearStanding()
void standIfPossible()
void makeMad()
boolean tameWithName(final Player player)
void tickRidden(final Player controller, final Vec3 riddenInput)
Vec2 getRiddenRotation(final LivingEntity controller)
void addPassenger(final Entity passenger)
Vec3 getRiddenInput(final Player controller, final Vec3 selfInput)
float getRiddenSpeed(final Player controller)
void executeRidersJump(final float amount, final Vec3 input)
void playJumpSound()
void addAdditionalSaveData(final ValueOutput output)
void readAdditionalSaveData(final ValueInput input)
boolean canMate(final Animal partner)
boolean canParent()
boolean isMobControlled()
void setOffspringAttributes(final AgeableMob partner, final AbstractHorse baby)
double createOffspringAttribute(double parentAValue, double parentBValue, final double attributeRangeMin, final double attributeRangeMax, final RandomSource random)
float getEatAnim(final float a)
float getStandAnim(final float a)
float getMouthAnim(final float a)
void onPlayerJump(int jumpAmount)
boolean canJump()
void handleStartJump(final int jumpScale)
void handleStopJump()
void spawnTamingParticles(final boolean success)
void handleEntityEvent(final @EntityEvent.Value byte id)
void positionRider(final Entity passenger, final Entity.MoveFunction moveFunction)
float generateMaxHealth(final IntUnaryOperator integerByBoundProvider)
double generateJumpStrength(final DoubleSupplier probabilityProvider)
double generateSpeed(final DoubleSupplier probabilityProvider)
boolean onClimbable()
Vec3 getDismountLocationForPassenger(final LivingEntity passenger)
void randomizeAttributes(final RandomSource random)
boolean hasInventoryChanged(final Container oldInventory)
int getAmbientStandInterval()
Vec3 getPassengerAttachmentPoint(final Entity passenger, final EntityDimensions dimensions, final float scale)
int getInventoryColumns()
boolean shouldPanic()

Fields & Constants (46)

CHEST_SLOT_OFFSET
INVENTORY_SLOT_OFFSET
BREEDING_CROSS_FACTOR
MIN_MOVEMENT_SPEED
MAX_MOVEMENT_SPEED
MIN_JUMP_STRENGTH
MAX_JUMP_STRENGTH
MIN_HEALTH
MAX_HEALTH
BACKWARDS_MOVE_SPEED_FACTOR
SIDEWAYS_MOVE_SPEED_FACTOR
PARENT_HORSE_SELECTOR
MOMMY_TARGETING
DATA_ID_FLAGS
FLAG_TAME
FLAG_BRED
FLAG_EATING
FLAG_STANDING
FLAG_OPEN_MOUTH
BABY_SCALE
INVENTORY_ROWS
DEFAULT_TEMPER
DEFAULT_EATING_HAYSTACK
DEFAULT_BRED
DEFAULT_TAME
eatingCounter
mouthCounter
standCounter
tailCounter
sprintCounter
inventory
temper
playerJumpPendingScale
allowStandSliding
eatAnim
eatAnimO
standAnim
standAnimO
mouthAnim
mouthAnimO
canGallop
gallopSoundCounter
owner
attributeRangeMin
attributeRangeMax
spawnReason

String literals (6)

"EatingHaystack"
"Bred"
"Temper"
"Tame"
"Owner"
"Incorrect range for an attribute"

Code Graph: Dependencies (75)

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

Full Source

AbstractHorse.java1046 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.animal.equine;
2
3
import java.util.function.DoubleSupplier;
4
import java.util.function.IntUnaryOperator;
5
import net.minecraft.advancements.triggers.CriteriaTriggers;
6
import net.minecraft.core.BlockPos;
7
import net.minecraft.core.Direction;
8
import net.minecraft.core.Holder;
9
import net.minecraft.core.particles.ParticleOptions;
10
import net.minecraft.core.particles.ParticleTypes;
11
import net.minecraft.network.syncher.EntityDataAccessor;
12
import net.minecraft.network.syncher.EntityDataSerializers;
13
import net.minecraft.network.syncher.SynchedEntityData;
14
import net.minecraft.server.level.ServerLevel;
15
import net.minecraft.server.level.ServerPlayer;
16
import net.minecraft.sounds.SoundEvent;
17
import net.minecraft.sounds.SoundEvents;
18
import net.minecraft.tags.ItemTags;
19
import net.minecraft.util.Mth;
20
import net.minecraft.util.RandomSource;
21
import net.minecraft.world.Container;
22
import net.minecraft.world.DifficultyInstance;
23
import net.minecraft.world.InteractionHand;
24
import net.minecraft.world.InteractionResult;
25
import net.minecraft.world.SimpleContainer;
26
import net.minecraft.world.damagesource.DamageSource;
27
import net.minecraft.world.entity.AgeableMob;
28
import net.minecraft.world.entity.Entity;
29
import net.minecraft.world.entity.EntityDimensions;
30
import net.minecraft.world.entity.EntityEvent;
31
import net.minecraft.world.entity.EntityReference;
32
import net.minecraft.world.entity.EntitySpawnReason;
33
import net.minecraft.world.entity.EntityType;
34
import net.minecraft.world.entity.EquipmentSlot;
35
import net.minecraft.world.entity.HasCustomInventoryScreen;
36
import net.minecraft.world.entity.HumanoidArm;
37
import net.minecraft.world.entity.Leashable;
38
import net.minecraft.world.entity.LivingEntity;
39
import net.minecraft.world.entity.OwnableEntity;
40
import net.minecraft.world.entity.PlayerRideableJumping;
41
import net.minecraft.world.entity.Pose;
42
import net.minecraft.world.entity.SlotAccess;
43
import net.minecraft.world.entity.SpawnGroupData;
44
import net.minecraft.world.entity.ai.attributes.Attribute;
45
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
46
import net.minecraft.world.entity.ai.attributes.Attributes;
47
import net.minecraft.world.entity.ai.goal.BreedGoal;
48
import net.minecraft.world.entity.ai.goal.FloatGoal;
49
import net.minecraft.world.entity.ai.goal.FollowParentGoal;
50
import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
51
import net.minecraft.world.entity.ai.goal.PanicGoal;
52
import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
53
import net.minecraft.world.entity.ai.goal.RandomStandGoal;
54
import net.minecraft.world.entity.ai.goal.RunAroundLikeCrazyGoal;
55
import net.minecraft.world.entity.ai.goal.TemptGoal;
56
import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal;
57
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
58
import net.minecraft.world.entity.animal.Animal;
59
import net.minecraft.world.entity.player.Player;
60
import net.minecraft.world.entity.vehicle.DismountHelper;
61
import net.minecraft.world.inventory.AbstractMountInventoryMenu;
62
import net.minecraft.world.item.ItemStack;
63
import net.minecraft.world.item.Items;
64
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
65
import net.minecraft.world.item.enchantment.EnchantmentHelper;
66
import net.minecraft.world.item.equipment.Equippable;
67
import net.minecraft.world.level.Level;
68
import net.minecraft.world.level.ServerLevelAccessor;
69
import net.minecraft.world.level.block.Blocks;
70
import net.minecraft.world.level.block.SoundType;
71
import net.minecraft.world.level.block.state.BlockState;
72
import net.minecraft.world.level.gameevent.GameEvent;
73
import net.minecraft.world.level.storage.ValueInput;
74
import net.minecraft.world.level.storage.ValueOutput;
75
import net.minecraft.world.phys.AABB;
76
import net.minecraft.world.phys.Vec2;
77
import net.minecraft.world.phys.Vec3;
78
import org.jspecify.annotations.Nullable;
79
80
public abstract class AbstractHorse extends Animal implements PlayerRideableJumping, HasCustomInventoryScreen, OwnableEntity {
81
	public static final int CHEST_SLOT_OFFSET = 499;
82
	public static final int INVENTORY_SLOT_OFFSET = 500;
83
	public static final double BREEDING_CROSS_FACTOR = 0.15;
84
	private static final float MIN_MOVEMENT_SPEED = (float)generateSpeed(() -> 0.0);
85
	private static final float MAX_MOVEMENT_SPEED = (float)generateSpeed(() -> 1.0);
86
	private static final float MIN_JUMP_STRENGTH = (float)generateJumpStrength(() -> 0.0);
87
	private static final float MAX_JUMP_STRENGTH = (float)generateJumpStrength(() -> 1.0);
88
	private static final float MIN_HEALTH = generateMaxHealth(i -> 0);
89
	private static final float MAX_HEALTH = generateMaxHealth(i -> i - 1);
90
	private static final float BACKWARDS_MOVE_SPEED_FACTOR = 0.25F;
91
	private static final float SIDEWAYS_MOVE_SPEED_FACTOR = 0.5F;
92
	private static final TargetingConditions.Selector PARENT_HORSE_SELECTOR = (target, level) -> target instanceof AbstractHorse horse && horse.isBred();
93
	private static final TargetingConditions MOMMY_TARGETING = TargetingConditions.forNonCombat().range(16.0).ignoreLineOfSight().selector(PARENT_HORSE_SELECTOR);
94
	private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(AbstractHorse.class, EntityDataSerializers.BYTE);
95
	private static final int FLAG_TAME = 2;
96
	private static final int FLAG_BRED = 8;
97
	private static final int FLAG_EATING = 16;
98
	private static final int FLAG_STANDING = 32;
99
	private static final int FLAG_OPEN_MOUTH = 64;
100
	protected static final float BABY_SCALE = 0.7F;
101
	public static final int INVENTORY_ROWS = 3;
102
	private static final int DEFAULT_TEMPER = 0;
103
	private static final boolean DEFAULT_EATING_HAYSTACK = false;
104
	private static final boolean DEFAULT_BRED = false;
105
	private static final boolean DEFAULT_TAME = false;
106
	private int eatingCounter;
107
	private int mouthCounter;
108
	private int standCounter;
109
	public int tailCounter;
110
	public int sprintCounter;
111
	protected SimpleContainer inventory;
112
	protected int temper = 0;
113
	protected float playerJumpPendingScale;
114
	protected boolean allowStandSliding;
115
	private float eatAnim;
116
	private float eatAnimO;
117
	private float standAnim;
118
	private float standAnimO;
119
	private float mouthAnim;
120
	private float mouthAnimO;
121
	protected boolean canGallop = true;
122
	protected int gallopSoundCounter;
123
	private @Nullable EntityReference<LivingEntity> owner;
124
125
	protected AbstractHorse(final EntityType<? extends AbstractHorse> type, final Level level) {
126
		super(type, level);
127
		this.createInventory();
128
	}
129
130
	@Override
131
	protected void registerGoals() {
132
		this.goalSelector.addGoal(1, new RunAroundLikeCrazyGoal(this, 1.2));
133
		this.goalSelector.addGoal(2, new BreedGoal(this, 1.0, AbstractHorse.class));
134
		this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.0));
135
		this.goalSelector.addGoal(6, new WaterAvoidingRandomStrollGoal(this, 0.7));
136
		this.goalSelector.addGoal(7, new LookAtPlayerGoal(this, Player.class, 6.0F));
137
		this.goalSelector.addGoal(8, new RandomLookAroundGoal(this));
138
		if (this.canPerformRearing()) {
139
			this.goalSelector.addGoal(9, new RandomStandGoal(this));
140
		}
141
142
		this.addBehaviourGoals();
143
	}
144
145
	protected void addBehaviourGoals() {
146
		this.goalSelector.addGoal(0, new FloatGoal(this));
147
		this.goalSelector.addGoal(1, new AbstractHorse.MountPanicGoal(1.2));
148
		this.goalSelector.addGoal(3, new TemptGoal(this, 1.25, i -> i.is(ItemTags.HORSE_TEMPT_ITEMS), false));
149
	}
150
151
	@Override
152
	protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
153
		super.defineSynchedData(entityData);
154
		entityData.define(DATA_ID_FLAGS, (byte)0);
155
	}
156
157
	protected boolean getFlag(final int flag) {
158
		return (this.entityData.get(DATA_ID_FLAGS) & flag) != 0;
159
	}
160
161
	protected void setFlag(final int flag, final boolean value) {
162
		byte current = this.entityData.get(DATA_ID_FLAGS);
163
		if (value) {
164
			this.entityData.set(DATA_ID_FLAGS, (byte)(current | flag));
165
		} else {
166
			this.entityData.set(DATA_ID_FLAGS, (byte)(current & ~flag));
167
		}
168
	}
169
170
	public boolean isTamed() {
171
		return this.getFlag(2);
172
	}
173
174
	@Override
175
	public @Nullable EntityReference<LivingEntity> getOwnerReference() {
176
		return this.owner;
177
	}
178
179
	public void setOwner(final @Nullable LivingEntity owner) {
180
		this.owner = EntityReference.of(owner);
181
	}
182
183
	public void setTamed(final boolean flag) {
184
		this.setFlag(2, flag);
185
	}
186
187
	@Override
188
	public void onElasticLeashPull() {
189
		super.onElasticLeashPull();
190
		if (this.isEating()) {
191
			this.setEating(false);
192
		}
193
	}
194
195
	@Override
196
	public boolean supportQuadLeash() {
197
		return true;
198
	}
199
200
	@Override
201
	public Vec3[] getQuadLeashOffsets() {
202
		return Leashable.createQuadLeashOffsets(this, 0.04, 0.52, 0.23, 0.87);
203
	}
204
205
	public boolean isEating() {
206
		return this.getFlag(16);
207
	}
208
209
	public boolean isStanding() {
210
		return this.getFlag(32);
211
	}
212
213
	public boolean isBred() {
214
		return this.getFlag(8);
215
	}
216
217
	public void setBred(final boolean flag) {
218
		this.setFlag(8, flag);
219
	}
220
221
	@Override
222
	public boolean canUseSlot(final EquipmentSlot slot) {
223
		return slot != EquipmentSlot.SADDLE ? super.canUseSlot(slot) : this.isAlive() && !this.isBaby() && this.isTamed();
224
	}
225
226
	public void equipBodyArmor(final Player player, final ItemStack itemStack) {
227
		if (this.isEquippableInSlot(itemStack, EquipmentSlot.BODY)) {
228
			this.setItemSlotAndDropWhenKilled(EquipmentSlot.BODY, itemStack.consumeAndReturn(1, player));
229
		}
230
	}
231
232
	@Override
233
	protected boolean canDispenserEquipIntoSlot(final EquipmentSlot slot) {
234
		return (slot == EquipmentSlot.BODY || slot == EquipmentSlot.SADDLE) && this.isTamed() || super.canDispenserEquipIntoSlot(slot);
235
	}
236
237
	public int getTemper() {
238
		return this.temper;
239
	}
240
241
	public void setTemper(final int temper) {
242
		this.temper = temper;
243
	}
244
245
	public int modifyTemper(final int amount) {
246
		int temper = Mth.clamp(this.getTemper() + amount, 0, this.getMaxTemper());
247
		this.setTemper(temper);
248
		return temper;
249
	}
250
251
	@Override
252
	public boolean isPushable() {
253
		return !this.isVehicle();
254
	}
255
256
	private void eating() {
257
		this.openMouth();
258
		if (!this.isSilent()) {
259
			SoundEvent eatingSound = this.getEatingSound();
260
			if (eatingSound != null) {
261
				this.level()
262
					.playSound(
263
						null, this.getX(), this.getY(), this.getZ(), eatingSound, this.getSoundSource(), 1.0F, 1.0F + (this.random.nextFloat() - this.random.nextFloat()) * 0.2F
264
					);
265
			}
266
		}
267
	}
268
269
	@Override
270
	public boolean causeFallDamage(final double fallDistance, final float damageModifier, final DamageSource damageSource) {
271
		if (fallDistance > 1.0) {
272
			this.playSound(this.isBaby() ? SoundEvents.HORSE_LAND_BABY : SoundEvents.HORSE_LAND, 0.4F, 1.0F);
273
		}
274
275
		int dmg = this.calculateFallDamage(fallDistance, damageModifier);
276
		if (dmg <= 0) {
277
			return false;
278
		}
279
280
		this.hurt(damageSource, dmg);
281
		this.propagateFallToPassengers(fallDistance, damageModifier, damageSource);
282
		this.playBlockFallSound();
283
		return true;
284
	}
285
286
	public final int getInventorySize() {
287
		return AbstractMountInventoryMenu.getInventorySize(this.getInventoryColumns());
288
	}
289
290
	protected void createInventory() {
291
		SimpleContainer old = this.inventory;
292
		this.inventory = new SimpleContainer(this.getInventorySize());
293
		if (old != null) {
294
			int max = Math.min(old.getContainerSize(), this.inventory.getContainerSize());
295
296
			for (int slot = 0; slot < max; slot++) {
297
				ItemStack itemStack = old.getItem(slot);
298
				if (!itemStack.isEmpty()) {
299
					this.inventory.setItem(slot, itemStack.copy());
300
				}
301
			}
302
		}
303
	}
304
305
	@Override
306
	protected Holder<SoundEvent> getEquipSound(final EquipmentSlot slot, final ItemStack stack, final Equippable equippable) {
307
		return slot == EquipmentSlot.SADDLE ? SoundEvents.HORSE_SADDLE : super.getEquipSound(slot, stack, equippable);
308
	}
309
310
	@Override
311
	public boolean hurtServer(final ServerLevel level, final DamageSource source, final float damage) {
312
		boolean wasHurt = super.hurtServer(level, source, damage);
313
		if (wasHurt && this.random.nextInt(3) == 0) {
314
			this.standIfPossible();
315
		}
316
317
		return wasHurt;
318
	}
319
320
	protected boolean canPerformRearing() {
321
		return true;
322
	}
323
324
	protected @Nullable SoundEvent getEatingSound() {
325
		return null;
326
	}
327
328
	protected @Nullable SoundEvent getAngrySound() {
329
		return null;
330
	}
331
332
	@Override
333
	protected void playStepSound(final BlockPos pos, final BlockState blockState) {
334
		if (!blockState.liquid()) {
335
			BlockState aboveState = this.level().getBlockState(pos.above());
336
			SoundType soundType = blockState.getSoundType();
337
			if (aboveState.is(Blocks.SNOW)) {
338
				soundType = aboveState.getSoundType();
339
			}
340
341
			if (this.isVehicle() && this.canGallop) {
342
				this.gallopSoundCounter++;
343
				if (this.gallopSoundCounter > 5 && this.gallopSoundCounter % 3 == 0) {
344
					this.playGallopSound(soundType);
345
				} else if (this.gallopSoundCounter <= 5) {
346
					this.playSound(SoundEvents.HORSE_STEP_WOOD, soundType.getVolume() * 0.15F, soundType.getPitch());
347
				}
348
			} else if (this.isWoodSoundType(soundType)) {
349
				this.playSound(SoundEvents.HORSE_STEP_WOOD, soundType.getVolume() * 0.15F, soundType.getPitch());
350
			} else {
351
				this.playSound(this.isBaby() ? SoundEvents.HORSE_STEP_BABY : SoundEvents.HORSE_STEP, soundType.getVolume() * 0.15F, soundType.getPitch());
352
			}
353
		}
354
	}
355
356
	private boolean isWoodSoundType(final SoundType soundType) {
357
		return soundType == SoundType.WOOD
358
			|| soundType == SoundType.NETHER_WOOD
359
			|| soundType == SoundType.STEM
360
			|| soundType == SoundType.CHERRY_WOOD
361
			|| soundType == SoundType.BAMBOO_WOOD;
362
	}
363
364
	protected void playGallopSound(final SoundType soundType) {
365
		this.playSound(SoundEvents.HORSE_GALLOP, soundType.getVolume() * 0.15F, soundType.getPitch());
366
	}
367
368
	public static AttributeSupplier.Builder createBaseHorseAttributes() {
369
		return Animal.createAnimalAttributes()
370
			.add(Attributes.JUMP_STRENGTH, 0.7)
371
			.add(Attributes.MAX_HEALTH, 53.0)
372
			.add(Attributes.MOVEMENT_SPEED, 0.225F)
373
			.add(Attributes.STEP_HEIGHT, 1.0)
374
			.add(Attributes.SAFE_FALL_DISTANCE, 6.0)
375
			.add(Attributes.FALL_DAMAGE_MULTIPLIER, 0.5);
376
	}
377
378
	@Override
379
	public int getMaxSpawnClusterSize() {
380
		return 6;
381
	}
382
383
	public int getMaxTemper() {
384
		return 100;
385
	}
386
387
	@Override
388
	protected float getSoundVolume() {
389
		return 0.8F;
390
	}
391
392
	@Override
393
	public int getAmbientSoundInterval() {
394
		return 400;
395
	}
396
397
	@Override
398
	public void openCustomInventoryScreen(final Player player) {
399
		if (!this.level().isClientSide() && (!this.isVehicle() || this.hasPassenger(player)) && this.isTamed()) {
400
			player.openHorseInventory(this, this.inventory);
401
		}
402
	}
403
404
	public InteractionResult fedFood(final Player player, final ItemStack itemStack) {
405
		boolean ateFood = this.handleEating(player, itemStack);
406
		if (ateFood) {
407
			itemStack.consume(1, player);
408
		}
409
410
		return !ateFood && !this.level().isClientSide() ? InteractionResult.PASS : InteractionResult.SUCCESS_SERVER;
411
	}
412
413
	protected boolean handleEating(final Player player, final ItemStack itemStack) {
414
		boolean itemUsed = false;
415
		float heal = 0.0F;
416
		int ageUp = 0;
417
		int temper = 0;
418
		if (itemStack.is(Items.WHEAT)) {
419
			heal = 2.0F;
420
			ageUp = 20;
421
			temper = 3;
422
		} else if (itemStack.is(Items.SUGAR)) {
423
			heal = 1.0F;
424
			ageUp = 30;
425
			temper = 3;
426
		} else if (itemStack.is(Items.HAY_BLOCK)) {
427
			heal = 20.0F;
428
			ageUp = 180;
429
		} else if (itemStack.is(Items.APPLE)) {
430
			heal = 3.0F;
431
			ageUp = 60;
432
			temper = 3;
433
		} else if (itemStack.is(Items.RED_MUSHROOM)) {
434
			heal = 3.0F;
435
			ageUp = 0;
436
			temper = 3;
437
		} else if (itemStack.is(Items.CARROT)) {
438
			heal = 3.0F;
439
			ageUp = 60;
440
			temper = 3;
441
		} else if (itemStack.is(Items.GOLDEN_CARROT)) {
442
			heal = 4.0F;
443
			ageUp = 60;
444
			temper = 5;
445
			if (!this.level().isClientSide() && this.isTamed() && this.getAge() == 0 && !this.isInLove()) {
446
				itemUsed = true;
447
				this.setInLove(player);
448
			}
449
		} else if (itemStack.is(Items.GOLDEN_APPLE) || itemStack.is(Items.ENCHANTED_GOLDEN_APPLE)) {
450
			heal = 10.0F;
451
			ageUp = 240;
452
			temper = 10;
453
			if (!this.level().isClientSide() && this.isTamed() && this.getAge() == 0 && !this.isInLove()) {
454
				itemUsed = true;
455
				this.setInLove(player);
456
			}
457
		}
458
459
		if (this.getHealth() < this.getMaxHealth() && heal > 0.0F) {
460
			this.heal(heal);
461
			itemUsed = true;
462
		}
463
464
		if (this.isBaby() && ageUp > 0 && !this.isAgeLocked()) {
465
			this.level().addParticle(ParticleTypes.HAPPY_VILLAGER, this.getRandomX(1.0), this.getRandomY() + 0.5, this.getRandomZ(1.0), 0.0, 0.0, 0.0);
466
			if (!this.level().isClientSide()) {
467
				this.ageUp(ageUp);
468
				itemUsed = true;
469
			}
470
		}
471
472
		if (temper > 0 && (itemUsed || !this.isTamed()) && this.getTemper() < this.getMaxTemper() && !this.level().isClientSide()) {
473
			this.modifyTemper(temper);
474
			itemUsed = true;
475
		}
476
477
		if (itemUsed) {
478
			this.eating();
479
			this.gameEvent(GameEvent.EAT);
480
		}
481
482
		return itemUsed;
483
	}
484
485
	protected void doPlayerRide(final Player player) {
486
		this.setEating(false);
487
		this.clearStanding();
488
		if (!this.level().isClientSide()) {
489
			player.setYRot(this.getYRot());
490
			player.setXRot(this.getXRot());
491
			player.startRiding(this);
492
		}
493
	}
494
495
	@Override
496
	public boolean isImmobile() {
497
		return super.isImmobile() && this.isVehicle() && this.isSaddled() || this.isEating() || this.isStanding();
498
	}
499
500
	@Override
501
	public boolean isFood(final ItemStack itemStack) {
502
		return itemStack.is(ItemTags.HORSE_FOOD);
503
	}
504
505
	private void moveTail() {
506
		this.tailCounter = 1;
507
	}
508
509
	@Override
510
	protected void dropEquipment(final ServerLevel level) {
511
		super.dropEquipment(level);
512
		if (this.inventory != null) {
513
			for (int i = 0; i < this.inventory.getContainerSize(); i++) {
514
				ItemStack itemStack = this.inventory.getItem(i);
515
				if (!itemStack.isEmpty() && !EnchantmentHelper.has(itemStack, EnchantmentEffectComponents.PREVENT_EQUIPMENT_DROP)) {
516
					this.spawnAtLocation(level, itemStack);
517
				}
518
			}
519
		}
520
	}
521
522
	@Override
523
	public void aiStep() {
524
		if (this.random.nextInt(200) == 0) {
525
			this.moveTail();
526
		}
527
528
		super.aiStep();
529
		if (this.level() instanceof ServerLevel level && this.isAlive()) {
530
			if (this.random.nextInt(900) == 0 && this.deathTime == 0) {
531
				this.heal(1.0F);
532
			}
533
534
			if (this.canEatGrass()) {
535
				if (!this.isEating() && !this.isVehicle() && this.random.nextInt(300) == 0 && level.getBlockState(this.blockPosition().below()).is(Blocks.GRASS_BLOCK)) {
536
					this.setEating(true);
537
				}
538
539
				if (this.isEating() && ++this.eatingCounter > 50) {
540
					this.eatingCounter = 0;
541
					this.setEating(false);
542
				}
543
			}
544
545
			this.followMommy(level);
546
		}
547
	}
548
549
	protected void followMommy(final ServerLevel level) {
550
		if (this.isBred() && this.isBaby() && !this.isEating()) {
551
			LivingEntity mommy = level.getNearestEntity(
552
				AbstractHorse.class, MOMMY_TARGETING, this, this.getX(), this.getY(), this.getZ(), this.getBoundingBox().inflate(16.0)
553
			);
554
			if (mommy != null && this.distanceToSqr(mommy) > 4.0) {
555
				this.navigation.createPath(mommy, 0);
556
			}
557
		}
558
	}
559
560
	public boolean canEatGrass() {
561
		return true;
562
	}
563
564
	@Override
565
	public void tick() {
566
		super.tick();
567
		if (this.mouthCounter > 0 && ++this.mouthCounter > 30) {
568
			this.mouthCounter = 0;
569
			this.setFlag(64, false);
570
		}
571
572
		if (this.standCounter > 0 && --this.standCounter <= 0) {
573
			this.clearStanding();
574
		}
575
576
		if (this.tailCounter > 0 && ++this.tailCounter > 8) {
577
			this.tailCounter = 0;
578
		}
579
580
		if (this.sprintCounter > 0) {
581
			this.sprintCounter++;
582
			if (this.sprintCounter > 300) {
583
				this.sprintCounter = 0;
584
			}
585
		}
586
587
		this.eatAnimO = this.eatAnim;
588
		if (this.isEating()) {
589
			this.eatAnim = this.eatAnim + ((1.0F - this.eatAnim) * 0.4F + 0.05F);
590
			if (this.eatAnim > 1.0F) {
591
				this.eatAnim = 1.0F;
592
			}
593
		} else {
594
			this.eatAnim = this.eatAnim + ((0.0F - this.eatAnim) * 0.4F - 0.05F);
595
			if (this.eatAnim < 0.0F) {
596
				this.eatAnim = 0.0F;
597
			}
598
		}
599
600
		this.standAnimO = this.standAnim;
601
		if (this.isStanding()) {
602
			this.eatAnim = 0.0F;
603
			this.eatAnimO = this.eatAnim;
604
			this.standAnim = this.standAnim + ((1.0F - this.standAnim) * 0.4F + 0.05F);
605
			if (this.standAnim > 1.0F) {
606
				this.standAnim = 1.0F;
607
			}
608
		} else {
609
			this.allowStandSliding = false;
610
			this.standAnim = this.standAnim + ((0.8F * this.standAnim * this.standAnim * this.standAnim - this.standAnim) * 0.6F - 0.05F);
611
			if (this.standAnim < 0.0F) {
612
				this.standAnim = 0.0F;
613
			}
614
		}
615
616
		this.mouthAnimO = this.mouthAnim;
617
		if (this.getFlag(64)) {
618
			this.mouthAnim = this.mouthAnim + ((1.0F - this.mouthAnim) * 0.7F + 0.05F);
619
			if (this.mouthAnim > 1.0F) {
620
				this.mouthAnim = 1.0F;
621
			}
622
		} else {
623
			this.mouthAnim = this.mouthAnim + ((0.0F - this.mouthAnim) * 0.7F - 0.05F);
624
			if (this.mouthAnim < 0.0F) {
625
				this.mouthAnim = 0.0F;
626
			}
627
		}
628
	}
629
630
	@Override
631
	public InteractionResult mobInteract(final Player player, final InteractionHand hand) {
632
		if (this.isVehicle() || this.isBaby()) {
633
			return super.mobInteract(player, hand);
634
		}
635
636
		if (this.isTamed() && player.isSecondaryUseActive()) {
637
			this.openCustomInventoryScreen(player);
638
			return InteractionResult.SUCCESS;
639
		}
640
641
		ItemStack itemStack = player.getItemInHand(hand);
642
		if (!itemStack.isEmpty()) {
643
			InteractionResult interactionResult = itemStack.interactLivingEntity(player, this, hand);
644
			if (interactionResult.consumesAction()) {
645
				return interactionResult;
646
			}
647
648
			if (this.isEquippableInSlot(itemStack, EquipmentSlot.BODY) && !this.isWearingBodyArmor()) {
649
				this.equipBodyArmor(player, itemStack);
650
				return InteractionResult.SUCCESS;
651
			}
652
		}
653
654
		this.doPlayerRide(player);
655
		return InteractionResult.SUCCESS;
656
	}
657
658
	private void openMouth() {
659
		if (!this.level().isClientSide()) {
660
			this.mouthCounter = 1;
661
			this.setFlag(64, true);
662
		}
663
	}
664
665
	public void setEating(final boolean flag) {
666
		this.setFlag(16, flag);
667
	}
668
669
	public void setStanding(final int ticks) {
670
		this.setEating(false);
671
		this.setFlag(32, true);
672
		this.standCounter = ticks;
673
	}
674
675
	public void clearStanding() {
676
		this.setFlag(32, false);
677
		this.standCounter = 0;
678
	}
679
680
	public @Nullable SoundEvent getAmbientStandSound() {
681
		return this.getAmbientSound();
682
	}
683
684
	public void standIfPossible() {
685
		if (this.canPerformRearing() && (this.isEffectiveAi() || !this.level().isClientSide())) {
686
			this.setStanding(20);
687
		}
688
	}
689
690
	public void makeMad() {
691
		if (!this.isStanding() && !this.level().isClientSide()) {
692
			this.standIfPossible();
693
			this.makeSound(this.getAngrySound());
694
		}
695
	}
696
697
	public boolean tameWithName(final Player player) {
698
		this.setOwner(player);
699
		this.setTamed(true);
700
		if (player instanceof ServerPlayer serverPlayer) {
701
			CriteriaTriggers.TAME_ANIMAL.trigger(serverPlayer, this);
702
		}
703
704
		this.level().broadcastEntityEvent(this, (byte)7);
705
		return true;
706
	}
707
708
	@Override
709
	protected void tickRidden(final Player controller, final Vec3 riddenInput) {
710
		super.tickRidden(controller, riddenInput);
711
		Vec2 rotation = this.getRiddenRotation(controller);
712
		this.setRot(rotation.y, rotation.x);
713
		this.yRotO = this.yBodyRot = this.yHeadRot = this.getYRot();
714
		if (this.isLocalInstanceAuthoritative()) {
715
			if (riddenInput.z <= 0.0) {
716
				this.gallopSoundCounter = 0;
717
			}
718
719
			if (this.onGround()) {
720
				if (this.playerJumpPendingScale > 0.0F && !this.isJumping()) {
721
					this.executeRidersJump(this.playerJumpPendingScale, riddenInput);
722
				}
723
724
				this.playerJumpPendingScale = 0.0F;
725
			}
726
		}
727
	}
728
729
	protected Vec2 getRiddenRotation(final LivingEntity controller) {
730
		return new Vec2(controller.getXRot() * 0.5F, controller.getYRot());
731
	}
732
733
	@Override
734
	protected void addPassenger(final Entity passenger) {
735
		super.addPassenger(passenger);
736
		passenger.absSnapRotationTo(this.getViewYRot(0.0F), this.getViewXRot(0.0F));
737
	}
738
739
	@Override
740
	protected Vec3 getRiddenInput(final Player controller, final Vec3 selfInput) {
741
		if (this.onGround() && this.playerJumpPendingScale == 0.0F && this.isStanding() && !this.allowStandSliding) {
742
			return Vec3.ZERO;
743
		}
744
745
		float sideways = controller.xxa * 0.5F;
746
		float forward = controller.zza;
747
		if (forward <= 0.0F) {
748
			forward *= 0.25F;
749
		}
750
751
		return new Vec3(sideways, 0.0, forward);
752
	}
753
754
	@Override
755
	protected float getRiddenSpeed(final Player controller) {
756
		return (float)this.getAttributeValue(Attributes.MOVEMENT_SPEED);
757
	}
758
759
	protected void executeRidersJump(final float amount, final Vec3 input) {
760
		double impulse = this.getJumpPower(amount);
761
		Vec3 movement = this.getDeltaMovement();
762
		this.setDeltaMovement(movement.x, impulse, movement.z);
763
		this.needsSync = true;
764
		if (input.z > 0.0) {
765
			float sin = Mth.sin(this.getYRot() * (float) (Math.PI / 180.0));
766
			float cos = Mth.cos(this.getYRot() * (float) (Math.PI / 180.0));
767
			this.setDeltaMovement(this.getDeltaMovement().add(-0.4F * sin * amount, 0.0, 0.4F * cos * amount));
768
		}
769
	}
770
771
	protected void playJumpSound() {
772
		this.playSound(SoundEvents.HORSE_JUMP, 0.4F, 1.0F);
773
	}
774
775
	@Override
776
	protected void addAdditionalSaveData(final ValueOutput output) {
777
		super.addAdditionalSaveData(output);
778
		output.putBoolean("EatingHaystack", this.isEating());
779
		output.putBoolean("Bred", this.isBred());
780
		output.putInt("Temper", this.getTemper());
781
		output.putBoolean("Tame", this.isTamed());
782
		EntityReference.store(this.owner, output, "Owner");
783
	}
784
785
	@Override
786
	protected void readAdditionalSaveData(final ValueInput input) {
787
		super.readAdditionalSaveData(input);
788
		this.setEating(input.getBooleanOr("EatingHaystack", false));
789
		this.setBred(input.getBooleanOr("Bred", false));
790
		this.setTemper(input.getIntOr("Temper", 0));
791
		this.setTamed(input.getBooleanOr("Tame", false));
792
		this.owner = EntityReference.readWithOldOwnerConversion(input, "Owner", this.level());
793
	}
794
795
	@Override
796
	public boolean canMate(final Animal partner) {
797
		return false;
798
	}
799
800
	protected boolean canParent() {
801
		return !this.isVehicle() && !this.isPassenger() && this.isTamed() && !this.isBaby() && this.getHealth() >= this.getMaxHealth() && this.isInLove();
802
	}
803
804
	public boolean isMobControlled() {
805
		return false;
806
	}
807
808
	@Override
809
	public @Nullable AgeableMob getBreedOffspring(final ServerLevel level, final AgeableMob partner) {
810
		return null;
811
	}
812
813
	protected void setOffspringAttributes(final AgeableMob partner, final AbstractHorse baby) {
814
		this.setOffspringAttribute(partner, baby, Attributes.MAX_HEALTH, MIN_HEALTH, MAX_HEALTH);
815
		this.setOffspringAttribute(partner, baby, Attributes.JUMP_STRENGTH, MIN_JUMP_STRENGTH, MAX_JUMP_STRENGTH);
816
		this.setOffspringAttribute(partner, baby, Attributes.MOVEMENT_SPEED, MIN_MOVEMENT_SPEED, MAX_MOVEMENT_SPEED);
817
	}
818
819
	private void setOffspringAttribute(
820
		final AgeableMob partner, final AbstractHorse baby, final Holder<Attribute> attribute, final double attributeRangeMin, final double attributeRangeMax
821
	) {
822
		double newValue = createOffspringAttribute(
823
			this.getAttributeBaseValue(attribute), partner.getAttributeBaseValue(attribute), attributeRangeMin, attributeRangeMax, this.random
824
		);
825
		baby.getAttribute(attribute).setBaseValue(newValue);
826
	}
827
828
	public static double createOffspringAttribute(
829
		double parentAValue, double parentBValue, final double attributeRangeMin, final double attributeRangeMax, final RandomSource random
830
	) {
831
		if (attributeRangeMax <= attributeRangeMin) {
832
			throw new IllegalArgumentException("Incorrect range for an attribute");
833
		} else {
834
			parentAValue = Mth.clamp(parentAValue, attributeRangeMin, attributeRangeMax);
835
			parentBValue = Mth.clamp(parentBValue, attributeRangeMin, attributeRangeMax);
836
			double margin = 0.15 * (attributeRangeMax - attributeRangeMin);
837
			double range = Math.abs(parentAValue - parentBValue) + margin * 2.0;
838
			double average = (parentAValue + parentBValue) / 2.0;
839
			double babyQuality = (random.nextDouble() + random.nextDouble() + random.nextDouble()) / 3.0 - 0.5;
840
			double newValue = average + range * babyQuality;
841
			if (newValue > attributeRangeMax) {
842
				double difference = newValue - attributeRangeMax;
843
				return attributeRangeMax - difference;
844
			} else if (newValue < attributeRangeMin) {
845
				double difference = attributeRangeMin - newValue;
846
				return attributeRangeMin + difference;
847
			} else {
848
				return newValue;
849
			}
850
		}
851
	}
852
853
	public float getEatAnim(final float a) {
854
		return Mth.lerp(a, this.eatAnimO, this.eatAnim);
855
	}
856
857
	public float getStandAnim(final float a) {
858
		return Mth.lerp(a, this.standAnimO, this.standAnim);
859
	}
860
861
	public float getMouthAnim(final float a) {
862
		return Mth.lerp(a, this.mouthAnimO, this.mouthAnim);
863
	}
864
865
	@Override
866
	public void onPlayerJump(int jumpAmount) {
867
		if (this.isSaddled()) {
868
			if (jumpAmount < 0) {
869
				jumpAmount = 0;
870
			} else {
871
				this.allowStandSliding = true;
872
				this.standIfPossible();
873
			}
874
875
			this.playerJumpPendingScale = this.getPlayerJumpPendingScale(jumpAmount);
876
		}
877
	}
878
879
	@Override
880
	public boolean canJump() {
881
		return this.isSaddled();
882
	}
883
884
	@Override
885
	public void handleStartJump(final int jumpScale) {
886
		this.allowStandSliding = true;
887
		this.standIfPossible();
888
		this.playJumpSound();
889
	}
890
891
	@Override
892
	public void handleStopJump() {
893
	}
894
895
	protected void spawnTamingParticles(final boolean success) {
896
		ParticleOptions particle = success ? ParticleTypes.HEART : ParticleTypes.SMOKE;
897
898
		for (int i = 0; i < 7; i++) {
899
			double xa = this.random.nextGaussian() * 0.02;
900
			double ya = this.random.nextGaussian() * 0.02;
901
			double za = this.random.nextGaussian() * 0.02;
902
			this.level().addParticle(particle, this.getRandomX(1.0), this.getRandomY() + 0.5, this.getRandomZ(1.0), xa, ya, za);
903
		}
904
	}
905
906
	@Override
907
	public void handleEntityEvent(final @EntityEvent.Value byte id) {
908
		if (id == 7) {
909
			this.spawnTamingParticles(true);
910
		} else if (id == 6) {
911
			this.spawnTamingParticles(false);
912
		} else {
913
			super.handleEntityEvent(id);
914
		}
915
	}
916
917
	@Override
918
	protected void positionRider(final Entity passenger, final Entity.MoveFunction moveFunction) {
919
		super.positionRider(passenger, moveFunction);
920
		if (passenger instanceof LivingEntity livingEntity) {
921
			livingEntity.yBodyRot = this.yBodyRot;
922
		}
923
	}
924
925
	protected static float generateMaxHealth(final IntUnaryOperator integerByBoundProvider) {
926
		return 15.0F + integerByBoundProvider.applyAsInt(8) + integerByBoundProvider.applyAsInt(9);
927
	}
928
929
	protected static double generateJumpStrength(final DoubleSupplier probabilityProvider) {
930
		return 0.4F + probabilityProvider.getAsDouble() * 0.2 + probabilityProvider.getAsDouble() * 0.2 + probabilityProvider.getAsDouble() * 0.2;
931
	}
932
933
	protected static double generateSpeed(final DoubleSupplier probabilityProvider) {
934
		return (0.45F + probabilityProvider.getAsDouble() * 0.3 + probabilityProvider.getAsDouble() * 0.3 + probabilityProvider.getAsDouble() * 0.3) * 0.25;
935
	}
936
937
	@Override
938
	public boolean onClimbable() {
939
		return false;
940
	}
941
942
	@Override
943
	public @Nullable SlotAccess getSlot(final int slot) {
944
		int inventorySlot = slot - 500;
945
		return inventorySlot >= 0 && inventorySlot < this.inventory.getContainerSize() ? this.inventory.getSlot(inventorySlot) : super.getSlot(slot);
946
	}
947
948
	@Override
949
	public @Nullable LivingEntity getControllingPassenger() {
950
		return this.isSaddled() && this.getFirstPassenger() instanceof Player passenger ? passenger : super.getControllingPassenger();
951
	}
952
953
	private @Nullable Vec3 getDismountLocationInDirection(final Vec3 direction, final LivingEntity passenger) {
954
		double targetX = this.getX() + direction.x;
955
		double targetY = this.getBoundingBox().minY;
956
		double targetZ = this.getZ() + direction.z;
957
		BlockPos.MutableBlockPos targetBlockPos = new BlockPos.MutableBlockPos();
958
959
		for (Pose dismountPose : passenger.getDismountPoses()) {
960
			targetBlockPos.set(targetX, targetY, targetZ);
961
			double dismountJumpLimit = this.getBoundingBox().maxY + 0.75;
962
963
			do {
964
				double blockFloorHeight = this.level().getBlockFloorHeight(targetBlockPos);
965
				if (targetBlockPos.getY() + blockFloorHeight > dismountJumpLimit) {
966
					break;
967
				}
968
969
				if (DismountHelper.isBlockFloorValid(blockFloorHeight)) {
970
					AABB poseCollisionBox = passenger.getLocalBoundsForPose(dismountPose);
971
					Vec3 location = new Vec3(targetX, targetBlockPos.getY() + blockFloorHeight, targetZ);
972
					if (DismountHelper.canDismountTo(this.level(), passenger, poseCollisionBox.move(location))) {
973
						passenger.setPose(dismountPose);
974
						return location;
975
					}
976
				}
977
978
				targetBlockPos.move(Direction.UP);
979
			} while (targetBlockPos.getY() < dismountJumpLimit);
980
		}
981
982
		return null;
983
	}
984
985
	@Override
986
	public Vec3 getDismountLocationForPassenger(final LivingEntity passenger) {
987
		Vec3 mainHandDirection = getCollisionHorizontalEscapeVector(
988
			this.getBbWidth(), passenger.getBbWidth(), this.getYRot() + (passenger.getMainArm() == HumanoidArm.RIGHT ? 90.0F : -90.0F)
989
		);
990
		Vec3 mainHandLocation = this.getDismountLocationInDirection(mainHandDirection, passenger);
991
		if (mainHandLocation != null) {
992
			return mainHandLocation;
993
		}
994
995
		Vec3 offHandDirection = getCollisionHorizontalEscapeVector(
996
			this.getBbWidth(), passenger.getBbWidth(), this.getYRot() + (passenger.getMainArm() == HumanoidArm.LEFT ? 90.0F : -90.0F)
997
		);
998
		Vec3 offHandLocation = this.getDismountLocationInDirection(offHandDirection, passenger);
999
		return offHandLocation != null ? offHandLocation : this.position();
1000
	}
1001
1002
	protected void randomizeAttributes(final RandomSource random) {
1003
	}
1004
1005
	@Override
1006
	public @Nullable SpawnGroupData finalizeSpawn(
1007
		final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, @Nullable SpawnGroupData groupData
1008
	) {
1009
		if (groupData == null) {
1010
			groupData = new AgeableMob.AgeableMobGroupData(0.2F);
1011
		}
1012
1013
		this.randomizeAttributes(level.getRandom());
1014
		return super.finalizeSpawn(level, difficulty, spawnReason, groupData);
1015
	}
1016
1017
	public boolean hasInventoryChanged(final Container oldInventory) {
1018
		return this.inventory != oldInventory;
1019
	}
1020
1021
	public int getAmbientStandInterval() {
1022
		return this.getAmbientSoundInterval();
1023
	}
1024
1025
	@Override
1026
	protected Vec3 getPassengerAttachmentPoint(final Entity passenger, final EntityDimensions dimensions, final float scale) {
1027
		return super.getPassengerAttachmentPoint(passenger, dimensions, scale)
1028
			.add(new Vec3(0.0, 0.15 * this.standAnimO * scale, -0.7 * this.standAnimO * scale).yRot(-this.getYRot() * (float) (Math.PI / 180.0)));
1029
	}
1030
1031
	public int getInventoryColumns() {
1032
		return 0;
1033
	}
1034
1035
	private class MountPanicGoal extends PanicGoal {
1036
		public MountPanicGoal(final double speedModifier) {
1037
			super(AbstractHorse.this, speedModifier);
1038
		}
1039
1040
		@Override
1041
		public boolean shouldPanic() {
1042
			return !AbstractHorse.this.isMobControlled() && super.shouldPanic();
1043
		}
1044
	}
1045
}
1046

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