RestrictSunGoal .java

net.minecraft.world.entity.ai.goal.RestrictSunGoal (class): members: mob, canUse, stop, start. imports: GoalUtils, GroundPathNavigation, PathfinderMob.

net.minecraft.world.entity.ai.goalclass34 linescommonextends Goal977 B

API Surface (3)

boolean canUse()
void start()
void stop()

Fields & Constants (1)

mob

Code Graph: Dependencies (5)

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

Full Source

RestrictSunGoal.java34 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.goal;
2
3
import net.minecraft.world.entity.EquipmentSlot;
4
import net.minecraft.world.entity.PathfinderMob;
5
import net.minecraft.world.entity.ai.navigation.GroundPathNavigation;
6
import net.minecraft.world.entity.ai.util.GoalUtils;
7
8
public class RestrictSunGoal extends Goal {
9
	private final PathfinderMob mob;
10
11
	public RestrictSunGoal(final PathfinderMob mob) {
12
		this.mob = mob;
13
	}
14
15
	@Override
16
	public boolean canUse() {
17
		return this.mob.level().isBrightOutside() && this.mob.getItemBySlot(EquipmentSlot.HEAD).isEmpty() && GoalUtils.hasGroundPathNavigation(this.mob);
18
	}
19
20
	@Override
21
	public void start() {
22
		if (this.mob.getNavigation() instanceof GroundPathNavigation pathNavigation) {
23
			pathNavigation.setAvoidSun(true);
24
		}
25
	}
26
27
	@Override
28
	public void stop() {
29
		if (GoalUtils.hasGroundPathNavigation(this.mob) && this.mob.getNavigation() instanceof GroundPathNavigation pathNavigation) {
30
			pathNavigation.setAvoidSun(false);
31
		}
32
	}
33
}
34

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