package com.dairymoose.modernlife.blocks;

import com.dairymoose.modernlife.tileentities.ShowerHeadBlockEntity;
import com.dairymoose.modernlife.util.ModernLifeUtil;
import java.util.stream.Stream;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
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.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/ShowerHeadBlock.class */
public class ShowerHeadBlock extends AbstractWallBlock implements EntityBlock {
    protected static final VoxelShape SHAPE_NORTH = (VoxelShape) Stream.of(Block.box(6.5d, 9.0d, 10.75d, 9.5d, 12.0d, 16.0d)).reduce((v1, v2) -> {
        return Shapes.join(v1, v2, BooleanOp.OR);
    }).get();
    protected static final VoxelShape SHAPE_EAST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH);
    protected static final VoxelShape SHAPE_SOUTH = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_EAST);
    protected static final VoxelShape SHAPE_WEST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH);

    public ShowerHeadBlock(Properties props) {
        super(props);
        registerDefaultState((BlockState) this.stateDefinition.any().setValue(AbstractWallBlock.FACING, Direction.SOUTH));
    }

    public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> type) {
        return ModernLifeUtil.createTickerHelper(type, ShowerHeadBlockEntity.SHOWER_HEAD, ShowerHeadBlockEntity::tick);
    }

    public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
        return ShowerHeadBlockEntity.SHOWER_HEAD.create(pos, state);
    }

    public InteractionResult use(BlockState blockState, Level world, BlockPos pos, Player Player, InteractionHand hand, BlockHitResult rayTrace) {
        BlockEntity tileEntity = world.getBlockEntity(pos);
        if (tileEntity instanceof ShowerHeadBlockEntity) {
            ShowerHeadBlockEntity showerHead = (ShowerHeadBlockEntity) tileEntity;
            if (!showerHead.isRunning()) {
                showerHead.startRunning();
            } else {
                showerHead.stopRunning();
            }
            if (!world.isClientSide) {
                ((ServerLevel) world).sendBlockUpdated(pos, blockState, blockState, 2);
            }
        }
        return InteractionResult.CONSUME;
    }

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

    /* renamed from: com.dairymoose.modernlife.blocks.ShowerHeadBlock$1 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/ShowerHeadBlock$1.class */
    static /* synthetic */ class C00561 {
        static final /* synthetic */ int[] $SwitchMap$net$minecraft$core$Direction = new int[Direction.values().length];

        static {
            try {
                $SwitchMap$net$minecraft$core$Direction[Direction.NORTH.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                $SwitchMap$net$minecraft$core$Direction[Direction.SOUTH.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                $SwitchMap$net$minecraft$core$Direction[Direction.EAST.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                $SwitchMap$net$minecraft$core$Direction[Direction.WEST.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
        }
    }

    public VoxelShape getShape(BlockState bs, BlockGetter reader, BlockPos pos, CollisionContext sel) {
        switch (C00561.$SwitchMap$net$minecraft$core$Direction[bs.getValue(AbstractWallBlock.FACING).ordinal()]) {
            case 1:
                return SHAPE_NORTH;
            case 2:
                return SHAPE_SOUTH;
            case 3:
                return SHAPE_EAST;
            case 4:
                return SHAPE_WEST;
            default:
                return SHAPE_NORTH;
        }
    }
}
