package com.dairymoose.modernlife.blocks;

import com.dairymoose.entity.DummyEntity;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;

/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/MiniStoolBlock.class */
public class MiniStoolBlock extends Block {
    protected static final VoxelShape SHAPE_NORMAL = (VoxelShape) Stream.of(Block.box(2.0d, 0.0d, 2.0d, 14.0d, 9.0d, 14.0d)).reduce((v1, v2) -> {
        return Shapes.join(v1, v2, BooleanOp.OR);
    }).get();
    protected static final VoxelShape SHAPE_EXTENDED = (VoxelShape) Stream.of(Block.box(2.0d, 0.0d, 2.0d, 14.0d, 16.0d, 14.0d)).reduce((v1, v2) -> {
        return Shapes.join(v1, v2, BooleanOp.OR);
    }).get();
    public static final BooleanProperty EXTENDED = BlockStateProperties.EXTENDED;

    public MiniStoolBlock(Properties p_i48377_1_) {
        super(p_i48377_1_);
        registerDefaultState((BlockState) defaultBlockState().setValue(EXTENDED, false));
    }

    public int getFlammability(BlockState state, BlockGetter world, BlockPos pos, Direction face) {
        if (this.material.isFlammable()) {
            return 20;
        }
        return 0;
    }

    public int getFireSpreadSpeed(BlockState state, BlockGetter world, BlockPos pos, Direction face) {
        if (this.material.isFlammable()) {
            return 5;
        }
        return 0;
    }

    public BlockState updateShape(BlockState state, Direction dir, BlockState updater, LevelAccessor world, BlockPos pos, BlockPos updaterPos) {
        if (!world.getBlockState(pos.above()).isAir()) {
            return (BlockState) defaultBlockState().setValue(EXTENDED, true);
        }
        return defaultBlockState();
    }

    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        builder.add(new Property[]{EXTENDED});
    }

    public InteractionResult use(BlockState p_225533_1_, Level p_225533_2_, BlockPos p_225533_3_, Player player, InteractionHand p_225533_5_, BlockHitResult p_225533_6_) {
        if (!p_225533_2_.isClientSide) {
            DummyEntity dummy = DummyEntity.getEntity(0.4f, p_225533_2_, p_225533_3_, false);
            dummy.ride(player);
        }
        return InteractionResult.CONSUME;
    }

    @Nullable
    public BlockState getStateForPlacement(BlockPlaceContext context) {
        if (!context.getLevel().getBlockState(context.getClickedPos().above()).isAir()) {
            return (BlockState) defaultBlockState().setValue(EXTENDED, true);
        }
        return defaultBlockState();
    }

    public VoxelShape getShape(BlockState bs, BlockGetter reader, BlockPos pos, CollisionContext sel) {
        if (((Boolean) bs.getValue(EXTENDED)).booleanValue()) {
            return SHAPE_EXTENDED;
        }
        return SHAPE_NORMAL;
    }
}
