RunAroundLikeCrazyGoal .java

net.minecraft.world.entity.ai.goal.RunAroundLikeCrazyGoal (class): members: posX, posY, posZ, horse, speedModifier, canContinueToUse, canUse, start, tick.

net.minecraft.world.entity.ai.goalclass75 linescommonextends Goal2.0 KB

API Surface (4)

boolean canUse()
void start()
boolean canContinueToUse()
void tick()

Fields & Constants (5)

horse
speedModifier
posX
posY
posZ

Code Graph: Dependencies (6)

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

Full Source

RunAroundLikeCrazyGoal.java75 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.goal;
2
3
import java.util.EnumSet;
4
import net.minecraft.world.entity.Entity;
5
import net.minecraft.world.entity.ai.util.DefaultRandomPos;
6
import net.minecraft.world.entity.animal.equine.AbstractHorse;
7
import net.minecraft.world.entity.player.Player;
8
import net.minecraft.world.phys.Vec3;
9
10
public class RunAroundLikeCrazyGoal extends Goal {
11
	private final AbstractHorse horse;
12
	private final double speedModifier;
13
	private double posX;
14
	private double posY;
15
	private double posZ;
16
17
	public RunAroundLikeCrazyGoal(final AbstractHorse mob, final double speedModifier) {
18
		this.horse = mob;
19
		this.speedModifier = speedModifier;
20
		this.setFlags(EnumSet.of(Goal.Flag.MOVE));
21
	}
22
23
	@Override
24
	public boolean canUse() {
25
		if (!this.horse.isMobControlled() && !this.horse.isTamed() && this.horse.isVehicle()) {
26
			Vec3 pos = DefaultRandomPos.getPos(this.horse, 5, 4);
27
			if (pos == null) {
28
				return false;
29
			}
30
31
			this.posX = pos.x;
32
			this.posY = pos.y;
33
			this.posZ = pos.z;
34
			return true;
35
		} else {
36
			return false;
37
		}
38
	}
39
40
	@Override
41
	public void start() {
42
		this.horse.getNavigation().moveTo(this.posX, this.posY, this.posZ, this.speedModifier);
43
	}
44
45
	@Override
46
	public boolean canContinueToUse() {
47
		return !this.horse.isTamed() && !this.horse.getNavigation().isDone() && this.horse.isVehicle();
48
	}
49
50
	@Override
51
	public void tick() {
52
		if (!this.horse.isTamed() && this.horse.getRandom().nextInt(this.adjustedTickDelay(50)) == 0) {
53
			Entity passenger = this.horse.getFirstPassenger();
54
			if (passenger == null) {
55
				return;
56
			}
57
58
			if (passenger instanceof Player player) {
59
				int temper = this.horse.getTemper();
60
				int maxTemper = this.horse.getMaxTemper();
61
				if (maxTemper > 0 && this.horse.getRandom().nextInt(maxTemper) < temper) {
62
					this.horse.tameWithName(player);
63
					return;
64
				}
65
66
				this.horse.modifyTemper(5);
67
			}
68
69
			this.horse.ejectPassengers();
70
			this.horse.makeMad();
71
			this.horse.level().broadcastEntityEvent(this.horse, (byte)6);
72
		}
73
	}
74
}
75

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