| 1 | package net.minecraft.world.entity.ai.behavior;
|
| 2 |
|
| 3 | import net.minecraft.core.GlobalPos;
|
| 4 | import net.minecraft.world.entity.EntityTypes;
|
| 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.NearestVisibleLivingEntities;
|
| 9 | import net.minecraft.world.entity.ai.memory.WalkTarget;
|
| 10 |
|
| 11 | public class SocializeAtBell {
|
| 12 | private static final float SPEED_MODIFIER = 0.3F;
|
| 13 |
|
| 14 | public static OneShot<LivingEntity> create() {
|
| 15 | return BehaviorBuilder.create(
|
| 16 | i -> i.group(
|
| 17 | i.registered(MemoryModuleType.WALK_TARGET),
|
| 18 | i.registered(MemoryModuleType.LOOK_TARGET),
|
| 19 | i.present(MemoryModuleType.MEETING_POINT),
|
| 20 | i.present(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES),
|
| 21 | i.absent(MemoryModuleType.INTERACTION_TARGET)
|
| 22 | )
|
| 23 | .apply(
|
| 24 | i,
|
| 25 | (walkTarget, lookTarget, meetingPoint, nearestEntities, interactionTarget) -> (level, body, timestamp) -> {
|
| 26 | GlobalPos memory = i.get(meetingPoint);
|
| 27 | NearestVisibleLivingEntities visibleEntities = i.get(nearestEntities);
|
| 28 | if (level.getRandom().nextInt(100) == 0
|
| 29 | && level.dimension() == memory.dimension()
|
| 30 | && memory.pos().closerToCenterThan(body.position(), 4.0)
|
| 31 | && visibleEntities.contains(mob -> mob.is(EntityTypes.VILLAGER))) {
|
| 32 | visibleEntities.findClosest(mob -> mob.is(EntityTypes.VILLAGER) && mob.distanceToSqr(body) <= 32.0).ifPresent(mob -> {
|
| 33 | interactionTarget.set(mob);
|
| 34 | lookTarget.set(new EntityTracker(mob, true));
|
| 35 | walkTarget.set(new WalkTarget(new EntityTracker(mob, false), 0.3F, 1));
|
| 36 | });
|
| 37 | return true;
|
| 38 | } else {
|
| 39 | return false;
|
| 40 | }
|
| 41 | }
|
| 42 | )
|
| 43 | );
|
| 44 | }
|
| 45 | }
|
| 46 |
|