SwellGoal .java

net.minecraft.world.entity.ai.goal.SwellGoal (class): members: creeper, requiresUpdateEveryTick, target, canUse, stop, start, tick. imports: Creeper.

net.minecraft.world.entity.ai.goalclass54 linescommonextends Goal1.3 KB

API Surface (5)

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

Fields & Constants (2)

creeper
target

Code Graph: Dependencies (3)

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

Full Source

SwellGoal.java54 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.LivingEntity;
5
import net.minecraft.world.entity.monster.Creeper;
6
import org.jspecify.annotations.Nullable;
7
8
public class SwellGoal extends Goal {
9
	private final Creeper creeper;
10
	private @Nullable LivingEntity target;
11
12
	public SwellGoal(final Creeper creeper) {
13
		this.creeper = creeper;
14
		this.setFlags(EnumSet.of(Goal.Flag.MOVE));
15
	}
16
17
	@Override
18
	public boolean canUse() {
19
		LivingEntity target = this.creeper.getTarget();
20
		return this.creeper.getSwellDir() > 0 || target != null && !target.isDeadOrDying() && this.creeper.distanceToSqr(target) < 9.0;
21
	}
22
23
	@Override
24
	public void start() {
25
		this.creeper.getNavigation().stop();
26
		this.target = this.creeper.getTarget();
27
	}
28
29
	@Override
30
	public void stop() {
31
		this.target = null;
32
	}
33
34
	@Override
35
	public boolean requiresUpdateEveryTick() {
36
		return true;
37
	}
38
39
	@Override
40
	public void tick() {
41
		if (this.target != null && !this.target.isDeadOrDying()) {
42
			if (this.creeper.distanceToSqr(this.target) > 49.0) {
43
				this.creeper.setSwellDir(-1);
44
			} else if (!this.creeper.getSensing().hasLineOfSight(this.target)) {
45
				this.creeper.setSwellDir(-1);
46
			} else {
47
				this.creeper.setSwellDir(1);
48
			}
49
		} else {
50
			this.creeper.setSwellDir(-1);
51
		}
52
	}
53
}
54

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