| 1 | package net.minecraft.world.entity.monster.skeleton;
|
| 2 |
|
| 3 | import net.minecraft.network.syncher.EntityDataAccessor;
|
| 4 | import net.minecraft.network.syncher.EntityDataSerializers;
|
| 5 | import net.minecraft.network.syncher.SynchedEntityData;
|
| 6 | import net.minecraft.server.level.ServerLevel;
|
| 7 | import net.minecraft.sounds.SoundEvent;
|
| 8 | import net.minecraft.sounds.SoundEvents;
|
| 9 | import net.minecraft.sounds.SoundSource;
|
| 10 | import net.minecraft.world.InteractionHand;
|
| 11 | import net.minecraft.world.InteractionResult;
|
| 12 | import net.minecraft.world.damagesource.DamageSource;
|
| 13 | import net.minecraft.world.effect.MobEffectInstance;
|
| 14 | import net.minecraft.world.effect.MobEffects;
|
| 15 | import net.minecraft.world.entity.EntityType;
|
| 16 | import net.minecraft.world.entity.Shearable;
|
| 17 | import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
| 18 | import net.minecraft.world.entity.ai.attributes.Attributes;
|
| 19 | import net.minecraft.world.entity.player.Player;
|
| 20 | import net.minecraft.world.entity.projectile.arrow.AbstractArrow;
|
| 21 | import net.minecraft.world.entity.projectile.arrow.Arrow;
|
| 22 | import net.minecraft.world.item.ItemStack;
|
| 23 | import net.minecraft.world.item.Items;
|
| 24 | import net.minecraft.world.level.Level;
|
| 25 | import net.minecraft.world.level.gameevent.GameEvent;
|
| 26 | import net.minecraft.world.level.storage.ValueInput;
|
| 27 | import net.minecraft.world.level.storage.ValueOutput;
|
| 28 | import net.minecraft.world.level.storage.loot.BuiltInLootTables;
|
| 29 | import org.jspecify.annotations.Nullable;
|
| 30 |
|
| 31 | public class Bogged extends AbstractSkeleton implements Shearable {
|
| 32 | private static final EntityDataAccessor<Boolean> DATA_SHEARED = SynchedEntityData.defineId(Bogged.class, EntityDataSerializers.BOOLEAN);
|
| 33 | private static final String SHEARED_TAG_NAME = "sheared";
|
| 34 | private static final boolean DEFAULT_SHEARED = false;
|
| 35 |
|
| 36 | public static AttributeSupplier.Builder createAttributes() {
|
| 37 | return AbstractSkeleton.createAttributes().add(Attributes.MAX_HEALTH, 16.0);
|
| 38 | }
|
| 39 |
|
| 40 | public Bogged(final EntityType<? extends Bogged> type, final Level level) {
|
| 41 | super(type, level);
|
| 42 | }
|
| 43 |
|
| 44 | @Override
|
| 45 | protected void defineSynchedData(final SynchedEntityData.Builder entityData) {
|
| 46 | super.defineSynchedData(entityData);
|
| 47 | entityData.define(DATA_SHEARED, false);
|
| 48 | }
|
| 49 |
|
| 50 | @Override
|
| 51 | protected void addAdditionalSaveData(final ValueOutput output) {
|
| 52 | super.addAdditionalSaveData(output);
|
| 53 | output.putBoolean("sheared", this.isSheared());
|
| 54 | }
|
| 55 |
|
| 56 | @Override
|
| 57 | protected void readAdditionalSaveData(final ValueInput input) {
|
| 58 | super.readAdditionalSaveData(input);
|
| 59 | this.setSheared(input.getBooleanOr("sheared", false));
|
| 60 | }
|
| 61 |
|
| 62 | public boolean isSheared() {
|
| 63 | return this.entityData.get(DATA_SHEARED);
|
| 64 | }
|
| 65 |
|
| 66 | public void setSheared(final boolean sheared) {
|
| 67 | this.entityData.set(DATA_SHEARED, sheared);
|
| 68 | }
|
| 69 |
|
| 70 | @Override
|
| 71 | protected InteractionResult mobInteract(final Player player, final InteractionHand hand) {
|
| 72 | ItemStack itemStack = player.getItemInHand(hand);
|
| 73 | if (itemStack.is(Items.SHEARS) && this.readyForShearing()) {
|
| 74 | if (this.level() instanceof ServerLevel level) {
|
| 75 | this.shear(level, SoundSource.PLAYERS, itemStack);
|
| 76 | this.gameEvent(GameEvent.SHEAR, player);
|
| 77 | itemStack.hurtAndBreak(1, player, hand.asEquipmentSlot());
|
| 78 | }
|
| 79 |
|
| 80 | return InteractionResult.SUCCESS;
|
| 81 | } else {
|
| 82 | return super.mobInteract(player, hand);
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | protected SoundEvent getAmbientSound() {
|
| 88 | return SoundEvents.BOGGED_AMBIENT;
|
| 89 | }
|
| 90 |
|
| 91 | @Override
|
| 92 | protected SoundEvent getHurtSound(final DamageSource source) {
|
| 93 | return SoundEvents.BOGGED_HURT;
|
| 94 | }
|
| 95 |
|
| 96 | @Override
|
| 97 | protected SoundEvent getDeathSound() {
|
| 98 | return SoundEvents.BOGGED_DEATH;
|
| 99 | }
|
| 100 |
|
| 101 | @Override
|
| 102 | protected SoundEvent getStepSound() {
|
| 103 | return SoundEvents.BOGGED_STEP;
|
| 104 | }
|
| 105 |
|
| 106 | @Override
|
| 107 | protected AbstractArrow getArrow(final ItemStack projectile, final float power, final @Nullable ItemStack firingWeapon) {
|
| 108 | AbstractArrow abstractArrow = super.getArrow(projectile, power, firingWeapon);
|
| 109 | if (abstractArrow instanceof Arrow arrow) {
|
| 110 | arrow.addEffect(new MobEffectInstance(MobEffects.POISON, 100));
|
| 111 | }
|
| 112 |
|
| 113 | return abstractArrow;
|
| 114 | }
|
| 115 |
|
| 116 | @Override
|
| 117 | protected int getHardAttackInterval() {
|
| 118 | return 50;
|
| 119 | }
|
| 120 |
|
| 121 | @Override
|
| 122 | protected int getAttackInterval() {
|
| 123 | return 70;
|
| 124 | }
|
| 125 |
|
| 126 | @Override
|
| 127 | public void shear(final ServerLevel level, final SoundSource soundSource, final ItemStack tool) {
|
| 128 | level.playSound(null, this, SoundEvents.BOGGED_SHEAR, soundSource, 1.0F, 1.0F);
|
| 129 | this.spawnShearedMushrooms(level, tool);
|
| 130 | this.setSheared(true);
|
| 131 | }
|
| 132 |
|
| 133 | private void spawnShearedMushrooms(final ServerLevel level, final ItemStack tool) {
|
| 134 | this.dropFromShearingLootTable(level, BuiltInLootTables.BOGGED_SHEAR, tool, (l, drop) -> this.spawnAtLocation(l, drop, this.getBbHeight()));
|
| 135 | }
|
| 136 |
|
| 137 | @Override
|
| 138 | public boolean readyForShearing() {
|
| 139 | return !this.isSheared();
|
| 140 | }
|
| 141 | }
|
| 142 |
|