| 1 | package net.minecraft.world.entity.animal.nautilus;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableList;
|
| 4 | import com.google.common.collect.ImmutableMap;
|
| 5 | import com.google.common.collect.ImmutableSet;
|
| 6 | import com.mojang.datafixers.util.Pair;
|
| 7 | import java.util.List;
|
| 8 | import net.minecraft.sounds.SoundEvents;
|
| 9 | import net.minecraft.world.entity.ai.ActivityData;
|
| 10 | import net.minecraft.world.entity.ai.behavior.ChargeAttack;
|
| 11 | import net.minecraft.world.entity.ai.behavior.CountDownCooldownTicks;
|
| 12 | import net.minecraft.world.entity.ai.behavior.FollowTemptation;
|
| 13 | import net.minecraft.world.entity.ai.behavior.GateBehavior;
|
| 14 | import net.minecraft.world.entity.ai.behavior.LookAtTargetSink;
|
| 15 | import net.minecraft.world.entity.ai.behavior.MoveToTargetSink;
|
| 16 | import net.minecraft.world.entity.ai.behavior.RandomStroll;
|
| 17 | import net.minecraft.world.entity.ai.behavior.SetWalkTargetFromLookTarget;
|
| 18 | import net.minecraft.world.entity.ai.behavior.StartAttacking;
|
| 19 | import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
| 20 | import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
| 21 | import net.minecraft.world.entity.schedule.Activity;
|
| 22 |
|
| 23 | public class ZombieNautilusAi {
|
| 24 | private static final float SPEED_MULTIPLIER_WHEN_IDLING_IN_WATER = 1.0F;
|
| 25 | private static final float SPEED_MULTIPLIER_WHEN_TEMPTED = 0.9F;
|
| 26 | private static final float SPEED_WHEN_ATTACKING = 0.5F;
|
| 27 | private static final float ATTACK_KNOCKBACK_FORCE = 2.0F;
|
| 28 | private static final int TIME_BETWEEN_ATTACKS = 80;
|
| 29 | private static final double MAX_CHARGE_DISTANCE = 12.0;
|
| 30 | private static final double MAX_TARGET_DETECTION_DISTANCE = 11.0;
|
| 31 |
|
| 32 | public static List<ActivityData<ZombieNautilus>> getActivities() {
|
| 33 | return List.of(initCoreActivity(), initIdleActivity(), initFightActivity());
|
| 34 | }
|
| 35 |
|
| 36 | private static ActivityData<ZombieNautilus> initCoreActivity() {
|
| 37 | return ActivityData.create(
|
| 38 | Activity.CORE,
|
| 39 | 0,
|
| 40 | ImmutableList.of(
|
| 41 | new LookAtTargetSink(45, 90),
|
| 42 | new MoveToTargetSink(),
|
| 43 | new CountDownCooldownTicks(MemoryModuleType.TEMPTATION_COOLDOWN_TICKS),
|
| 44 | new CountDownCooldownTicks(MemoryModuleType.CHARGE_COOLDOWN_TICKS),
|
| 45 | new CountDownCooldownTicks(MemoryModuleType.ATTACK_TARGET_COOLDOWN)
|
| 46 | )
|
| 47 | );
|
| 48 | }
|
| 49 |
|
| 50 | private static ActivityData<ZombieNautilus> initIdleActivity() {
|
| 51 | return ActivityData.create(
|
| 52 | Activity.IDLE,
|
| 53 | ImmutableList.of(
|
| 54 | Pair.of(1, new FollowTemptation(mob -> 0.9F, mob -> mob.isBaby() ? 2.5 : 3.5)),
|
| 55 | Pair.of(2, StartAttacking.create(NautilusAi::findNearestValidAttackTarget)),
|
| 56 | Pair.of(
|
| 57 | 3,
|
| 58 | new GateBehavior<>(
|
| 59 | ImmutableMap.of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT),
|
| 60 | ImmutableSet.of(),
|
| 61 | GateBehavior.OrderPolicy.ORDERED,
|
| 62 | GateBehavior.RunningPolicy.TRY_ALL,
|
| 63 | ImmutableList.of(Pair.of(RandomStroll.swim(1.0F), 2), Pair.of(SetWalkTargetFromLookTarget.create(1.0F, 3), 3))
|
| 64 | )
|
| 65 | )
|
| 66 | )
|
| 67 | );
|
| 68 | }
|
| 69 |
|
| 70 | private static ActivityData<ZombieNautilus> initFightActivity() {
|
| 71 | return ActivityData.create(
|
| 72 | Activity.FIGHT,
|
| 73 | ImmutableList.of(Pair.of(0, new ChargeAttack(80, NautilusAi.ATTACK_TARGET_CONDITIONS, 0.5F, 2.0F, 12.0, 11.0, SoundEvents.ZOMBIE_NAUTILUS_DASH))),
|
| 74 | ImmutableSet.of(
|
| 75 | Pair.of(MemoryModuleType.ATTACK_TARGET, MemoryStatus.VALUE_PRESENT),
|
| 76 | Pair.of(MemoryModuleType.TEMPTING_PLAYER, MemoryStatus.VALUE_ABSENT),
|
| 77 | Pair.of(MemoryModuleType.BREED_TARGET, MemoryStatus.VALUE_ABSENT),
|
| 78 | Pair.of(MemoryModuleType.CHARGE_COOLDOWN_TICKS, MemoryStatus.VALUE_ABSENT)
|
| 79 | )
|
| 80 | );
|
| 81 | }
|
| 82 |
|
| 83 | public static void updateActivity(final ZombieNautilus body) {
|
| 84 | body.getBrain().setActiveActivityToFirstValid(ImmutableList.of(Activity.FIGHT, Activity.IDLE));
|
| 85 | }
|
| 86 | }
|
| 87 |
|