PathfindToRaidGoal .java

net.minecraft.world.entity.ai.goal.PathfindToRaidGoal (class, 72 lines): extends Goal. members: RECRUITMENT_SEARCH_TICK_DELAY, recruitmentTick, mob, tick.

net.minecraft.world.entity.ai.goalclass72 linescommonextends Raider>2.3 KB

API Surface (3)

boolean canUse()
boolean canContinueToUse()
void tick()

Fields & Constants (4)

RECRUITMENT_SEARCH_TICK_DELAY
SPEED_MODIFIER
mob
recruitmentTick

Code Graph: Dependencies (7)

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

Full Source

PathfindToRaidGoal.java72 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.goal;
2
3
import com.google.common.collect.Sets;
4
import java.util.EnumSet;
5
import java.util.List;
6
import java.util.Set;
7
import net.minecraft.server.level.ServerLevel;
8
import net.minecraft.world.entity.ai.util.DefaultRandomPos;
9
import net.minecraft.world.entity.raid.Raid;
10
import net.minecraft.world.entity.raid.Raider;
11
import net.minecraft.world.entity.raid.Raids;
12
import net.minecraft.world.phys.Vec3;
13
14
public class PathfindToRaidGoal<T extends Raider> extends Goal {
15
	private static final int RECRUITMENT_SEARCH_TICK_DELAY = 20;
16
	private static final float SPEED_MODIFIER = 1.0F;
17
	private final T mob;
18
	private int recruitmentTick;
19
20
	public PathfindToRaidGoal(final T mob) {
21
		this.mob = mob;
22
		this.setFlags(EnumSet.of(Goal.Flag.MOVE));
23
	}
24
25
	@Override
26
	public boolean canUse() {
27
		return this.mob.getTarget() == null
28
			&& !this.mob.hasControllingPassenger()
29
			&& this.mob.hasActiveRaid()
30
			&& !this.mob.getCurrentRaid().isOver()
31
			&& !getServerLevel(this.mob.level()).isVillage(this.mob.blockPosition());
32
	}
33
34
	@Override
35
	public boolean canContinueToUse() {
36
		return this.mob.hasActiveRaid() && !this.mob.getCurrentRaid().isOver() && !getServerLevel(this.mob.level()).isVillage(this.mob.blockPosition());
37
	}
38
39
	@Override
40
	public void tick() {
41
		if (this.mob.hasActiveRaid()) {
42
			Raid raid = this.mob.getCurrentRaid();
43
			if (this.mob.tickCount > this.recruitmentTick) {
44
				this.recruitmentTick = this.mob.tickCount + 20;
45
				this.recruitNearby(raid);
46
			}
47
48
			if (!this.mob.isPathFinding()) {
49
				Vec3 posTowards = DefaultRandomPos.getPosTowards(this.mob, 15, 4, Vec3.atBottomCenterOf(raid.getCenter()), (float) (Math.PI / 2));
50
				if (posTowards != null) {
51
					this.mob.getNavigation().moveTo(posTowards.x, posTowards.y, posTowards.z, 1.0);
52
				}
53
			}
54
		}
55
	}
56
57
	private void recruitNearby(final Raid raid) {
58
		if (raid.isActive()) {
59
			ServerLevel level = getServerLevel(this.mob.level());
60
			Set<Raider> raidersToAdd = Sets.newHashSet();
61
			List<Raider> raidersNearby = level.getEntitiesOfClass(
62
				Raider.class, this.mob.getBoundingBox().inflate(16.0), mob -> !mob.hasActiveRaid() && Raids.canJoinRaid(mob)
63
			);
64
			raidersToAdd.addAll(raidersNearby);
65
66
			for (Raider raider : raidersToAdd) {
67
				raid.joinRaid(level, raid.getGroupsSpawned(), raider, null, true);
68
			}
69
		}
70
	}
71
}
72

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