| 1 | package net.minecraft.world.entity.monster.breeze;
|
| 2 |
|
| 3 | import java.util.Map;
|
| 4 | import net.minecraft.core.BlockPos;
|
| 5 | import net.minecraft.server.level.ServerLevel;
|
| 6 | import net.minecraft.util.Mth;
|
| 7 | import net.minecraft.world.entity.LivingEntity;
|
| 8 | import net.minecraft.world.entity.Pose;
|
| 9 | import net.minecraft.world.entity.ai.behavior.Behavior;
|
| 10 | import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
| 11 | import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
| 12 | import net.minecraft.world.entity.ai.memory.WalkTarget;
|
| 13 | import net.minecraft.world.entity.ai.util.DefaultRandomPos;
|
| 14 | import net.minecraft.world.phys.Vec3;
|
| 15 |
|
| 16 | public class Slide extends Behavior<Breeze> {
|
| 17 | public Slide() {
|
| 18 | super(
|
| 19 | Map.of(
|
| 20 | MemoryModuleType.ATTACK_TARGET,
|
| 21 | MemoryStatus.VALUE_PRESENT,
|
| 22 | MemoryModuleType.WALK_TARGET,
|
| 23 | MemoryStatus.VALUE_ABSENT,
|
| 24 | MemoryModuleType.BREEZE_JUMP_COOLDOWN,
|
| 25 | MemoryStatus.VALUE_ABSENT,
|
| 26 | MemoryModuleType.BREEZE_SHOOT,
|
| 27 | MemoryStatus.VALUE_ABSENT
|
| 28 | )
|
| 29 | );
|
| 30 | }
|
| 31 |
|
| 32 | protected boolean checkExtraStartConditions(final ServerLevel level, final Breeze breeze) {
|
| 33 | return breeze.onGround() && !breeze.isInWater() && breeze.getPose() == Pose.STANDING;
|
| 34 | }
|
| 35 |
|
| 36 | protected void start(final ServerLevel level, final Breeze breeze, final long timestamp) {
|
| 37 | LivingEntity enemy = breeze.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null);
|
| 38 | if (enemy != null) {
|
| 39 | boolean isWithinInnerRing = breeze.withinInnerCircleRange(enemy.position());
|
| 40 | Vec3 position = null;
|
| 41 | if (isWithinInnerRing) {
|
| 42 | Vec3 position0 = DefaultRandomPos.getPosAway(breeze, 5, 5, enemy.position());
|
| 43 | if (position0 != null
|
| 44 | && BreezeUtil.hasLineOfSight(breeze, position0)
|
| 45 | && enemy.distanceToSqr(position0.x, position0.y, position0.z) > enemy.distanceToSqr(breeze)) {
|
| 46 | position = position0;
|
| 47 | }
|
| 48 | }
|
| 49 |
|
| 50 | if (position == null) {
|
| 51 | position = breeze.getRandom().nextBoolean() ? BreezeUtil.randomPointBehindTarget(enemy, breeze.getRandom()) : randomPointInMiddleCircle(breeze, enemy);
|
| 52 | }
|
| 53 |
|
| 54 | breeze.getBrain().setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(BlockPos.containing(position), 0.6F, 1));
|
| 55 | }
|
| 56 | }
|
| 57 |
|
| 58 | private static Vec3 randomPointInMiddleCircle(final Breeze breeze, final LivingEntity enemy) {
|
| 59 | Vec3 direction = enemy.position().subtract(breeze.position());
|
| 60 | double distance = direction.length() - Mth.lerp(breeze.getRandom().nextDouble(), 8.0, 4.0);
|
| 61 | Vec3 target = direction.normalize().multiply(distance, distance, distance);
|
| 62 | return breeze.position().add(target);
|
| 63 | }
|
| 64 | }
|
| 65 |
|