| 1 | package net.minecraft.world.entity.animal.camel;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableList;
|
| 4 | import com.google.common.collect.ImmutableMap;
|
| 5 | import com.mojang.datafixers.util.Pair;
|
| 6 | import java.util.List;
|
| 7 | import java.util.function.Predicate;
|
| 8 | import net.minecraft.server.level.ServerLevel;
|
| 9 | import net.minecraft.util.RandomSource;
|
| 10 | import net.minecraft.util.valueproviders.UniformInt;
|
| 11 | import net.minecraft.world.entity.EntityTypes;
|
| 12 | import net.minecraft.world.entity.ai.ActivityData;
|
| 13 | import net.minecraft.world.entity.ai.behavior.AnimalMakeLove;
|
| 14 | import net.minecraft.world.entity.ai.behavior.AnimalPanic;
|
| 15 | import net.minecraft.world.entity.ai.behavior.BabyFollowAdult;
|
| 16 | import net.minecraft.world.entity.ai.behavior.Behavior;
|
| 17 | import net.minecraft.world.entity.ai.behavior.CountDownCooldownTicks;
|
| 18 | import net.minecraft.world.entity.ai.behavior.DoNothing;
|
| 19 | import net.minecraft.world.entity.ai.behavior.FollowTemptation;
|
| 20 | import net.minecraft.world.entity.ai.behavior.LookAtTargetSink;
|
| 21 | import net.minecraft.world.entity.ai.behavior.MoveToTargetSink;
|
| 22 | import net.minecraft.world.entity.ai.behavior.RandomLookAround;
|
| 23 | import net.minecraft.world.entity.ai.behavior.RandomStroll;
|
| 24 | import net.minecraft.world.entity.ai.behavior.RunOne;
|
| 25 | import net.minecraft.world.entity.ai.behavior.SetEntityLookTargetSometimes;
|
| 26 | import net.minecraft.world.entity.ai.behavior.SetWalkTargetFromLookTarget;
|
| 27 | import net.minecraft.world.entity.ai.behavior.Swim;
|
| 28 | import net.minecraft.world.entity.ai.behavior.declarative.BehaviorBuilder;
|
| 29 | import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
| 30 | import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
| 31 | import net.minecraft.world.entity.schedule.Activity;
|
| 32 |
|
| 33 | public class CamelAi {
|
| 34 | private static final float SPEED_MULTIPLIER_WHEN_PANICKING = 4.0F;
|
| 35 | private static final float SPEED_MULTIPLIER_WHEN_IDLING = 2.0F;
|
| 36 | private static final float SPEED_MULTIPLIER_WHEN_TEMPTED = 2.5F;
|
| 37 | private static final float SPEED_MULTIPLIER_WHEN_FOLLOWING_ADULT = 2.5F;
|
| 38 | private static final float SPEED_MULTIPLIER_WHEN_MAKING_LOVE = 1.0F;
|
| 39 | private static final UniformInt ADULT_FOLLOW_RANGE = UniformInt.of(5, 16);
|
| 40 |
|
| 41 | protected static void initMemories(final Camel body, final RandomSource random) {
|
| 42 | }
|
| 43 |
|
| 44 | protected static List<ActivityData<Camel>> getActivities() {
|
| 45 | return List.of(initCoreActivity(), initIdleActivity());
|
| 46 | }
|
| 47 |
|
| 48 | private static ActivityData<Camel> initCoreActivity() {
|
| 49 | return ActivityData.create(
|
| 50 | Activity.CORE,
|
| 51 | 0,
|
| 52 | ImmutableList.of(
|
| 53 | new Swim<>(0.8F),
|
| 54 | new CamelAi.CamelPanic(4.0F),
|
| 55 | new LookAtTargetSink(45, 90),
|
| 56 | new MoveToTargetSink(),
|
| 57 | new CountDownCooldownTicks(MemoryModuleType.TEMPTATION_COOLDOWN_TICKS),
|
| 58 | new CountDownCooldownTicks(MemoryModuleType.GAZE_COOLDOWN_TICKS)
|
| 59 | )
|
| 60 | );
|
| 61 | }
|
| 62 |
|
| 63 | private static ActivityData<Camel> initIdleActivity() {
|
| 64 | return ActivityData.create(
|
| 65 | Activity.IDLE,
|
| 66 | ImmutableList.of(
|
| 67 | Pair.of(0, SetEntityLookTargetSometimes.create(EntityTypes.PLAYER, 6.0F, UniformInt.of(30, 60))),
|
| 68 | Pair.of(1, new AnimalMakeLove(EntityTypes.CAMEL)),
|
| 69 | Pair.of(
|
| 70 | 2,
|
| 71 | new RunOne<>(
|
| 72 | ImmutableList.of(
|
| 73 | Pair.of(new FollowTemptation(camel -> 2.5F, camel -> camel.isBaby() ? 2.5 : 3.5), 1),
|
| 74 | Pair.of(BehaviorBuilder.triggerIf(Predicate.not(Camel::refuseToMove), BabyFollowAdult.create(ADULT_FOLLOW_RANGE, 2.5F)), 1)
|
| 75 | )
|
| 76 | )
|
| 77 | ),
|
| 78 | Pair.of(3, new RandomLookAround(UniformInt.of(150, 250), 30.0F, 0.0F, 0.0F)),
|
| 79 | Pair.of(
|
| 80 | 4,
|
| 81 | new RunOne<>(
|
| 82 | ImmutableMap.of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT),
|
| 83 | ImmutableList.of(
|
| 84 | Pair.of(BehaviorBuilder.triggerIf(Predicate.not(Camel::refuseToMove), RandomStroll.stroll(2.0F)), 1),
|
| 85 | Pair.of(BehaviorBuilder.triggerIf(Predicate.not(Camel::refuseToMove), SetWalkTargetFromLookTarget.create(2.0F, 3)), 1),
|
| 86 | Pair.of(new CamelAi.RandomSitting(20), 1),
|
| 87 | Pair.of(new DoNothing(30, 60), 1)
|
| 88 | )
|
| 89 | )
|
| 90 | )
|
| 91 | )
|
| 92 | );
|
| 93 | }
|
| 94 |
|
| 95 | public static void updateActivity(final Camel body) {
|
| 96 | body.getBrain().setActiveActivityToFirstValid(ImmutableList.of(Activity.IDLE));
|
| 97 | }
|
| 98 |
|
| 99 | public static class CamelPanic extends AnimalPanic<Camel> {
|
| 100 | public CamelPanic(final float speedMultiplier) {
|
| 101 | super(speedMultiplier);
|
| 102 | }
|
| 103 |
|
| 104 | protected boolean checkExtraStartConditions(final ServerLevel level, final Camel body) {
|
| 105 | return super.checkExtraStartConditions(level, body) && !body.isMobControlled();
|
| 106 | }
|
| 107 |
|
| 108 | protected void start(final ServerLevel level, final Camel camel, final long timestamp) {
|
| 109 | camel.standUpInstantly();
|
| 110 | super.start(level, camel, timestamp);
|
| 111 | }
|
| 112 | }
|
| 113 |
|
| 114 | public static class RandomSitting extends Behavior<Camel> {
|
| 115 | private final int minimalPoseTicks;
|
| 116 |
|
| 117 | public RandomSitting(final int minimalPoseTimeSec) {
|
| 118 | super(ImmutableMap.of());
|
| 119 | this.minimalPoseTicks = minimalPoseTimeSec * 20;
|
| 120 | }
|
| 121 |
|
| 122 | protected boolean checkExtraStartConditions(final ServerLevel level, final Camel body) {
|
| 123 | return !body.isInWater()
|
| 124 | && body.getPoseTime() >= this.minimalPoseTicks
|
| 125 | && !body.isLeashed()
|
| 126 | && body.onGround()
|
| 127 | && !body.hasControllingPassenger()
|
| 128 | && body.canCamelChangePose();
|
| 129 | }
|
| 130 |
|
| 131 | protected void start(final ServerLevel level, final Camel body, final long timestamp) {
|
| 132 | if (body.isCamelSitting()) {
|
| 133 | body.standUp();
|
| 134 | } else if (!body.isPanicking()) {
|
| 135 | body.sitDown();
|
| 136 | }
|
| 137 | }
|
| 138 | }
|
| 139 | }
|
| 140 |
|