EntityTracker .java

net.minecraft.world.entity.ai.behavior.EntityTracker (class): members: targetEyeHeight, trackEyeHeight, currentBlockPosition, currentPosition, isVisibleBy.

net.minecraft.world.entity.ai.behaviorclass59 linescommon1.8 KB

Implements

API Surface (5)

Vec3 currentPosition()
BlockPos currentBlockPosition()
boolean isVisibleBy(final LivingEntity body)
Entity getEntity()
String toString()

Fields & Constants (3)

entity
trackEyeHeight
targetEyeHeight

String literals (1)

"EntityTracker for "

Full Source

EntityTracker.java59 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.behavior;
2
3
import java.util.Optional;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.world.entity.Entity;
6
import net.minecraft.world.entity.LivingEntity;
7
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
8
import net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities;
9
import net.minecraft.world.phys.Vec3;
10
11
public class EntityTracker implements PositionTracker {
12
	private final Entity entity;
13
	private final boolean trackEyeHeight;
14
	private final boolean targetEyeHeight;
15
16
	public EntityTracker(final Entity entity, final boolean trackEyeHeight) {
17
		this(entity, trackEyeHeight, false);
18
	}
19
20
	public EntityTracker(final Entity entity, final boolean trackEyeHeight, final boolean targetEyeHeight) {
21
		this.entity = entity;
22
		this.trackEyeHeight = trackEyeHeight;
23
		this.targetEyeHeight = targetEyeHeight;
24
	}
25
26
	@Override
27
	public Vec3 currentPosition() {
28
		return this.trackEyeHeight ? this.entity.position().add(0.0, this.entity.getEyeHeight(), 0.0) : this.entity.position();
29
	}
30
31
	@Override
32
	public BlockPos currentBlockPosition() {
33
		return this.targetEyeHeight ? BlockPos.containing(this.entity.getEyePosition()) : this.entity.blockPosition();
34
	}
35
36
	@Override
37
	public boolean isVisibleBy(final LivingEntity body) {
38
		if (this.entity instanceof LivingEntity livingEntity) {
39
			if (!livingEntity.isAlive()) {
40
				return false;
41
			}
42
43
			Optional<NearestVisibleLivingEntities> visibleEntities = body.getBrain().getMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES);
44
			return visibleEntities.isPresent() && visibleEntities.get().contains(livingEntity);
45
		} else {
46
			return true;
47
		}
48
	}
49
50
	public Entity getEntity() {
51
		return this.entity;
52
	}
53
54
	@Override
55
	public String toString() {
56
		return "EntityTracker for " + this.entity;
57
	}
58
}
59

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