153 lines
5.3 KiB
Java
153 lines
5.3 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package net.minecraft.world.entity.monster;
|
|
|
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
|
import net.minecraft.network.syncher.SynchedEntityData;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.sounds.SoundEvent;
|
|
import net.minecraft.sounds.SoundEvents;
|
|
import net.minecraft.sounds.SoundSource;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.InteractionResult;
|
|
import net.minecraft.world.damagesource.DamageSource;
|
|
import net.minecraft.world.effect.MobEffectInstance;
|
|
import net.minecraft.world.effect.MobEffects;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.Shearable;
|
|
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
|
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
|
import net.minecraft.world.entity.monster.AbstractSkeleton;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.entity.projectile.AbstractArrow;
|
|
import net.minecraft.world.entity.projectile.Arrow;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
|
import net.minecraft.world.level.storage.ValueInput;
|
|
import net.minecraft.world.level.storage.ValueOutput;
|
|
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public class Bogged
|
|
extends AbstractSkeleton
|
|
implements Shearable {
|
|
private static final EntityDataAccessor<Boolean> DATA_SHEARED = SynchedEntityData.defineId(Bogged.class, EntityDataSerializers.BOOLEAN);
|
|
private static final String SHEARED_TAG_NAME = "sheared";
|
|
private static final boolean DEFAULT_SHEARED = false;
|
|
|
|
public static AttributeSupplier.Builder createAttributes() {
|
|
return AbstractSkeleton.createAttributes().add(Attributes.MAX_HEALTH, 16.0);
|
|
}
|
|
|
|
public Bogged(EntityType<? extends Bogged> type, Level level) {
|
|
super((EntityType<? extends AbstractSkeleton>)type, level);
|
|
}
|
|
|
|
@Override
|
|
protected void defineSynchedData(SynchedEntityData.Builder entityData) {
|
|
super.defineSynchedData(entityData);
|
|
entityData.define(DATA_SHEARED, false);
|
|
}
|
|
|
|
@Override
|
|
protected void addAdditionalSaveData(ValueOutput output) {
|
|
super.addAdditionalSaveData(output);
|
|
output.putBoolean(SHEARED_TAG_NAME, this.isSheared());
|
|
}
|
|
|
|
@Override
|
|
protected void readAdditionalSaveData(ValueInput input) {
|
|
super.readAdditionalSaveData(input);
|
|
this.setSheared(input.getBooleanOr(SHEARED_TAG_NAME, false));
|
|
}
|
|
|
|
public boolean isSheared() {
|
|
return this.entityData.get(DATA_SHEARED);
|
|
}
|
|
|
|
public void setSheared(boolean sheared) {
|
|
this.entityData.set(DATA_SHEARED, sheared);
|
|
}
|
|
|
|
@Override
|
|
protected InteractionResult mobInteract(Player player, InteractionHand hand) {
|
|
ItemStack itemStack = player.getItemInHand(hand);
|
|
if (itemStack.is(Items.SHEARS) && this.readyForShearing()) {
|
|
Level level = this.level();
|
|
if (level instanceof ServerLevel) {
|
|
ServerLevel level2 = (ServerLevel)level;
|
|
this.shear(level2, SoundSource.PLAYERS, itemStack);
|
|
this.gameEvent(GameEvent.SHEAR, player);
|
|
itemStack.hurtAndBreak(1, (LivingEntity)player, hand.asEquipmentSlot());
|
|
}
|
|
return InteractionResult.SUCCESS;
|
|
}
|
|
return super.mobInteract(player, hand);
|
|
}
|
|
|
|
@Override
|
|
protected SoundEvent getAmbientSound() {
|
|
return SoundEvents.BOGGED_AMBIENT;
|
|
}
|
|
|
|
@Override
|
|
protected SoundEvent getHurtSound(DamageSource source) {
|
|
return SoundEvents.BOGGED_HURT;
|
|
}
|
|
|
|
@Override
|
|
protected SoundEvent getDeathSound() {
|
|
return SoundEvents.BOGGED_DEATH;
|
|
}
|
|
|
|
@Override
|
|
protected SoundEvent getStepSound() {
|
|
return SoundEvents.BOGGED_STEP;
|
|
}
|
|
|
|
@Override
|
|
protected AbstractArrow getArrow(ItemStack projectile, float power, @Nullable ItemStack firingWeapon) {
|
|
AbstractArrow abstractArrow = super.getArrow(projectile, power, firingWeapon);
|
|
if (abstractArrow instanceof Arrow) {
|
|
Arrow arrow = (Arrow)abstractArrow;
|
|
arrow.addEffect(new MobEffectInstance(MobEffects.POISON, 100));
|
|
}
|
|
return abstractArrow;
|
|
}
|
|
|
|
@Override
|
|
protected int getHardAttackInterval() {
|
|
return 50;
|
|
}
|
|
|
|
@Override
|
|
protected int getAttackInterval() {
|
|
return 70;
|
|
}
|
|
|
|
@Override
|
|
public void shear(ServerLevel level, SoundSource soundSource, ItemStack tool) {
|
|
level.playSound(null, this, SoundEvents.BOGGED_SHEAR, soundSource, 1.0f, 1.0f);
|
|
this.spawnShearedMushrooms(level, tool);
|
|
this.setSheared(true);
|
|
}
|
|
|
|
private void spawnShearedMushrooms(ServerLevel level, ItemStack tool) {
|
|
this.dropFromShearingLootTable(level, BuiltInLootTables.BOGGED_SHEAR, tool, (l, drop) -> this.spawnAtLocation((ServerLevel)l, (ItemStack)drop, this.getBbHeight()));
|
|
}
|
|
|
|
@Override
|
|
public boolean readyForShearing() {
|
|
return !this.isSheared() && this.isAlive();
|
|
}
|
|
}
|
|
|