StartHuntingHoglin .java

net.minecraft.world.entity.monster.piglin.StartHuntingHoglin (class): members: create. imports: OneShot, Hoglin, BehaviorBuilder, MemoryModuleType.

net.minecraft.world.entity.monster.piglinclass37 linescommon1.4 KB

API Surface (1)

OneShot<Piglin> create()

Code Graph: Dependencies (7)

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

Full Source

StartHuntingHoglin.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.monster.piglin;
2
3
import java.util.List;
4
import net.minecraft.world.entity.ai.behavior.OneShot;
5
import net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder;
6
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
7
import net.minecraft.world.entity.monster.hoglin.Hoglin;
8
9
public class StartHuntingHoglin {
10
	public static OneShot<Piglin> create() {
11
		return BehaviorBuilder.create(
12
			i -> i.group(
13
					i.present(MemoryModuleType.NEAREST_VISIBLE_HUNTABLE_HOGLIN),
14
					i.absent(MemoryModuleType.ANGRY_AT),
15
					i.absent(MemoryModuleType.HUNTED_RECENTLY),
16
					i.registered(MemoryModuleType.NEAREST_VISIBLE_ADULT_PIGLINS)
17
				)
18
				.apply(i, (huntable, angryAt, huntedRecently, nearestPiglins) -> (level, body, timestamp) -> {
19
					if (!body.isBaby() && !i.<List>tryGet(nearestPiglins).filter(p -> p.stream().anyMatch(StartHuntingHoglin::hasHuntedRecently)).isPresent()) {
20
						Hoglin target = i.get(huntable);
21
						PiglinAi.setAngerTarget(level, body, target);
22
						PiglinAi.dontKillAnyMoreHoglinsForAWhile(body);
23
						PiglinAi.broadcastAngerTarget(level, body, target);
24
						i.<List>tryGet(nearestPiglins).ifPresent(p -> p.forEach(PiglinAi::dontKillAnyMoreHoglinsForAWhile));
25
						return true;
26
					} else {
27
						return false;
28
					}
29
				})
30
		);
31
	}
32
33
	private static boolean hasHuntedRecently(final AbstractPiglin otherPiglin) {
34
		return otherPiglin.getBrain().hasMemoryValue(MemoryModuleType.HUNTED_RECENTLY);
35
	}
36
}
37

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