RandomLookAroundGoal .java

net.minecraft.world.entity.ai.goal.RandomLookAroundGoal (class): members: relX, relZ, lookTime, requiresUpdateEveryTick, canContinueToUse, mob, canUse.

net.minecraft.world.entity.ai.goalclass46 linescommonextends Goal1022 B

API Surface (5)

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

Fields & Constants (4)

mob
relX
relZ
lookTime

Code Graph: Dependencies (2)

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

Full Source

RandomLookAroundGoal.java46 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.Mob;
5
6
public class RandomLookAroundGoal extends Goal {
7
	private final Mob mob;
8
	private double relX;
9
	private double relZ;
10
	private int lookTime;
11
12
	public RandomLookAroundGoal(final Mob mob) {
13
		this.mob = mob;
14
		this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK));
15
	}
16
17
	@Override
18
	public boolean canUse() {
19
		return this.mob.getRandom().nextFloat() < 0.02F;
20
	}
21
22
	@Override
23
	public boolean canContinueToUse() {
24
		return this.lookTime >= 0;
25
	}
26
27
	@Override
28
	public void start() {
29
		double rnd = (Math.PI * 2) * this.mob.getRandom().nextDouble();
30
		this.relX = Math.cos(rnd);
31
		this.relZ = Math.sin(rnd);
32
		this.lookTime = 20 + this.mob.getRandom().nextInt(20);
33
	}
34
35
	@Override
36
	public boolean requiresUpdateEveryTick() {
37
		return true;
38
	}
39
40
	@Override
41
	public void tick() {
42
		this.lookTime--;
43
		this.mob.getLookControl().setLookAt(this.mob.getX() + this.relX, this.mob.getEyeY(), this.mob.getZ() + this.relZ);
44
	}
45
}
46

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