package com.dairymoose.modernlife.blocks;

import com.dairymoose.entity.DummyEntity;
import com.dairymoose.modernlife.tileentities.ToiletBlockEntity;
import com.dairymoose.modernlife.util.ModernLifeUtil;
import java.util.stream.Stream;
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.Items;
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.EntityBlock;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
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.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.WaterFluid;
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/ToiletBlock.class */
public class ToiletBlock extends StandardHorizontalBlock implements SimpleWaterloggedBlock, EntityBlock {
    public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
    protected static final VoxelShape SHAPE_SOUTH = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(10.5d, 0.0d, 5.0d, 11.5d, 1.0d, 13.0d), Block.box(5.5d, 0.0d, 14.0d, 6.5d, 1.0d, 15.0d), Block.box(9.5d, 0.0d, 14.0d, 10.5d, 1.0d, 15.0d), Block.box(10.5d, 0.0d, 13.0d, 11.5d, 1.0d, 14.0d), Block.box(4.5d, 0.0d, 13.0d, 5.5d, 1.0d, 14.0d), Block.box(9.5d, 0.0d, 3.0d, 10.5d, 1.0d, 4.0d), Block.box(5.5d, 0.0d, 3.0d, 6.5d, 1.0d, 4.0d), Block.box(4.5d, 0.0d, 4.0d, 5.5d, 1.0d, 5.0d), Block.box(10.5d, 0.0d, 4.0d, 11.5d, 1.0d, 5.0d), Block.box(6.5d, 0.0d, 2.0d, 9.5d, 1.0d, 3.0d), Block.box(6.5d, 0.0d, 15.0d, 9.5d, 1.0d, 16.0d), Block.box(11.5d, 0.0d, 11.0d, 12.5d, 1.0d, 13.0d), Block.box(3.5d, 0.0d, 11.0d, 4.5d, 1.0d, 13.0d), Block.box(11.5d, 0.0d, 11.0d, 12.5d, 1.0d, 13.0d), Block.box(12.5d, 0.0d, 7.0d, 13.5d, 1.0d, 11.0d), Block.box(2.5d, 0.0d, 7.0d, 3.5d, 1.0d, 11.0d), Block.box(3.5d, 0.0d, 5.0d, 4.5d, 1.0d, 7.0d), Block.box(11.5d, 0.0d, 5.0d, 12.5d, 1.0d, 7.0d), Block.box(5.5d, 1.0d, 13.0d, 6.5d, 3.0d, 14.0d), Block.box(6.5d, 1.0d, 14.0d, 9.5d, 3.0d, 15.0d), Block.box(9.5d, 1.0d, 13.0d, 10.5d, 3.0d, 14.0d), Block.box(10.5d, 1.0d, 12.0d, 11.5d, 3.0d, 13.0d), Block.box(11.5d, 1.0d, 6.0d, 12.5d, 3.0d, 11.0d), Block.box(11.5d, 1.0d, 11.0d, 12.5d, 3.0d, 13.0d), Block.box(4.5d, 1.0d, 12.0d, 5.5d, 3.0d, 13.0d), Block.box(9.5d, 1.0d, 4.0d, 10.5d, 3.0d, 5.0d), Block.box(5.5d, 1.0d, 4.0d, 6.5d, 3.0d, 5.0d), Block.box(6.5d, 1.0d, 3.0d, 9.5d, 3.0d, 4.0d), Block.box(4.5d, 1.0d, 5.0d, 5.5d, 3.0d, 6.0d), Block.box(3.5d, 1.0d, 6.0d, 4.5d, 3.0d, 11.0d), Block.box(10.5d, 1.0d, 5.0d, 11.5d, 3.0d, 6.0d), Block.box(3.5d, 1.0d, 11.0d, 4.5d, 3.0d, 13.0d), Block.box(5.5d, 3.0d, 12.0d, 6.5d, 6.0d, 13.0d), Block.box(6.5d, 3.0d, 13.0d, 9.5d, 6.0d, 14.0d), Block.box(9.5d, 3.0d, 12.0d, 10.5d, 6.0d, 13.0d), Block.box(10.5d, 3.0d, 11.0d, 11.5d, 6.0d, 12.0d), Block.box(10.5d, 3.0d, 6.0d, 11.5d, 6.0d, 11.0d), Block.box(4.5d, 3.0d, 11.0d, 5.5d, 6.0d, 12.0d), Block.box(9.5d, 3.0d, 5.0d, 10.5d, 6.0d, 6.0d), Block.box(5.5d, 3.0d, 5.0d, 6.5d, 6.0d, 6.0d), Block.box(6.5d, 3.0d, 4.0d, 9.5d, 6.0d, 6.0d), Block.box(4.5d, 3.0d, 6.0d, 5.5d, 6.0d, 11.0d), Block.box(4.0d, 8.0d, 0.0d, 12.0d, 15.0d, 4.0d), Block.box(6.0d, 4.0d, 0.0d, 10.0d, 8.0d, 3.0d), Block.box(6.0d, 4.0d, 3.0d, 10.0d, 6.0d, 4.0d), Block.box(4.25d, 13.5d, 4.0d, 5.25d, 14.5d, 5.0d), Block.box(3.0d, 15.0d, 0.0d, 13.0d, 16.0d, 5.0d), Block.box(5.5d, 3.0d, 12.0d, 6.5d, 6.0d, 13.0d), Block.box(6.5d, 3.0d, 13.0d, 9.5d, 6.0d, 14.0d), Block.box(9.5d, 3.0d, 12.0d, 10.5d, 6.0d, 13.0d), Block.box(10.5d, 3.0d, 11.0d, 11.5d, 6.0d, 12.0d), Block.box(10.5d, 3.0d, 6.0d, 11.5d, 6.0d, 11.0d), Block.box(4.5d, 3.0d, 11.0d, 5.5d, 6.0d, 12.0d), Block.box(9.5d, 3.0d, 5.0d, 10.5d, 6.0d, 6.0d), Block.box(5.5d, 3.0d, 5.0d, 6.5d, 6.0d, 6.0d), Block.box(6.5d, 3.0d, 4.0d, 9.5d, 6.0d, 5.0d), Block.box(4.5d, 3.0d, 6.0d, 5.5d, 6.0d, 11.0d), Block.box(2.25d, 13.75d, 4.0d, 4.25d, 14.25d, 5.0d), Block.box(5.0d, 6.0d, 6.0d, 11.0d, 7.0d, 13.0d), Block.box(5.25d, 7.0d, 6.0d, 10.75d, 14.0d, 6.5d), Block.box(5.5d, 0.0d, 4.0d, 10.5d, 1.0d, 14.0d), Block.box(4.5d, 0.0d, 5.0d, 5.5d, 1.0d, 13.0d), Block.box(5.5d, 1.0d, 5.0d, 10.5d, 3.0d, 13.0d), Block.box(5.25d, 6.0d, 6.25d, 5.5d, 6.9d, 12.75d), Block.box(10.5d, 6.0d, 6.25d, 10.75d, 6.9d, 12.75d), Block.box(5.25d, 6.0d, 12.5d, 10.75d, 6.9d, 12.75d), Block.box(5.25d, 6.0d, 6.25d, 10.75d, 6.9d, 6.5d)}).reduce((v1, v2) -> {
        return Shapes.join(v1, v2, BooleanOp.OR);
    }).get();
    protected static final VoxelShape SHAPE_WEST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_SOUTH);
    protected static final VoxelShape SHAPE_NORTH = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_WEST);
    protected static final VoxelShape SHAPE_EAST = ModernLifeUtil.RotateVoxelShapeClockwise(SHAPE_NORTH);
    public static long lastFlushTimestampServer = 0;
    public static long lastFlushTimestampClient = 0;

    public ToiletBlock(Properties p_i48377_1_) {
        super(p_i48377_1_);
        registerDefaultState((BlockState) ((BlockState) defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, Direction.NORTH)).setValue(WATERLOGGED, false));
    }

    public BlockState updateShape(BlockState p_196271_1_, Direction p_196271_2_, BlockState p_196271_3_, LevelAccessor p_196271_4_, BlockPos p_196271_5_, BlockPos p_196271_6_) {
        if (((Boolean) p_196271_1_.getValue(WATERLOGGED)).booleanValue()) {
            p_196271_4_.scheduleTick(p_196271_5_, Fluids.WATER, Fluids.WATER.getTickDelay(p_196271_4_));
        }
        return super.updateShape(p_196271_1_, p_196271_2_, p_196271_3_, p_196271_4_, p_196271_5_, p_196271_6_);
    }

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

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

    @Override // com.dairymoose.modernlife.blocks.StandardHorizontalBlock
    public BlockState getStateForPlacement(BlockPlaceContext context) {
        BlockState superState = super.getStateForPlacement(context);
        if (superState == null) {
            superState = defaultBlockState();
        }
        BlockState state = context.getLevel().getBlockState(context.getClickedPos());
        if ((state.getFluidState().getType() instanceof WaterFluid) && state.getFluidState().isSource()) {
            superState.setValue(WATERLOGGED, true);
        }
        return superState;
    }

    public FluidState getFluidState(BlockState p_204507_1_) {
        if (((Boolean) p_204507_1_.getValue(WATERLOGGED)).booleanValue()) {
            return Fluids.WATER.getSource(false);
        }
        return super.getFluidState(p_204507_1_);
    }

    @Override // com.dairymoose.modernlife.blocks.StandardHorizontalBlock
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        builder.add(new Property[]{HorizontalDirectionalBlock.FACING, WATERLOGGED});
    }

    public InteractionResult use(BlockState blockState, Level world, BlockPos pos, Player Player, InteractionHand hand, BlockHitResult rayTrace) {
        if (Player.getMainHandItem() != null && Player.getMainHandItem().getItem() != Items.BUCKET) {
            if (Player.isSteppingCarefully()) {
                BlockEntity tileEntity = world.getBlockEntity(pos);
                if (tileEntity instanceof ToiletBlockEntity) {
                    ToiletBlockEntity toiletEntity = (ToiletBlockEntity) tileEntity;
                    toiletEntity.flush(blockState, world, pos, Player, hand, rayTrace);
                    return InteractionResult.CONSUME;
                }
            } else if (!world.isClientSide) {
                DummyEntity dummy = DummyEntity.getEntity(0.22f, world, pos, false);
                dummy.ride(Player);
            }
        }
        return super.use(blockState, world, pos, Player, hand, rayTrace);
    }

    /* renamed from: com.dairymoose.modernlife.blocks.ToiletBlock$1 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/ToiletBlock$1.class */
    static /* synthetic */ class C00631 {
        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 (C00631.$SwitchMap$net$minecraft$core$Direction[bs.getValue(HorizontalDirectionalBlock.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;
        }
    }
}
