diff --git a/flake.nix b/flake.nix index 3609535d..0e576475 100644 --- a/flake.nix +++ b/flake.nix @@ -58,9 +58,7 @@ # ancmp = ./ancmp; }) // { - default = packages.buildNinecraftInstance { - version = packages.mcpeVersions.a0_6_1; - }; + default = packages.ninecraft-demo; }; apps = { extract = { diff --git a/nix/pkgs/buildNinecraftInstance.nix b/nix/pkgs/buildNinecraftInstance.nix index ada3d0ae..cf65d1e6 100644 --- a/nix/pkgs/buildNinecraftInstance.nix +++ b/nix/pkgs/buildNinecraftInstance.nix @@ -9,6 +9,8 @@ stdenvNoCC, writeShellScript, writeText, + curl, + ... }: { name ? "ninecraft", homeDir ? "$(mktemp -d)", @@ -17,6 +19,7 @@ options ? null, version ? mcpeVersions.a0_6_1, useNixGL ? false, + versionParam ? false, ... }: let optionsTxtContent = lib.concatStringsSep "\n" ( @@ -51,49 +54,57 @@ // options ) ); + ninecraftLib = + writeShellScript "ninecraft-lib" (builtins.readFile ./ninecraft-lib.sh); optionsTxt = writeText "options.txt" optionsTxtContent; - startScript = writeShellScript "start-ninecraft-${name}.sh" '' - homeDir=${homeDir} - ${ - lib.optionalString (gameDir != null) '' - gameDir=${gameDir} + startScript = + writeShellScript "start-ninecraft-${name}.sh" '' + source ${ninecraftLib} + homeDir=${homeDir} + ${ + lib.optionalString (gameDir != null) '' + gameDir=${gameDir} + + # Install Version + if [ -z "$1" ]; then + installVersion "${version}" + else + installVersion "$1" "${ + if stdenvNoCC +.hostPlatform.isx86 + then "x86" + else "" + }" + fi - # Version - if [ ! -d $gameDir ]; then - mkdir -p $gameDir + '' + } + ${lib.optionalString (builtins.isAttrs options) '' + # Options + if [[ ! -d "$homeDir/storage/games/com.mojang/minecraftpe" ]]; then + mkdir -p $homeDir/{mods,global_overrides,storage/games/com.mojang/minecraftpe} fi - if [[ ( ! -d "$gameDir/lib" ) || ( ! -d "$gameDir/res" ) || ( ! -d "$gameDir/assets" ) ]]; then - cp -r "${version}"/{assets,lib,res} "$gameDir" - chmod -R u+w "$gameDir"/{assets,lib,res} + if [[ -L $homeDir/options.txt ]] || [[ ! -e $homeDir/options.txt ]]; then + cp -sf "${optionsTxt}" $homeDir/options.txt + fi + if [[ -L "$homeDir/storage/games/com.mojang/minecraftpe/options.txt" ]] || [[ ! -e "$homeDir/storage/games/com.mojang/minecraftpe/options.txt" ]]; then + cp -sf "${optionsTxt}" "$homeDir/storage/games/com.mojang/minecraftpe/options.txt" fi - '' - } - ${lib.optionalString (builtins.isAttrs options) '' - # Options - if [[ ! -d "$homeDir/storage/games/com.mojang/minecraftpe" ]]; then - mkdir -p $homeDir/{mods,global_overrides,storage/games/com.mojang/minecraftpe} - fi - if [[ -L $homeDir/options.txt ]] || [[ ! -e $homeDir/options.txt ]]; then - cp -sf "${optionsTxt}" $homeDir/options.txt - fi - if [[ -L "$homeDir/storage/games/com.mojang/minecraftpe/options.txt" ]] || [[ ! -e "$homeDir/storage/games/com.mojang/minecraftpe/options.txt" ]]; then - cp -sf "${optionsTxt}" "$homeDir/storage/games/com.mojang/minecraftpe/options.txt" - fi - ''} - # Mods - ${lib.concatMapStrings (mod: "cp -r ${mod}/* $homeDir") mods} + ''} + # Mods + ${lib.concatMapStrings (mod: "cp -r ${mod}/* $homeDir") mods} - ${lib.optionalString useNixGL "\"${nixgl.auto.nixGLDefault}\" \\:quit"} - "${lib.getExe ninecraft}" \ - --game "${ - if (isNull gameDir) - then version - else "$gameDir" - }" \ - --home "$homeDir" \ - "$@" - ''; + ${lib.optionalString useNixGL "\"${nixgl.auto.nixGLDefault}\" \\:quit"} + "${lib.getExe ninecraft}" \ + --game "${ + if (isNull gameDir) + then version + else "$gameDir" + }" \ + --home "$homeDir" \ + "$@" + ''; in stdenvNoCC.mkDerivation { name = "ninecraft-${name}"; @@ -110,7 +121,10 @@ in runHook postInstall ''; - desktopItems = makeNinecraftDesktopItems { - instance = name; - }; + desktopItems = lib.optional true (builtins.elemAt ( + makeNinecraftDesktopItems { + instance = name; + } + ) + 0); } diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix index 0d426247..2dcc1b0a 100644 --- a/nix/pkgs/default.nix +++ b/nix/pkgs/default.nix @@ -41,8 +41,9 @@ rev = "main"; hash = lib.getHash name; }), - flakeRoot?../.., + flakeRoot ? ../.., ninecraft-extract ? ../../tools/extract.sh, + ... }: rec { fetchApk = pkgs.callPackage ./fetchApk.nix {}; mcpeVersions = @@ -66,7 +67,9 @@ }; ninecraft-nixgl = buildNinecraftInstance { - version = mcpeVersions.a0_6_1; + versionParam = true; + # homeDir = "$HOME/.local/share}/ninecraft"; + gameDir = "$(mktemp -d)"; useNixGL = true; }; # test = pkgs.callPackage ./test.nix { @@ -76,4 +79,12 @@ # buildNinecraftMod # ; # }; + # ninecraft-demo = pkgs.callPackage ./ninecraft-demo.nix { + # inherit ninecraft ninecraft-extract; + # }; + ninecraft-demo = buildNinecraftInstance { + # homeDir = "$HOME/.local/share}/ninecraft"; + versionParam = true; + gameDir = "$(mktemp -d)"; + }; } diff --git a/nix/pkgs/desktop.nix b/nix/pkgs/desktop.nix index f7c2530f..a31bf812 100644 --- a/nix/pkgs/desktop.nix +++ b/nix/pkgs/desktop.nix @@ -3,6 +3,7 @@ lib, ninecraft-extract, mcpeVersions, + ... }: { instance ? null, version ? mcpeVersions.a0_6_1, @@ -21,11 +22,12 @@ in [ icon = "${version}/res/drawable/iconx.png"; exec = "ninecraft${ if (instance == null) - then " --game \"${gameDir}\" --home \"${homeDir}\"" - else "-${instance}" + then " --game \"${gameDir}\" --home \"${homeDir}\" %u" + else "-${instance} %u" }"; categories = ["Game" "AdventureGame"]; keywords = ["mcpe" "android" "mcpi" "pocket" "edition"]; + mimeTypes = lib.optional (instance != null) "application/vnd.android.package-archive"; } ) diff --git a/nix/pkgs/fetchApk.nix b/nix/pkgs/fetchApk.nix index 5eb390b5..8c8d1bbe 100644 --- a/nix/pkgs/fetchApk.nix +++ b/nix/pkgs/fetchApk.nix @@ -1,6 +1,7 @@ { fetchzip, lib, + ... }: options: fetchzip (options // { diff --git a/nix/pkgs/meta.nix b/nix/pkgs/meta.nix index effb7b1a..89ad9228 100644 --- a/nix/pkgs/meta.nix +++ b/nix/pkgs/meta.nix @@ -1,4 +1,4 @@ -{lib}: { +{lib, ...}: { description = "MCPE Launcher"; longDescription = "A mcpe 0.1 .0 - 0.10 .5 launcher for linux and windows"; homepage = "https://github.com/MCPI-Revival/Ninecraft"; diff --git a/nix/pkgs/ninecraft-lib.sh b/nix/pkgs/ninecraft-lib.sh new file mode 100644 index 00000000..135b5a26 --- /dev/null +++ b/nix/pkgs/ninecraft-lib.sh @@ -0,0 +1,46 @@ +set -e +# set -x + +installVersion() { + if [[ -n "$gameDir" && -r "$gameDir" ]]; then + VERSION=$1 + ARCH=$2 + VERSION_PATH=$(readlink -f $VERSION) + + pushd "$gameDir" + rm -rf assets res lib + + if [[ -d "$VERSION_PATH" ]]; then + cp -r "$VERSION_PATH"/{assets,lib,res} "$gameDir" + else + + if [[ $VERSION =~ ^https?:\/\/ ]]; then + URL=$VERSION + else + if [[ -z "$ARCH" ]]; then + + URL="https://archive.org/download/MCPEAlpha/PE-a${VERSION}.apk" + else + URL="https://archive.org/download/MCPEAlpha/PE-a${VERSION}-${ARCH}.apk" + fi + fi + + if [[ -f "$VERSION_PATH" ]]; then + APK=$VERSION_PATH + else + echo "Downloading Minecraft PE from $URL..." + curl -L --output mcpe.apk "$URL" + APK=$(pwd)/mcpe.apk + fi + + echo "Extracting APK $APK..." + ninecraft-extract "$APK" + fi + + + chmod -R u+w "$gameDir"/{assets,lib,res} + + pwd + ls + fi +} \ No newline at end of file diff --git a/nix/pkgs/test.nix b/nix/pkgs/test.nix index 9a5c6755..fc849861 100644 --- a/nix/pkgs/test.nix +++ b/nix/pkgs/test.nix @@ -3,6 +3,7 @@ buildNinecraftMod, mcpeVersions, writeTextDir, + ... }: buildNinecraftInstance { name = "test"; diff --git a/nix/pkgs/versions.nix b/nix/pkgs/versions.nix index bff4579c..100d3f57 100644 --- a/nix/pkgs/versions.nix +++ b/nix/pkgs/versions.nix @@ -2,6 +2,7 @@ lib, fetchApk, stdenv, + ... }: let versions = { a0_1_0 = {