BabyFollowAdult .java

net.minecraft.world.entity.ai.behavior.BabyFollowAdult (class): members: nearestVisibleType, followRange, speedModifier, create. imports: WalkTarget.

net.minecraft.world.entity.ai.behaviorclass41 linescommon1.6 KB

API Surface (2)

OneShot<LivingEntity> create(final UniformInt followRange, final float speedModifier)
OneShot<LivingEntity> create(final UniformInt followRange, final Function<LivingEntity, Float> speedModifier, final MemoryModuleType<? extends LivingEntity> nearestVisibleType, final boolean targetEye)

Fields & Constants (3)

followRange
speedModifier
nearestVisibleType

Code Graph: Dependencies (6)

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

Full Source

BabyFollowAdult.java41 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.entity.ai.behavior;
2
3
import java.util.function.Function;
4
import net.minecraft.util.valueproviders.UniformInt;
5
import net.minecraft.world.entity.LivingEntity;
6
import net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder;
7
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
8
import net.minecraft.world.entity.ai.memory.WalkTarget;
9
10
public class BabyFollowAdult {
11
	public static OneShot<LivingEntity> create(final UniformInt followRange, final float speedModifier) {
12
		return create(followRange, mob -> speedModifier, MemoryModuleType.NEAREST_VISIBLE_ADULT, false);
13
	}
14
15
	public static OneShot<LivingEntity> create(
16
		final UniformInt followRange,
17
		final Function<LivingEntity, Float> speedModifier,
18
		final MemoryModuleType<? extends LivingEntity> nearestVisibleType,
19
		final boolean targetEye
20
	) {
21
		return BehaviorBuilder.create(
22
			i -> i.group(i.present(nearestVisibleType), i.registered(MemoryModuleType.LOOK_TARGET), i.absent(MemoryModuleType.WALK_TARGET))
23
				.apply(i, (nearestAdult, lookTarget, walkTarget) -> (level, body, timestamp) -> {
24
					if (!body.isBaby()) {
25
						return false;
26
					} else {
27
						LivingEntity adult = i.get(nearestAdult);
28
						if (body.closerThan(adult, followRange.maxInclusive() + 1) && !body.closerThan(adult, followRange.minInclusive())) {
29
							WalkTarget target = new WalkTarget(new EntityTracker(adult, targetEye, targetEye), speedModifier.apply(body), followRange.minInclusive() - 1);
30
							lookTarget.set(new EntityTracker(adult, true, targetEye));
31
							walkTarget.set(target);
32
							return true;
33
						} else {
34
							return false;
35
						}
36
					}
37
				})
38
		);
39
	}
40
}
41

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