OcelotAttackGoal .java

net.minecraft.world.entity.ai.goal.OcelotAttackGoal (class): members: attackTime, requiresUpdateEveryTick, canContinueToUse, target, mob, canUse, stop.

net.minecraft.world.entity.ai.goalclass70 linescommonextends Goal1.7 KB

API Surface (5)

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

Fields & Constants (3)

mob
target
attackTime

Code Graph: Dependencies (3)

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

Full Source

OcelotAttackGoal.java70 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
7
public class OcelotAttackGoal extends Goal {
8
	private final Mob mob;
9
	private LivingEntity target;
10
	private int attackTime;
11
12
	public OcelotAttackGoal(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
		LivingEntity bestTarget = this.mob.getTarget();
20
		if (bestTarget == null) {
21
			return false;
22
		}
23
24
		this.target = bestTarget;
25
		return true;
26
	}
27
28
	@Override
29
	public boolean canContinueToUse() {
30
		if (!this.target.isAlive()) {
31
			return false;
32
		} else {
33
			return this.mob.distanceToSqr(this.target) > 225.0 ? false : !this.mob.getNavigation().isDone() || this.canUse();
34
		}
35
	}
36
37
	@Override
38
	public void stop() {
39
		this.target = null;
40
		this.mob.getNavigation().stop();
41
	}
42
43
	@Override
44
	public boolean requiresUpdateEveryTick() {
45
		return true;
46
	}
47
48
	@Override
49
	public void tick() {
50
		this.mob.getLookControl().setLookAt(this.target, 30.0F, 30.0F);
51
		double meleeRadiusSqr = this.mob.getBbWidth() * 2.0F * (this.mob.getBbWidth() * 2.0F);
52
		double distSqr = this.mob.distanceToSqr(this.target.getX(), this.target.getY(), this.target.getZ());
53
		double speedModifier = 0.8;
54
		if (distSqr > meleeRadiusSqr && distSqr < 16.0) {
55
			speedModifier = 1.33;
56
		} else if (distSqr < 225.0) {
57
			speedModifier = 0.6;
58
		}
59
60
		this.mob.getNavigation().moveTo(this.target, speedModifier);
61
		this.attackTime = Math.max(this.attackTime - 1, 0);
62
		if (!(distSqr > meleeRadiusSqr)) {
63
			if (this.attackTime <= 0) {
64
				this.attackTime = 20;
65
				this.mob.doHurtTarget(getServerLevel(this.mob), this.target);
66
			}
67
		}
68
	}
69
}
70

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