package net.minecraft.world.level.block;

import com.google.common.collect.Maps;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Direction;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.ItemStack;
import net.minecraft.stats.Stats;
import net.minecraft.world.item.BlockItem;
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.world.level.Level;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.phys.shapes.VoxelShape;
import java.util.Map;

public class FlowerPotBlock extends Block {
    private static final Map<Block, Block> POTTED_BY_CONTENT;
    protected static final VoxelShape SHAPE;
    private final Block content;
    
    public FlowerPotBlock(final Block bvr, final Properties c) {
        super(c);
        this.content = bvr;
        FlowerPotBlock.POTTED_BY_CONTENT.put(bvr, this);
    }
    
    @Override
    public VoxelShape getShape(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final CollisionContext der) {
        return FlowerPotBlock.SHAPE;
    }
    
    @Override
    public RenderShape getRenderShape(final BlockState cfj) {
        return RenderShape.MODEL;
    }
    
    @Override
    public InteractionResult use(final BlockState cfj, final Level bqb, final BlockPos fu, final Player bec, final InteractionHand anf, final BlockHitResult deh) {
        final ItemStack bki8 = bec.getItemInHand(anf);
        final Item bke9 = bki8.getItem();
        final Block bvr10 = (bke9 instanceof BlockItem) ? FlowerPotBlock.POTTED_BY_CONTENT.getOrDefault(((BlockItem)bke9).getBlock(), Blocks.AIR) : Blocks.AIR;
        final boolean boolean11 = bvr10 == Blocks.AIR;
        final boolean boolean12 = this.content == Blocks.AIR;
        if (boolean11 != boolean12) {
            if (boolean12) {
                bqb.setBlock(fu, bvr10.defaultBlockState(), 3);
                bec.awardStat(Stats.POT_FLOWER);
                if (!bec.abilities.instabuild) {
                    bki8.shrink(1);
                }
            }
            else {
                final ItemStack bki9 = new ItemStack(this.content);
                if (bki8.isEmpty()) {
                    bec.setItemInHand(anf, bki9);
                }
                else if (!bec.addItem(bki9)) {
                    bec.drop(bki9, false);
                }
                bqb.setBlock(fu, Blocks.FLOWER_POT.defaultBlockState(), 3);
            }
            return InteractionResult.sidedSuccess(bqb.isClientSide);
        }
        return InteractionResult.CONSUME;
    }
    
    @Override
    public ItemStack getCloneItemStack(final BlockGetter bpg, final BlockPos fu, final BlockState cfj) {
        if (this.content == Blocks.AIR) {
            return super.getCloneItemStack(bpg, fu, cfj);
        }
        return new ItemStack(this.content);
    }
    
    @Override
    public BlockState updateShape(final BlockState cfj1, final Direction fz, final BlockState cfj3, final LevelAccessor bqc, final BlockPos fu5, final BlockPos fu6) {
        if (fz == Direction.DOWN && !cfj1.canSurvive(bqc, fu5)) {
            return Blocks.AIR.defaultBlockState();
        }
        return super.updateShape(cfj1, fz, cfj3, bqc, fu5, fu6);
    }
    
    public Block getContent() {
        return this.content;
    }
    
    @Override
    public boolean isPathfindable(final BlockState cfj, final BlockGetter bpg, final BlockPos fu, final PathComputationType czg) {
        return false;
    }
    
    static {
        POTTED_BY_CONTENT = Maps.newHashMap();
        SHAPE = Block.box(5.0, 0.0, 5.0, 11.0, 6.0, 11.0);
    }
}
