package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.core.Direction;
import net.minecraft.world.item.Items;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public class PumpkinBlock extends StemGrownBlock {
    protected PumpkinBlock(final Properties c) {
        super(c);
    }
    
    @Override
    public InteractionResult use(final BlockState byj, final Level bjw, final BlockPos fk, final Player ayj, final InteractionHand ajk, final BlockHitResult cvg) {
        final ItemStack ben8 = ayj.getItemInHand(ajk);
        if (ben8.getItem() == Items.SHEARS) {
            if (!bjw.isClientSide) {
                final Direction fp9 = cvg.getDirection();
                final Direction fp10 = (fp9.getAxis() == Direction.Axis.Y) ? ayj.getDirection().getOpposite() : fp9;
                bjw.playSound(null, fk, SoundEvents.PUMPKIN_CARVE, SoundSource.BLOCKS, 1.0f, 1.0f);
                bjw.setBlock(fk, ((AbstractStateHolder<O, BlockState>)Blocks.CARVED_PUMPKIN.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)CarvedPumpkinBlock.FACING, fp10), 11);
                final ItemEntity awb11 = new ItemEntity(bjw, fk.getX() + 0.5 + fp10.getStepX() * 0.65, fk.getY() + 0.1, fk.getZ() + 0.5 + fp10.getStepZ() * 0.65, new ItemStack(Items.PUMPKIN_SEEDS, 4));
                awb11.setDeltaMovement(0.05 * fp10.getStepX() + bjw.random.nextDouble() * 0.02, 0.05, 0.05 * fp10.getStepZ() + bjw.random.nextDouble() * 0.02);
                bjw.addFreshEntity(awb11);
                ben8.<Player>hurtAndBreak(1, ayj, ayj -> ayj.broadcastBreakEvent(ajk));
            }
            return InteractionResult.SUCCESS;
        }
        return super.use(byj, bjw, fk, ayj, ajk, cvg);
    }
    
    @Override
    public StemBlock getStem() {
        return (StemBlock)Blocks.PUMPKIN_STEM;
    }
    
    @Override
    public AttachedStemBlock getAttachedStem() {
        return (AttachedStemBlock)Blocks.ATTACHED_PUMPKIN_STEM;
    }
}
