LeapAtTargetGoal .java

net.minecraft.world.entity.ai.goal.LeapAtTargetGoal (class, 54 lines): members: yd, canContinueToUse, target, mob, canUse, start. imports: Mob.

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

API Surface (3)

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

Fields & Constants (3)

mob
target
yd

Code Graph: Dependencies (4)

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

Full Source

LeapAtTargetGoal.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.Mob;
6
import net.minecraft.world.phys.Vec3;
7
8
public class LeapAtTargetGoal extends Goal {
9
	private final Mob mob;
10
	private LivingEntity target;
11
	private final float yd;
12
13
	public LeapAtTargetGoal(final Mob mob, final float yd) {
14
		this.mob = mob;
15
		this.yd = yd;
16
		this.setFlags(EnumSet.of(Goal.Flag.JUMP, Goal.Flag.MOVE));
17
	}
18
19
	@Override
20
	public boolean canUse() {
21
		if (this.mob.hasControllingPassenger()) {
22
			return false;
23
		} else {
24
			this.target = this.mob.getTarget();
25
			if (this.target == null) {
26
				return false;
27
			} else {
28
				double d = this.mob.distanceToSqr(this.target);
29
				if (d < 4.0 || d > 16.0) {
30
					return false;
31
				} else {
32
					return !this.mob.onGround() ? false : this.mob.getRandom().nextInt(reducedTickDelay(5)) == 0;
33
				}
34
			}
35
		}
36
	}
37
38
	@Override
39
	public boolean canContinueToUse() {
40
		return !this.mob.onGround();
41
	}
42
43
	@Override
44
	public void start() {
45
		Vec3 movement = this.mob.getDeltaMovement();
46
		Vec3 delta = new Vec3(this.target.getX() - this.mob.getX(), 0.0, this.target.getZ() - this.mob.getZ());
47
		if (delta.lengthSqr() > 1.0E-7) {
48
			delta = delta.normalize().scale(0.4).add(movement.scale(0.2));
49
		}
50
51
		this.mob.setDeltaMovement(delta.x, this.yd, delta.z);
52
	}
53
}
54

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