TradeWithPlayerGoal .java

net.minecraft.world.entity.ai.goal.TradeWithPlayerGoal (class, 47 lines): members: mob, canUse, stop, start. imports: AbstractVillager, Player.

net.minecraft.world.entity.ai.goalclass47 linescommonextends Goal937 B

API Surface (3)

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

Fields & Constants (1)

mob

Code Graph: Dependencies (3)

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

Full Source

TradeWithPlayerGoal.java47 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.npc.villager.AbstractVillager;
5
import net.minecraft.world.entity.player.Player;
6
7
public class TradeWithPlayerGoal extends Goal {
8
	private final AbstractVillager mob;
9
10
	public TradeWithPlayerGoal(final AbstractVillager mob) {
11
		this.mob = mob;
12
		this.setFlags(EnumSet.of(Goal.Flag.JUMP, Goal.Flag.MOVE));
13
	}
14
15
	@Override
16
	public boolean canUse() {
17
		if (!this.mob.isAlive()) {
18
			return false;
19
		}
20
21
		if (this.mob.isInWater()) {
22
			return false;
23
		}
24
25
		if (!this.mob.onGround()) {
26
			return false;
27
		}
28
29
		if (this.mob.wasHurtRecently()) {
30
			return false;
31
		}
32
33
		Player trader = this.mob.getTradingPlayer();
34
		return trader == null ? false : !(this.mob.distanceToSqr(trader) > 16.0);
35
	}
36
37
	@Override
38
	public void start() {
39
		this.mob.getNavigation().stop();
40
	}
41
42
	@Override
43
	public void stop() {
44
		this.mob.setTradingPlayer(null);
45
	}
46
}
47

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