| 1 | package net.minecraft.world.entity.monster.skeleton;
|
| 2 |
|
| 3 | import net.minecraft.server.level.ServerLevel;
|
| 4 | import net.minecraft.sounds.SoundEvent;
|
| 5 | import net.minecraft.sounds.SoundEvents;
|
| 6 | import net.minecraft.tags.ItemTags;
|
| 7 | import net.minecraft.tags.TagKey;
|
| 8 | import net.minecraft.util.RandomSource;
|
| 9 | import net.minecraft.world.DifficultyInstance;
|
| 10 | import net.minecraft.world.damagesource.DamageSource;
|
| 11 | import net.minecraft.world.effect.MobEffectInstance;
|
| 12 | import net.minecraft.world.effect.MobEffects;
|
| 13 | import net.minecraft.world.entity.Entity;
|
| 14 | import net.minecraft.world.entity.EntitySpawnReason;
|
| 15 | import net.minecraft.world.entity.EntityType;
|
| 16 | import net.minecraft.world.entity.EquipmentSlot;
|
| 17 | import net.minecraft.world.entity.LivingEntity;
|
| 18 | import net.minecraft.world.entity.SpawnGroupData;
|
| 19 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 20 | import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
|
| 21 | import net.minecraft.world.entity.monster.piglin.AbstractPiglin;
|
| 22 | import net.minecraft.world.entity.projectile.arrow.AbstractArrow;
|
| 23 | import net.minecraft.world.item.Item;
|
| 24 | import net.minecraft.world.item.ItemStack;
|
| 25 | import net.minecraft.world.item.Items;
|
| 26 | import net.minecraft.world.level.Level;
|
| 27 | import net.minecraft.world.level.ServerLevelAccessor;
|
| 28 | import net.minecraft.world.level.pathfinder.PathType;
|
| 29 | import org.jspecify.annotations.Nullable;
|
| 30 |
|
| 31 | public class WitherSkeleton extends AbstractSkeleton {
|
| 32 | public WitherSkeleton(final EntityType<? extends WitherSkeleton> type, final Level level) {
|
| 33 | super(type, level);
|
| 34 | this.setPathfindingMalus(PathType.LAVA, 8.0F);
|
| 35 | }
|
| 36 |
|
| 37 | @Override
|
| 38 | protected void registerGoals() {
|
| 39 | this.targetSelector.addGoal(3, new NearestAttackableTargetGoal<>(this, AbstractPiglin.class, true));
|
| 40 | super.registerGoals();
|
| 41 | }
|
| 42 |
|
| 43 | @Override
|
| 44 | protected SoundEvent getAmbientSound() {
|
| 45 | return SoundEvents.WITHER_SKELETON_AMBIENT;
|
| 46 | }
|
| 47 |
|
| 48 | @Override
|
| 49 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 50 | return SoundEvents.WITHER_SKELETON_HURT;
|
| 51 | }
|
| 52 |
|
| 53 | @Override
|
| 54 | protected SoundEvent getDeathSound() {
|
| 55 | return SoundEvents.WITHER_SKELETON_DEATH;
|
| 56 | }
|
| 57 |
|
| 58 | @Override
|
| 59 | protected SoundEvent getStepSound() {
|
| 60 | return SoundEvents.WITHER_SKELETON_STEP;
|
| 61 | }
|
| 62 |
|
| 63 | @Override
|
| 64 | public TagKey<Item> getPreferredWeaponType() {
|
| 65 | return null;
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | public boolean canHoldItem(final ItemStack itemStack) {
|
| 70 | return !itemStack.is(ItemTags.WITHER_SKELETON_DISLIKED_WEAPONS) && super.canHoldItem(itemStack);
|
| 71 | }
|
| 72 |
|
| 73 | @Override
|
| 74 | protected void populateDefaultEquipmentSlots(final RandomSource random, final DifficultyInstance difficulty) {
|
| 75 | this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.STONE_SWORD));
|
| 76 | }
|
| 77 |
|
| 78 | @Override
|
| 79 | protected void populateDefaultEquipmentEnchantments(final ServerLevelAccessor level, final RandomSource random, final DifficultyInstance localDifficulty) {
|
| 80 | }
|
| 81 |
|
| 82 | @Override
|
| 83 | public @Nullable SpawnGroupData finalizeSpawn(
|
| 84 | final ServerLevelAccessor level, final DifficultyInstance difficulty, final EntitySpawnReason spawnReason, final @Nullable SpawnGroupData groupData
|
| 85 | ) {
|
| 86 | SpawnGroupData spawnGroupData = super.finalizeSpawn(level, difficulty, spawnReason, groupData);
|
| 87 | this.getAttribute(Attributes.ATTACK_DAMAGE).setBaseValue(4.0);
|
| 88 | this.reassessWeaponGoal();
|
| 89 | return spawnGroupData;
|
| 90 | }
|
| 91 |
|
| 92 | @Override
|
| 93 | public boolean doHurtTarget(final ServerLevel level, final Entity target) {
|
| 94 | if (!super.doHurtTarget(level, target)) {
|
| 95 | return false;
|
| 96 | }
|
| 97 |
|
| 98 | if (target instanceof LivingEntity livingEntity) {
|
| 99 | livingEntity.addEffect(new MobEffectInstance(MobEffects.WITHER, 200), this);
|
| 100 | }
|
| 101 |
|
| 102 | return true;
|
| 103 | }
|
| 104 |
|
| 105 | @Override
|
| 106 | protected AbstractArrow getArrow(final ItemStack projectile, final float power, final @Nullable ItemStack firingWeapon) {
|
| 107 | AbstractArrow arrow = super.getArrow(projectile, power, firingWeapon);
|
| 108 | arrow.igniteForSeconds(100.0F);
|
| 109 | return arrow;
|
| 110 | }
|
| 111 |
|
| 112 | @Override
|
| 113 | public boolean canBeAffected(final MobEffectInstance newEffect) {
|
| 114 | return newEffect.is(MobEffects.WITHER) ? false : super.canBeAffected(newEffect);
|
| 115 | }
|
| 116 | }
|
| 117 |
|