Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@
# ancmp = ./ancmp;
})
// {
default = packages.buildNinecraftInstance {
version = packages.mcpeVersions.a0_6_1;
};
default = packages.ninecraft-demo;
};
apps = {
extract = {
Expand Down
94 changes: 54 additions & 40 deletions nix/pkgs/buildNinecraftInstance.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
stdenvNoCC,
writeShellScript,
writeText,
curl,
...
}: {
name ? "ninecraft",
homeDir ? "$(mktemp -d)",
Expand All @@ -17,6 +19,7 @@
options ? null,
version ? mcpeVersions.a0_6_1,
useNixGL ? false,
versionParam ? false,
...
}: let
optionsTxtContent = lib.concatStringsSep "\n" (
Expand Down Expand Up @@ -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}";
Expand All @@ -110,7 +121,10 @@ in
runHook postInstall
'';

desktopItems = makeNinecraftDesktopItems {
instance = name;
};
desktopItems = lib.optional true (builtins.elemAt (
makeNinecraftDesktopItems {
instance = name;
}
)
0);
}
15 changes: 13 additions & 2 deletions nix/pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
rev = "main";
hash = lib.getHash name;
}),
flakeRoot?../..,
flakeRoot ? ../..,
ninecraft-extract ? ../../tools/extract.sh,
...
}: rec {
fetchApk = pkgs.callPackage ./fetchApk.nix {};
mcpeVersions =
Expand All @@ -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 {
Expand All @@ -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)";
};
}
6 changes: 4 additions & 2 deletions nix/pkgs/desktop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
lib,
ninecraft-extract,
mcpeVersions,
...
}: {
instance ? null,
version ? mcpeVersions.a0_6_1,
Expand All @@ -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";
}
)

Expand Down
1 change: 1 addition & 0 deletions nix/pkgs/fetchApk.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
fetchzip,
lib,
...
}: options:
fetchzip (options
// {
Expand Down
2 changes: 1 addition & 1 deletion nix/pkgs/meta.nix
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
46 changes: 46 additions & 0 deletions nix/pkgs/ninecraft-lib.sh
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions nix/pkgs/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
buildNinecraftMod,
mcpeVersions,
writeTextDir,
...
}:
buildNinecraftInstance {
name = "test";
Expand Down
1 change: 1 addition & 0 deletions nix/pkgs/versions.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
lib,
fetchApk,
stdenv,
...
}: let
versions = {
a0_1_0 = {
Expand Down
Loading