package net.minecraft.world.level.block;

import net.minecraft.world.level.block.state.AbstractStateHolder;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.StateDefinition;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import javax.annotation.Nullable;
import net.minecraft.world.item.BlockPlaceContext;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BooleanProperty;

public class RedstoneLampBlock extends Block {
    public static final BooleanProperty LIT;
    
    public RedstoneLampBlock(final Properties c) {
        super(c);
        this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)RedstoneLampBlock.LIT, false));
    }
    
    @Override
    public int getLightEmission(final BlockState byj) {
        return byj.<Boolean>getValue((Property<Boolean>)RedstoneLampBlock.LIT) ? super.getLightEmission(byj) : 0;
    }
    
    @Override
    public void onPlace(final BlockState byj1, final Level bjw, final BlockPos fk, final BlockState byj4, final boolean boolean5) {
        super.onPlace(byj1, bjw, fk, byj4, boolean5);
    }
    
    @Nullable
    @Override
    public BlockState getStateForPlacement(final BlockPlaceContext bcq) {
        return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Boolean>setValue((Property<Comparable>)RedstoneLampBlock.LIT, bcq.getLevel().hasNeighborSignal(bcq.getClickedPos()));
    }
    
    @Override
    public void neighborChanged(final BlockState byj, final Level bjw, final BlockPos fk3, final Block bph, final BlockPos fk5, final boolean boolean6) {
        if (bjw.isClientSide) {
            return;
        }
        final boolean boolean7 = byj.<Boolean>getValue((Property<Boolean>)RedstoneLampBlock.LIT);
        if (boolean7 != bjw.hasNeighborSignal(fk3)) {
            if (boolean7) {
                bjw.getBlockTicks().scheduleTick(fk3, this, 4);
            }
            else {
                bjw.setBlock(fk3, ((AbstractStateHolder<O, BlockState>)byj).<Comparable>cycle((Property<Comparable>)RedstoneLampBlock.LIT), 2);
            }
        }
    }
    
    @Override
    public void tick(final BlockState byj, final ServerLevel xd, final BlockPos fk, final Random random) {
        if (byj.<Boolean>getValue((Property<Boolean>)RedstoneLampBlock.LIT) && !xd.hasNeighborSignal(fk)) {
            xd.setBlock(fk, ((AbstractStateHolder<O, BlockState>)byj).<Comparable>cycle((Property<Comparable>)RedstoneLampBlock.LIT), 2);
        }
    }
    
    @Override
    protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
        a.add(RedstoneLampBlock.LIT);
    }
    
    @Override
    public boolean isValidSpawn(final BlockState byj, final BlockGetter bjg, final BlockPos fk, final EntityType<?> aku) {
        return true;
    }
    
    static {
        LIT = RedstoneTorchBlock.LIT;
    }
}
