package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.Container;
import net.minecraft.world.Containers;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.BlockPlaceContext;
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.properties.Property;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;

public abstract class AbstractFurnaceBlock extends BaseEntityBlock {
    public static final DirectionProperty FACING;
    public static final BooleanProperty LIT;
    
    protected AbstractFurnaceBlock(final Properties c) {
        super(c);
        this.registerDefaultState((((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).setValue((Property<Comparable>)AbstractFurnaceBlock.FACING, Direction.NORTH)).<Comparable, Boolean>setValue((Property<Comparable>)AbstractFurnaceBlock.LIT, false));
    }
    
    @Override
    public int getLightEmission(final BlockState byj) {
        return byj.<Boolean>getValue((Property<Boolean>)AbstractFurnaceBlock.LIT) ? super.getLightEmission(byj) : 0;
    }
    
    @Override
    public InteractionResult use(final BlockState byj, final Level bjw, final BlockPos fk, final Player ayj, final InteractionHand ajk, final BlockHitResult cvg) {
        if (bjw.isClientSide) {
            return InteractionResult.SUCCESS;
        }
        this.openContainer(bjw, fk, ayj);
        return InteractionResult.SUCCESS;
    }
    
    protected abstract void openContainer(final Level bjw, final BlockPos fk, final Player ayj);
    
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)AbstractFurnaceBlock.FACING, bcq.getHorizontalDirection().getOpposite());
    }
    
    @Override
    public void setPlacedBy(final Level bjw, final BlockPos fk, final BlockState byj, final LivingEntity akz, final ItemStack ben) {
        if (ben.hasCustomHoverName()) {
            final BlockEntity bwl7 = bjw.getBlockEntity(fk);
            if (bwl7 instanceof AbstractFurnaceBlockEntity) {
                ((AbstractFurnaceBlockEntity)bwl7).setCustomName(ben.getHoverName());
            }
        }
    }
    
    @Override
    public void onRemove(final BlockState byj1, final Level bjw, final BlockPos fk, final BlockState byj4, final boolean boolean5) {
        if (byj1.getBlock() == byj4.getBlock()) {
            return;
        }
        final BlockEntity bwl7 = bjw.getBlockEntity(fk);
        if (bwl7 instanceof AbstractFurnaceBlockEntity) {
            Containers.dropContents(bjw, fk, (Container)bwl7);
            bjw.updateNeighbourForOutputSignal(fk, this);
        }
        super.onRemove(byj1, bjw, fk, byj4, boolean5);
    }
    
    @Override
    public boolean hasAnalogOutputSignal(final BlockState byj) {
        return true;
    }
    
    @Override
    public int getAnalogOutputSignal(final BlockState byj, final Level bjw, final BlockPos fk) {
        return AbstractContainerMenu.getRedstoneSignalFromBlockEntity(bjw.getBlockEntity(fk));
    }
    
    @Override
    public RenderShape getRenderShape(final BlockState byj) {
        return RenderShape.MODEL;
    }
    
    @Override
    public BlockState rotate(final BlockState byj, final Rotation btu) {
        return ((AbstractStateHolder<O, BlockState>)byj).<Comparable, Direction>setValue((Property<Comparable>)AbstractFurnaceBlock.FACING, btu.rotate(byj.<Direction>getValue((Property<Direction>)AbstractFurnaceBlock.FACING)));
    }
    
    @Override
    public BlockState mirror(final BlockState byj, final Mirror bsu) {
        return byj.rotate(bsu.getRotation(byj.<Direction>getValue((Property<Direction>)AbstractFurnaceBlock.FACING)));
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(AbstractFurnaceBlock.FACING, AbstractFurnaceBlock.LIT);
    }
    
    static {
        FACING = HorizontalDirectionalBlock.FACING;
        LIT = RedstoneTorchBlock.LIT;
    }
}
