package com.dairymoose.modernlife.blocks;

import com.dairymoose.modernlife.blocks.gui.PhotocopierScreen;
import com.dairymoose.modernlife.core.CustomBlocks;
import com.dairymoose.modernlife.tileentities.PhotocopierBlockEntity;
import com.dairymoose.modernlife.util.ModernLifeUtil;
import java.util.List;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
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.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;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;

/* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/PhotocopierBlock.class */
public class PhotocopierBlock extends StandardHorizontalBlock implements EntityBlock {
    protected static final VoxelShape SHAPE_NORTH = (VoxelShape) Stream.of((Object[]) new VoxelShape[]{Block.box(1.75d, 14.275d, 1.0d, 4.5d, 14.275d, 2.5d), Block.box(0.0d, 1.0d, 1.0d, 16.0d, 2.0d, 16.0d), Block.box(0.0d, 2.0d, 0.0d, 16.0d, 3.0d, 16.0d), Block.box(0.0d, 3.0d, 1.0d, 16.0d, 4.0d, 16.0d), Block.box(0.0d, 4.0d, 0.0d, 16.0d, 5.0d, 16.0d), Block.box(0.0d, 5.0d, 1.0d, 16.0d, 6.0d, 16.0d), Block.box(0.0d, 6.0d, 0.0d, 16.0d, 7.0d, 16.0d), Block.box(0.0d, 7.0d, 1.0d, 16.0d, 8.0d, 16.0d), Block.box(0.0d, 8.0d, 14.0d, 16.0d, 10.0d, 16.0d), Block.box(0.0d, 8.0d, 0.0d, 16.0d, 9.0d, 3.0d), Block.box(0.0d, 9.0d, 1.0d, 16.0d, 10.0d, 3.0d), Block.box(0.0d, 10.0d, 0.0d, 16.0d, 14.0d, 16.0d), Block.box(0.0d, 14.25d, 3.0d, 16.0d, 15.5d, 16.0d), Block.box(0.0d, 14.0d, 14.25d, 16.0d, 14.25d, 16.0d), Block.box(10.0d, 15.5d, 3.0d, 16.0d, 16.0d, 16.0d), Block.box(0.0d, 0.0d, 1.0d, 1.0d, 1.0d, 2.0d), Block.box(0.0d, 0.0d, 15.0d, 1.0d, 1.0d, 16.0d), Block.box(15.0d, 0.0d, 1.0d, 16.0d, 1.0d, 2.0d), Block.box(15.0d, 0.0d, 15.0d, 16.0d, 1.0d, 16.0d), Block.box(-1.5d, 9.0d, 3.0d, 3.5d, 9.5d, 14.0d), Block.box(10.25d, 8.0d, 3.0d, 17.25d, 8.5d, 14.0d), Block.box(5.0d, 14.0d, 0.25d, 7.0d, 14.25d, 2.75d), Block.box(5.6d, 14.25d, 2.0d, 6.35d, 14.5d, 2.25d), Block.box(0.5999999999999996d, 14.25d, 0.75d, 1.3499999999999996d, 14.5d, 1.0d), Block.box(0.5999999999999996d, 14.25d, 1.25d, 1.3499999999999996d, 14.5d, 1.5d), Block.box(5.6d, 14.25d, 1.5d, 6.35d, 14.5d, 1.75d), Block.box(0.25d, 14.0d, 0.25d, 5.0d, 14.25d, 2.75d)}).reduce((v1, v2) -> {
        return Shapes.join((VoxelShape) v1, (VoxelShape) 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 PhotocopierBlock(Properties p_i48377_1_) {
        super(p_i48377_1_);
    }

    public void onRemove(BlockState p_196243_1_, Level p_196243_2_, BlockPos p_196243_3_, BlockState p_196243_4_, boolean p_196243_5_) {
        if (!p_196243_1_.is(p_196243_4_.getBlock())) {
            BlockEntity lvt_6_1_ = p_196243_2_.getBlockEntity(p_196243_3_);
            if (lvt_6_1_ instanceof PhotocopierBlockEntity) {
                Containers.dropContents(p_196243_2_, p_196243_3_, (PhotocopierBlockEntity) lvt_6_1_);
                p_196243_2_.updateNeighbourForOutputSignal(p_196243_3_, this);
            }
            super.onRemove(p_196243_1_, p_196243_2_, p_196243_3_, p_196243_4_, p_196243_5_);
        }
    }

    public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
        PhotocopierBlockEntity toReturn = (PhotocopierBlockEntity) PhotocopierBlockEntity.PHOTOCOPIER.create(pos, state);
        return toReturn;
    }

    public MenuProvider getMenuProvider(BlockState p_220052_1_, Level p_220052_2_, BlockPos p_220052_3_) {
        return new MenuProvider() { // from class: com.dairymoose.modernlife.blocks.PhotocopierBlock.1
            public AbstractContainerMenu createMenu(int paramInt, Inventory paramInventory, Player paramPlayer) {
                BlockEntity tileEntity = p_220052_2_.getBlockEntity(p_220052_3_);
                if (tileEntity instanceof PhotocopierBlockEntity) {
                    PhotocopierBlockEntity photocopierBlockEntity = (PhotocopierBlockEntity) tileEntity;
                    return new ChestMenu(MenuType.GENERIC_9x3, paramInt, paramInventory, photocopierBlockEntity, 3);
                }
                return null;
            }

            public Component getDisplayName() {
                return new TextComponent("Photocopier");
            }
        };
    }

    public void appendHoverText(ItemStack itemStack, @Nullable BlockGetter blockReader, List<Component> list, TooltipFlag tooltipFlag) {
        list.add(new TextComponent("Interact with a canvas or photograph to make copies"));
        list.add(new TextComponent(" * Requires paper"));
    }

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

    public InteractionResult use(BlockState blockState, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult rayTrace) {
        MenuProvider lvt_7_1_;
        ItemStack itemStack = player.getMainHandItem();
        if (itemStack.getItem() == CustomBlocks.ITEM_CANVAS.get()) {
            if (world.isClientSide) {
                DistExecutor.runWhenOn(Dist.CLIENT, () -> {
                    return new Runnable() { // from class: com.dairymoose.modernlife.blocks.PhotocopierBlock.2

                        @Override // java.lang.Runnable
                        public void run() {
                            Minecraft.getInstance().setScreen(new PhotocopierScreen(pos));
                        }
                    };
                });
            }
        } else if (!world.isClientSide && (lvt_7_1_ = getMenuProvider(blockState, world, pos)) != null) {
            player.openMenu(lvt_7_1_);
        }
        return InteractionResult.CONSUME;
    }
    /* renamed from: com.dairymoose.modernlife.blocks.PhotocopierBlock$3 */
    /* loaded from: outputsrg.jar:com/dairymoose/modernlife/blocks/PhotocopierBlock$3.class */
    static /* synthetic */ class C00443 {
        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 (C00443.$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;
        }
    }
}
