GolemSensor .java

net.minecraft.world.entity.ai.sensing.GolemSensor (class): members: MEMORY_TIME_TO_LIVE, checkForNearbyGolem, GOLEM_SCAN_RATE, golemDetected, doTick.

net.minecraft.world.entity.ai.sensingclass47 linescommonextends Sensor<LivingEntity>1.4 KB

API Surface (4)

void doTick(final ServerLevel level, final LivingEntity body)
Set<MemoryModuleType<?>> requires()
void checkForNearbyGolem(final LivingEntity body)
void golemDetected(final LivingEntity body)

Fields & Constants (2)

GOLEM_SCAN_RATE
MEMORY_TIME_TO_LIVE

Code Graph: Dependencies (5)

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

Full Source

GolemSensor.java47 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.sensing;
2
3
import java.util.List;
4
import java.util.Optional;
5
import java.util.Set;
6
import net.minecraft.server.level.ServerLevel;
7
import net.minecraft.world.entity.EntityTypes;
8
import net.minecraft.world.entity.LivingEntity;
9
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
10
11
public class GolemSensor extends Sensor<LivingEntity> {
12
	private static final int GOLEM_SCAN_RATE = 200;
13
	private static final int MEMORY_TIME_TO_LIVE = 599;
14
15
	public GolemSensor() {
16
		this(200);
17
	}
18
19
	public GolemSensor(final int scanRate) {
20
		super(scanRate);
21
	}
22
23
	@Override
24
	protected void doTick(final ServerLevel level, final LivingEntity body) {
25
		checkForNearbyGolem(body);
26
	}
27
28
	@Override
29
	public Set<MemoryModuleType<?>> requires() {
30
		return Set.of(MemoryModuleType.NEAREST_LIVING_ENTITIES, MemoryModuleType.GOLEM_DETECTED_RECENTLY);
31
	}
32
33
	public static void checkForNearbyGolem(final LivingEntity body) {
34
		Optional<List<LivingEntity>> livingEntitiesMemory = body.getBrain().getMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES);
35
		if (!livingEntitiesMemory.isEmpty()) {
36
			boolean golemPresent = livingEntitiesMemory.get().stream().anyMatch(entity -> entity.is(EntityTypes.IRON_GOLEM));
37
			if (golemPresent) {
38
				golemDetected(body);
39
			}
40
		}
41
	}
42
43
	public static void golemDetected(final LivingEntity body) {
44
		body.getBrain().setMemoryWithExpiry(MemoryModuleType.GOLEM_DETECTED_RECENTLY, true, 599L);
45
	}
46
}
47

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