| 1 | package net.minecraft.world.entity.animal.goat;
|
| 2 |
|
| 3 | import com.google.common.collect.ImmutableList;
|
| 4 | import com.google.common.collect.ImmutableSet;
|
| 5 | import com.mojang.datafixers.util.Pair;
|
| 6 | import java.util.List;
|
| 7 | import net.minecraft.sounds.SoundEvents;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 | import net.minecraft.util.valueproviders.UniformInt;
|
| 10 | import net.minecraft.world.entity.EntityTypes;
|
| 11 | import net.minecraft.world.entity.ai.ActivityData;
|
| 12 | import net.minecraft.world.entity.ai.behavior.AnimalMakeLove;
|
| 13 | import net.minecraft.world.entity.ai.behavior.AnimalPanic;
|
| 14 | import net.minecraft.world.entity.ai.behavior.BabyFollowAdult;
|
| 15 | import net.minecraft.world.entity.ai.behavior.CountDownCooldownTicks;
|
| 16 | import net.minecraft.world.entity.ai.behavior.DoNothing;
|
| 17 | import net.minecraft.world.entity.ai.behavior.FollowTemptation;
|
| 18 | import net.minecraft.world.entity.ai.behavior.LongJumpMidJump;
|
| 19 | import net.minecraft.world.entity.ai.behavior.LongJumpToRandomPos;
|
| 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.PrepareRamNearestTarget;
|
| 23 | import net.minecraft.world.entity.ai.behavior.RamTarget;
|
| 24 | import net.minecraft.world.entity.ai.behavior.RandomStroll;
|
| 25 | import net.minecraft.world.entity.ai.behavior.RunOne;
|
| 26 | import net.minecraft.world.entity.ai.behavior.SetEntityLookTargetSometimes;
|
| 27 | import net.minecraft.world.entity.ai.behavior.SetWalkTargetFromLookTarget;
|
| 28 | import net.minecraft.world.entity.ai.behavior.Swim;
|
| 29 | import net.minecraft.world.entity.ai.memory.MemoryModuleType;
|
| 30 | import net.minecraft.world.entity.ai.memory.MemoryStatus;
|
| 31 | import net.minecraft.world.entity.ai.targeting.TargetingConditions;
|
| 32 | import net.minecraft.world.entity.schedule.Activity;
|
| 33 | import net.minecraft.world.level.gamerules.GameRules;
|
| 34 |
|
| 35 | public class GoatAi {
|
| 36 | public static final int RAM_PREPARE_TIME = 20;
|
| 37 | public static final int RAM_MAX_DISTANCE = 7;
|
| 38 | private static final UniformInt ADULT_FOLLOW_RANGE = UniformInt.of(5, 16);
|
| 39 | private static final float SPEED_MULTIPLIER_WHEN_IDLING = 1.0F;
|
| 40 | private static final float SPEED_MULTIPLIER_WHEN_FOLLOWING_ADULT = 1.25F;
|
| 41 | private static final float SPEED_MULTIPLIER_WHEN_TEMPTED = 1.25F;
|
| 42 | private static final float SPEED_MULTIPLIER_WHEN_PANICKING = 2.0F;
|
| 43 | private static final float SPEED_MULTIPLIER_WHEN_PREPARING_TO_RAM = 1.25F;
|
| 44 | private static final UniformInt TIME_BETWEEN_LONG_JUMPS = UniformInt.of(600, 1200);
|
| 45 | public static final int MAX_LONG_JUMP_HEIGHT = 5;
|
| 46 | public static final int MAX_LONG_JUMP_WIDTH = 5;
|
| 47 | public static final float MAX_JUMP_VELOCITY_MULTIPLIER = 3.5714288F;
|
| 48 | private static final UniformInt TIME_BETWEEN_RAMS = UniformInt.of(600, 6000);
|
| 49 | private static final UniformInt TIME_BETWEEN_RAMS_SCREAMER = UniformInt.of(100, 300);
|
| 50 | private static final TargetingConditions RAM_TARGET_CONDITIONS = TargetingConditions.forCombat()
|
| 51 | .selector(
|
| 52 | (target, level) -> !target.is(EntityTypes.GOAT)
|
| 53 | && (level.getGameRules().get(GameRules.MOB_GRIEFING) || !target.is(EntityTypes.ARMOR_STAND))
|
| 54 | && level.getWorldBorder().isWithinBounds(target.getBoundingBox())
|
| 55 | );
|
| 56 | private static final float SPEED_MULTIPLIER_WHEN_RAMMING = 3.0F;
|
| 57 | public static final int RAM_MIN_DISTANCE = 4;
|
| 58 | public static final float ADULT_RAM_KNOCKBACK_FORCE = 2.5F;
|
| 59 | public static final float BABY_RAM_KNOCKBACK_FORCE = 1.0F;
|
| 60 |
|
| 61 | protected static void initMemories(final Goat body, final RandomSource random) {
|
| 62 | body.getBrain().setMemory(MemoryModuleType.LONG_JUMP_COOLDOWN_TICKS, TIME_BETWEEN_LONG_JUMPS.sample(random));
|
| 63 | body.getBrain().setMemory(MemoryModuleType.RAM_COOLDOWN_TICKS, TIME_BETWEEN_RAMS.sample(random));
|
| 64 | }
|
| 65 |
|
| 66 | protected static List<ActivityData<Goat>> getActivities() {
|
| 67 | return List.of(initCoreActivity(), initIdleActivity(), initLongJumpActivity(), initRamActivity());
|
| 68 | }
|
| 69 |
|
| 70 | private static ActivityData<Goat> initCoreActivity() {
|
| 71 | return ActivityData.create(
|
| 72 | Activity.CORE,
|
| 73 | 0,
|
| 74 | ImmutableList.of(
|
| 75 | new Swim<>(0.8F),
|
| 76 | new AnimalPanic(2.0F),
|
| 77 | new LookAtTargetSink(45, 90),
|
| 78 | new MoveToTargetSink(),
|
| 79 | new CountDownCooldownTicks(MemoryModuleType.TEMPTATION_COOLDOWN_TICKS),
|
| 80 | new CountDownCooldownTicks(MemoryModuleType.LONG_JUMP_COOLDOWN_TICKS),
|
| 81 | new CountDownCooldownTicks(MemoryModuleType.RAM_COOLDOWN_TICKS)
|
| 82 | )
|
| 83 | );
|
| 84 | }
|
| 85 |
|
| 86 | private static ActivityData<Goat> initIdleActivity() {
|
| 87 | return ActivityData.create(
|
| 88 | Activity.IDLE,
|
| 89 | ImmutableList.of(
|
| 90 | Pair.of(0, SetEntityLookTargetSometimes.create(EntityTypes.PLAYER, 6.0F, UniformInt.of(30, 60))),
|
| 91 | Pair.of(0, new AnimalMakeLove(EntityTypes.GOAT)),
|
| 92 | Pair.of(1, new FollowTemptation(s -> 1.25F)),
|
| 93 | Pair.of(2, BabyFollowAdult.create(ADULT_FOLLOW_RANGE, 1.25F)),
|
| 94 | Pair.of(
|
| 95 | 3,
|
| 96 | new RunOne<>(
|
| 97 | ImmutableList.of(Pair.of(RandomStroll.stroll(1.0F), 2), Pair.of(SetWalkTargetFromLookTarget.create(1.0F, 3), 2), Pair.of(new DoNothing(30, 60), 1))
|
| 98 | )
|
| 99 | )
|
| 100 | ),
|
| 101 | ImmutableSet.of(
|
| 102 | Pair.of(MemoryModuleType.RAM_COOLDOWN_TICKS, MemoryStatus.VALUE_PRESENT), Pair.of(MemoryModuleType.LONG_JUMP_COOLDOWN_TICKS, MemoryStatus.VALUE_PRESENT)
|
| 103 | )
|
| 104 | );
|
| 105 | }
|
| 106 |
|
| 107 | private static ActivityData<Goat> initLongJumpActivity() {
|
| 108 | return ActivityData.create(
|
| 109 | Activity.LONG_JUMP,
|
| 110 | ImmutableList.of(
|
| 111 | Pair.of(0, new LongJumpMidJump(TIME_BETWEEN_LONG_JUMPS, SoundEvents.GOAT_STEP)),
|
| 112 | Pair.of(
|
| 113 | 1,
|
| 114 | new LongJumpToRandomPos<>(
|
| 115 | TIME_BETWEEN_LONG_JUMPS, 5, 5, 3.5714288F, goat -> goat.isScreamingGoat() ? SoundEvents.GOAT_SCREAMING_LONG_JUMP : SoundEvents.GOAT_LONG_JUMP
|
| 116 | )
|
| 117 | )
|
| 118 | ),
|
| 119 | ImmutableSet.of(
|
| 120 | Pair.of(MemoryModuleType.TEMPTING_PLAYER, MemoryStatus.VALUE_ABSENT),
|
| 121 | Pair.of(MemoryModuleType.BREED_TARGET, MemoryStatus.VALUE_ABSENT),
|
| 122 | Pair.of(MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT),
|
| 123 | Pair.of(MemoryModuleType.LONG_JUMP_COOLDOWN_TICKS, MemoryStatus.VALUE_ABSENT)
|
| 124 | )
|
| 125 | );
|
| 126 | }
|
| 127 |
|
| 128 | private static ActivityData<Goat> initRamActivity() {
|
| 129 | return ActivityData.create(
|
| 130 | Activity.RAM,
|
| 131 | ImmutableList.of(
|
| 132 | Pair.of(
|
| 133 | 0,
|
| 134 | new RamTarget(
|
| 135 | goat -> goat.isScreamingGoat() ? TIME_BETWEEN_RAMS_SCREAMER : TIME_BETWEEN_RAMS,
|
| 136 | RAM_TARGET_CONDITIONS,
|
| 137 | 3.0F,
|
| 138 | goat -> goat.isBaby() ? 1.0 : 2.5,
|
| 139 | goat -> goat.isScreamingGoat() ? SoundEvents.GOAT_SCREAMING_RAM_IMPACT : SoundEvents.GOAT_RAM_IMPACT,
|
| 140 | var0 -> SoundEvents.GOAT_HORN_BREAK
|
| 141 | )
|
| 142 | ),
|
| 143 | Pair.of(
|
| 144 | 1,
|
| 145 | new PrepareRamNearestTarget<>(
|
| 146 | mob -> mob.isScreamingGoat() ? TIME_BETWEEN_RAMS_SCREAMER.minInclusive() : TIME_BETWEEN_RAMS.minInclusive(),
|
| 147 | 4,
|
| 148 | 7,
|
| 149 | 1.25F,
|
| 150 | RAM_TARGET_CONDITIONS,
|
| 151 | 20,
|
| 152 | goat -> goat.isScreamingGoat() ? SoundEvents.GOAT_SCREAMING_PREPARE_RAM : SoundEvents.GOAT_PREPARE_RAM
|
| 153 | )
|
| 154 | )
|
| 155 | ),
|
| 156 | ImmutableSet.of(
|
| 157 | Pair.of(MemoryModuleType.TEMPTING_PLAYER, MemoryStatus.VALUE_ABSENT),
|
| 158 | Pair.of(MemoryModuleType.BREED_TARGET, MemoryStatus.VALUE_ABSENT),
|
| 159 | Pair.of(MemoryModuleType.RAM_COOLDOWN_TICKS, MemoryStatus.VALUE_ABSENT)
|
| 160 | )
|
| 161 | );
|
| 162 | }
|
| 163 |
|
| 164 | public static void updateActivity(final Goat body) {
|
| 165 | body.getBrain().setActiveActivityToFirstValid(ImmutableList.of(Activity.RAM, Activity.LONG_JUMP, Activity.IDLE));
|
| 166 | }
|
| 167 | }
|
| 168 |
|