| 1 | package net.minecraft.world.entity.animal.equine;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.server.level.ServerLevel;
|
| 5 | import net.minecraft.sounds.SoundEvent;
|
| 6 | import net.minecraft.sounds.SoundEvents;
|
| 7 | import net.minecraft.tags.FluidTags;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 | import net.minecraft.world.InteractionHand;
|
| 10 | import net.minecraft.world.InteractionResult;
|
| 11 | import net.minecraft.world.damagesource.DamageSource;
|
| 12 | import net.minecraft.world.entity.AgeableMob;
|
| 13 | import net.minecraft.world.entity.EntityAttachment;
|
| 14 | import net.minecraft.world.entity.EntityAttachments;
|
| 15 | import net.minecraft.world.entity.EntityDimensions;
|
| 16 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 17 | import net.minecraft.world.entity.EntityType;
|
| 18 | import net.minecraft.world.entity.EntityTypes;
|
| 19 | import net.minecraft.world.entity.EquipmentSlot;
|
| 20 | import net.minecraft.world.entity.Pose;
|
| 21 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 22 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 23 | import net.minecraft.world.entity.animal.Animal;
|
| 24 | import net.minecraft.world.entity.player.Player;
|
| 25 | import net.minecraft.world.level.Level;
|
| 26 | import net.minecraft.world.level.LevelAccessor;
|
| 27 | import net.minecraft.world.level.storage.ValueInput;
|
| 28 | import net.minecraft.world.level.storage.ValueOutput;
|
| 29 | import org.jspecify.annotations.Nullable;
|
| 30 |
|
| 31 | public class SkeletonHorse extends AbstractHorse {
|
| 32 | private final SkeletonTrapGoal skeletonTrapGoal = new SkeletonTrapGoal(this);
|
| 33 | private static final int TRAP_MAX_LIFE = 18000;
|
| 34 | private static final boolean DEFAULT_IS_TRAP = false;
|
| 35 | private static final int DEFAULT_TRAP_TIME = 0;
|
| 36 | private static final EntityDimensions BABY_DIMENSIONS = EntityTypes.SKELETON_HORSE
|
| 37 | .getDimensions()
|
| 38 | .withAttachments(EntityAttachments.builder().attach(EntityAttachment.PASSENGER, 0.0F, EntityTypes.SKELETON_HORSE.getHeight() - 0.25F, 0.0F))
|
| 39 | .scale(0.7F);
|
| 40 | private boolean isTrap = false;
|
| 41 | private int trapTime = 0;
|
| 42 |
|
| 43 | public SkeletonHorse(final EntityType<? extends SkeletonHorse> type, final Level level) {
|
| 44 | super(type, level);
|
| 45 | }
|
| 46 |
|
| 47 | public static AttributeSupplier.Builder createAttributes() {
|
| 48 | return createBaseHorseAttributes().add(Attributes.MAX_HEALTH, 15.0).add(Attributes.MOVEMENT_SPEED, 0.2F);
|
| 49 | }
|
| 50 |
|
| 51 | public static boolean checkSkeletonHorseSpawnRules(
|
| 52 | final EntityType<? extends Animal> type, final LevelAccessor level, final EntitySpawnReason spawnReason, final BlockPos pos, final RandomSource random
|
| 53 | ) {
|
| 54 | return !EntitySpawnReason.isSpawner(spawnReason)
|
| 55 | ? Animal.checkAnimalSpawnRules(type, level, spawnReason, pos, random)
|
| 56 | : EntitySpawnReason.ignoresLightRequirements(spawnReason) || isBrightEnoughToSpawn(level, pos);
|
| 57 | }
|
| 58 |
|
| 59 | @Override
|
| 60 | protected void randomizeAttributes(final RandomSource random) {
|
| 61 | this.getAttribute(Attributes.JUMP_STRENGTH).setBaseValue(generateJumpStrength(random::nextDouble));
|
| 62 | }
|
| 63 |
|
| 64 | @Override
|
| 65 | protected void addBehaviourGoals() {
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | protected SoundEvent getAmbientSound() {
|
| 70 | return this.isEyeInFluid(FluidTags.WATER) ? SoundEvents.SKELETON_HORSE_AMBIENT_WATER : SoundEvents.SKELETON_HORSE_AMBIENT;
|
| 71 | }
|
| 72 |
|
| 73 | @Override
|
| 74 | protected SoundEvent getDeathSound() {
|
| 75 | return SoundEvents.SKELETON_HORSE_DEATH;
|
| 76 | }
|
| 77 |
|
| 78 | @Override
|
| 79 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 80 | return SoundEvents.SKELETON_HORSE_HURT;
|
| 81 | }
|
| 82 |
|
| 83 | @Override
|
| 84 | protected SoundEvent getSwimSound() {
|
| 85 | if (this.onGround()) {
|
| 86 | if (!this.isVehicle()) {
|
| 87 | return SoundEvents.SKELETON_HORSE_STEP_WATER;
|
| 88 | }
|
| 89 |
|
| 90 | this.gallopSoundCounter++;
|
| 91 | if (this.gallopSoundCounter > 5 && this.gallopSoundCounter % 3 == 0) {
|
| 92 | return SoundEvents.SKELETON_HORSE_GALLOP_WATER;
|
| 93 | }
|
| 94 |
|
| 95 | if (this.gallopSoundCounter <= 5) {
|
| 96 | return SoundEvents.SKELETON_HORSE_STEP_WATER;
|
| 97 | }
|
| 98 | }
|
| 99 |
|
| 100 | return SoundEvents.SKELETON_HORSE_SWIM;
|
| 101 | }
|
| 102 |
|
| 103 | @Override
|
| 104 | protected void playSwimSound(final float volume) {
|
| 105 | if (this.onGround()) {
|
| 106 | super.playSwimSound(0.3F);
|
| 107 | } else {
|
| 108 | super.playSwimSound(Math.min(0.1F, volume * 25.0F));
|
| 109 | }
|
| 110 | }
|
| 111 |
|
| 112 | @Override
|
| 113 | protected void playJumpSound() {
|
| 114 | if (this.isInWater()) {
|
| 115 | this.playSound(SoundEvents.SKELETON_HORSE_JUMP_WATER, 0.4F, 1.0F);
|
| 116 | } else {
|
| 117 | super.playJumpSound();
|
| 118 | }
|
| 119 | }
|
| 120 |
|
| 121 | @Override
|
| 122 | public EntityDimensions getDefaultDimensions(final Pose pose) {
|
| 123 | return this.isBaby() ? BABY_DIMENSIONS : super.getDefaultDimensions(pose);
|
| 124 | }
|
| 125 |
|
| 126 | @Override
|
| 127 | public void aiStep() {
|
| 128 | super.aiStep();
|
| 129 | if (!this.isPersistenceRequired() && this.isTrap() && this.trapTime++ >= 18000) {
|
| 130 | this.discard();
|
| 131 | }
|
| 132 | }
|
| 133 |
|
| 134 | @Override
|
| 135 | protected void addAdditionalSaveData(final ValueOutput output) {
|
| 136 | super.addAdditionalSaveData(output);
|
| 137 | output.putBoolean("SkeletonTrap", this.isTrap());
|
| 138 | output.putInt("SkeletonTrapTime", this.trapTime);
|
| 139 | }
|
| 140 |
|
| 141 | @Override
|
| 142 | protected void readAdditionalSaveData(final ValueInput input) {
|
| 143 | super.readAdditionalSaveData(input);
|
| 144 | this.setTrap(input.getBooleanOr("SkeletonTrap", false));
|
| 145 | this.trapTime = input.getIntOr("SkeletonTrapTime", 0);
|
| 146 | }
|
| 147 |
|
| 148 | @Override
|
| 149 | protected float getWaterSlowDown() {
|
| 150 | return 0.96F;
|
| 151 | }
|
| 152 |
|
| 153 | public boolean isTrap() {
|
| 154 | return this.isTrap;
|
| 155 | }
|
| 156 |
|
| 157 | public void setTrap(final boolean trap) {
|
| 158 | if (trap != this.isTrap) {
|
| 159 | this.isTrap = trap;
|
| 160 | if (trap) {
|
| 161 | this.goalSelector.addGoal(1, this.skeletonTrapGoal);
|
| 162 | } else {
|
| 163 | this.goalSelector.removeGoal(this.skeletonTrapGoal);
|
| 164 | }
|
| 165 | }
|
| 166 | }
|
| 167 |
|
| 168 | @Override
|
| 169 | public @Nullable AgeableMob getBreedOffspring(final ServerLevel level, final AgeableMob partner) {
|
| 170 | return EntityTypes.SKELETON_HORSE.create(level, EntitySpawnReason.BREEDING);
|
| 171 | }
|
| 172 |
|
| 173 | @Override
|
| 174 | public InteractionResult mobInteract(final Player player, final InteractionHand hand) {
|
| 175 | return !this.isTamed() ? InteractionResult.PASS : super.mobInteract(player, hand);
|
| 176 | }
|
| 177 |
|
| 178 | @Override
|
| 179 | public boolean canUseSlot(final EquipmentSlot slot) {
|
| 180 | return true;
|
| 181 | }
|
| 182 |
|
| 183 | @Override
|
| 184 | public boolean canAgeUp() {
|
| 185 | return false;
|
| 186 | }
|
| 187 | }
|
| 188 |
|