| 1 | package net.minecraft.world.entity.ai.behavior.warden;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableMap;
|
| 4 | import net.minecraft.server.level.ServerLevel;
|
| 5 | import net.minecraft.sounds.SoundEvents;
|
| 6 | import net.minecraft.world.entity.Pose;
|
| 7 | import net.minecraft.world.entity.ai.behavior.Behavior;
|
| 8 | import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
| 9 | import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
| 10 | import net.minecraft.world.entity.monster.warden.Warden;
|
| 11 | import net.minecraft.world.entity.monster.warden.WardenAi;
|
| 12 |
|
| 13 | public class Sniffing<E extends Warden> extends Behavior<E> {
|
| 14 | private static final double ANGER_FROM_SNIFFING_MAX_DISTANCE_XZ = 6.0;
|
| 15 | private static final double ANGER_FROM_SNIFFING_MAX_DISTANCE_Y = 20.0;
|
| 16 |
|
| 17 | public Sniffing(final int ticks) {
|
| 18 | super(
|
| 19 | ImmutableMap.of(
|
| 20 | MemoryModuleType.IS_SNIFFING,
|
| 21 | MemoryStatus.VALUE_PRESENT,
|
| 22 | MemoryModuleType.ATTACK_TARGET,
|
| 23 | MemoryStatus.VALUE_ABSENT,
|
| 24 | MemoryModuleType.WALK_TARGET,
|
| 25 | MemoryStatus.VALUE_ABSENT,
|
| 26 | MemoryModuleType.LOOK_TARGET,
|
| 27 | MemoryStatus.REGISTERED,
|
| 28 | MemoryModuleType.NEAREST_ATTACKABLE,
|
| 29 | MemoryStatus.REGISTERED,
|
| 30 | MemoryModuleType.DISTURBANCE_LOCATION,
|
| 31 | MemoryStatus.REGISTERED,
|
| 32 | MemoryModuleType.SNIFF_COOLDOWN,
|
| 33 | MemoryStatus.REGISTERED
|
| 34 | ),
|
| 35 | ticks
|
| 36 | );
|
| 37 | }
|
| 38 |
|
| 39 | protected boolean canStillUse(final ServerLevel level, final E body, final long timestamp) {
|
| 40 | return true;
|
| 41 | }
|
| 42 |
|
| 43 | protected void start(final ServerLevel level, final E body, final long timestamp) {
|
| 44 | body.playSound(SoundEvents.WARDEN_SNIFF, 5.0F, 1.0F);
|
| 45 | }
|
| 46 |
|
| 47 | protected void stop(final ServerLevel level, final E body, final long timestamp) {
|
| 48 | if (body.hasPose(Pose.SNIFFING)) {
|
| 49 | body.setPose(Pose.STANDING);
|
| 50 | }
|
| 51 |
|
| 52 | body.getBrain().eraseMemory(MemoryModuleType.IS_SNIFFING);
|
| 53 | body.getBrain().getMemory(MemoryModuleType.NEAREST_ATTACKABLE).filter(body::canTargetEntity).ifPresent(entity -> {
|
| 54 | if (body.closerThan(entity, 6.0, 20.0)) {
|
| 55 | body.increaseAngerAt(entity);
|
| 56 | }
|
| 57 |
|
| 58 | if (!body.getBrain().hasMemoryValue(MemoryModuleType.DISTURBANCE_LOCATION)) {
|
| 59 | WardenAi.setDisturbanceLocation(body, entity.blockPosition());
|
| 60 | }
|
| 61 | });
|
| 62 | }
|
| 63 | }
|
| 64 |
|