#!/bin/bash

# Get dependencies
bedrock_depends=()
if package_available libasound2t64; then
  bedrock_depends+=('libasound2t64')
else
  bedrock_depends+=('libasound2')
fi
install_packages "${bedrock_depends[@]}" libx11-6 libxext6 libegl1 zlib1g libstdc++6 libgl1-mesa-dri libcom-err2 libgmp10 libp11-kit0 || exit 1

#Download file
mkdir -p ~/.local/bin || error "Could not make directory"
if package_is_new_enough libc6 2.36 ;then
  wget -O ~/.local/bin/MCBedrock.AppImage 'https://github.com/minecraft-linux/appimage-builder/releases/download/v0.14.2-792/Minecraft_Bedrock_Launcher-bookworm-armhf-v0.14.2.792.AppImage' || error "failed to download Minecraft Bedrock Launcher"
else
  wget -O ~/.local/bin/MCBedrock.AppImage 'https://github.com/minecraft-linux/appimage-builder/releases/download/v0.14.2-792/Minecraft_Bedrock_Launcher-armhf-v0.14.2.792.AppImage' || error "failed to download Minecraft Bedrock Launcher"
fi
chmod +x ~/.local/bin/MCBedrock.AppImage

enable_module fuse || exit 1

#Make Desktop file
mkdir -p ~/.local/share/applications
echo "[Desktop Entry]
Version=1.1
Type=Application
Name=Minecraft Bedrock Launcher
Comment=A Minecraft: Bedrock Edition
Icon=$(dirname "$0")/icon-64.png
Exec=env GALLIUM_HUD=simple,fps $HOME/.local/bin/MCBedrock.AppImage
Categories=Game;
Terminal=false
StartupNotify=true" > ~/.local/share/applications/minecraftbedrock.desktop

