| 1 | package net.minecraft.world.entity.monster.breeze;
|
| 2 |
|
| 3 | import com.google.common.annotations.VisibleForTesting;
|
| 4 | import com.google.common.collect.ImmutableList;
|
| 5 | import com.google.common.collect.ImmutableSet;
|
| 6 | import com.mojang.datafixers.util.Pair;
|
| 7 | import java.util.List;
|
| 8 | import net.minecraft.server.level.ServerLevel;
|
| 9 | import net.minecraft.sounds.SoundEvents;
|
| 10 | import net.minecraft.util.Unit;
|
| 11 | import net.minecraft.world.damagesource.DamageSource;
|
| 12 | import net.minecraft.world.entity.LivingEntity;
|
| 13 | import net.minecraft.world.entity.Mob;
|
| 14 | import net.minecraft.world.entity.Pose;
|
| 15 | import net.minecraft.world.entity.ai.ActivityData;
|
| 16 | import net.minecraft.world.entity.ai.behavior.DoNothing;
|
| 17 | import net.minecraft.world.entity.ai.behavior.LookAtTargetSink;
|
| 18 | import net.minecraft.world.entity.ai.behavior.MoveToTargetSink;
|
| 19 | import net.minecraft.world.entity.ai.behavior.RandomStroll;
|
| 20 | import net.minecraft.world.entity.ai.behavior.RunOne;
|
| 21 | import net.minecraft.world.entity.ai.behavior.StartAttacking;
|
| 22 | import net.minecraft.world.entity.ai.behavior.StopAttackingIfTargetInvalid;
|
| 23 | import net.minecraft.world.entity.ai.behavior.Swim;
|
| 24 | import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
| 25 | import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
| 26 | import net.minecraft.world.entity.ai.sensing.Sensor;
|
| 27 | import net.minecraft.world.entity.schedule.Activity;
|
| 28 |
|
| 29 | public class BreezeAi {
|
| 30 | public static final float SPEED_MULTIPLIER_WHEN_SLIDING = 0.6F;
|
| 31 | public static final float JUMP_CIRCLE_INNER_RADIUS = 4.0F;
|
| 32 | public static final float JUMP_CIRCLE_MIDDLE_RADIUS = 8.0F;
|
| 33 | public static final float JUMP_CIRCLE_OUTER_RADIUS = 24.0F;
|
| 34 | private static final int TICKS_TO_REMEMBER_SEEN_TARGET = 100;
|
| 35 |
|
| 36 | protected static List<ActivityData<Breeze>> getActivities(final Breeze breeze) {
|
| 37 | return List.of(initCoreActivity(), initIdleActivity(), initFightActivity(breeze));
|
| 38 | }
|
| 39 |
|
| 40 | private static ActivityData<Breeze> initCoreActivity() {
|
| 41 | return ActivityData.create(Activity.CORE, 0, ImmutableList.of(new Swim<>(0.8F), new LookAtTargetSink(45, 90)));
|
| 42 | }
|
| 43 |
|
| 44 | private static ActivityData<Breeze> initIdleActivity() {
|
| 45 | return ActivityData.create(
|
| 46 | Activity.IDLE,
|
| 47 | ImmutableList.of(
|
| 48 | Pair.of(0, StartAttacking.create((var0, breeze) -> breeze.getBrain().getMemory(MemoryModuleType.NEAREST_ATTACKABLE))),
|
| 49 | Pair.of(
|
| 50 | 1,
|
| 51 | StartAttacking.create(
|
| 52 | (var0, breeze) -> breeze.getBrain()
|
| 53 | .getMemory(MemoryModuleType.HURT_BY)
|
| 54 | .map(DamageSource::getEntity)
|
| 55 | .filter(entity -> entity instanceof LivingEntity)
|
| 56 | .map(entity -> (LivingEntity)entity)
|
| 57 | )
|
| 58 | ),
|
| 59 | Pair.of(2, new BreezeAi.SlideToTargetSink(20, 40)),
|
| 60 | Pair.of(3, new RunOne<>(ImmutableList.of(Pair.of(new DoNothing(20, 100), 1), Pair.of(RandomStroll.stroll(0.6F), 2))))
|
| 61 | )
|
| 62 | );
|
| 63 | }
|
| 64 |
|
| 65 | private static ActivityData<Breeze> initFightActivity(final Breeze body) {
|
| 66 | return ActivityData.create(
|
| 67 | Activity.FIGHT,
|
| 68 | ImmutableList.of(
|
| 69 | Pair.of(0, StopAttackingIfTargetInvalid.create(Sensor.wasEntityAttackableLastNTicks(body, 100).negate()::test)),
|
| 70 | Pair.of(1, new Shoot()),
|
| 71 | Pair.of(2, new LongJump()),
|
| 72 | Pair.of(3, new ShootWhenStuck()),
|
| 73 | Pair.of(4, new Slide())
|
| 74 | ),
|
| 75 | ImmutableSet.of(Pair.of(MemoryModuleType.ATTACK_TARGET, MemoryStatus.VALUE_PRESENT), Pair.of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT))
|
| 76 | );
|
| 77 | }
|
| 78 |
|
| 79 | public static void updateActivity(final Breeze body) {
|
| 80 | body.getBrain().setActiveActivityToFirstValid(ImmutableList.of(Activity.FIGHT, Activity.IDLE));
|
| 81 | }
|
| 82 |
|
| 83 | public static class SlideToTargetSink extends MoveToTargetSink {
|
| 84 | @VisibleForTesting
|
| 85 | public SlideToTargetSink(final int minTimeout, final int maxTimeout) {
|
| 86 | super(minTimeout, maxTimeout);
|
| 87 | }
|
| 88 |
|
| 89 | @Override
|
| 90 | protected void start(final ServerLevel level, final Mob body, final long timestamp) {
|
| 91 | super.start(level, body, timestamp);
|
| 92 | body.playSound(SoundEvents.BREEZE_SLIDE);
|
| 93 | body.setPose(Pose.SLIDING);
|
| 94 | }
|
| 95 |
|
| 96 | @Override
|
| 97 | protected void stop(final ServerLevel level, final Mob body, final long timestamp) {
|
| 98 | super.stop(level, body, timestamp);
|
| 99 | body.setPose(Pose.STANDING);
|
| 100 | if (body.getBrain().hasMemoryValue(MemoryModuleType.ATTACK_TARGET)) {
|
| 101 | body.getBrain().setMemoryWithExpiry(MemoryModuleType.BREEZE_SHOOT, Unit.INSTANCE, 60L);
|
| 102 | }
|
| 103 | }
|
| 104 | }
|
| 105 | }
|
| 106 |
|