Skip to content

Instantly share code, notes, and snippets.

@torralbaa
Last active May 27, 2021 15:43
Show Gist options
  • Save torralbaa/ba7e78c71d562a99ff3b88308cd70d95 to your computer and use it in GitHub Desktop.
Save torralbaa/ba7e78c71d562a99ff3b88308cd70d95 to your computer and use it in GitHub Desktop.
MCPI-Reborn Dockerless build.

Minecraft Pi Reborn - Dockerless build

Warnings

Only for RPis - Tested on a RPi 4B - You still need Full/Fake KMS - Not magic. Conflicts with minecraft-pi-reborn-* Unsupported - Use at your own risk.

Script(s) to build MCPI-Reborn without Docker.

dockerless-build.sh gets MCPI-Reborn, applies some patches (in the dockerless.diff file, you have to download it too), and builds it without the Docker dependency. The resulting DEB will be placed under minecraft-pi-reborn. Then you can install it and run minecraft-pi or try to use MCPIL to launch it (it should be compatible).

This might or might not work on your machine, it works on my machine:tm:, but I thought maybe someone could find it useful, since it speeds up MCPI a bit.

#!/bin/bash
set -e
CORE_DEPS="make cmake git wget ca-certificates xinput"
RT_DEPS="libgles1 libx11-6 zlib1g libfreeimage3 libglfw3 libxfixes3 libpng12-0 tk"
DEV_DEPS="gcc g++ libgles-dev libx11-dev libxrandr-dev libsdl1.2-dev libc-dev zlib1g-dev libfreeimage-dev libglfw3-dev libxfixes-dev"
URL="https://www.minecraft.net/content/dam/minecraft/edition-pi/minecraft-pi-0.1.1.tar.gz"
BASE_DIR="/usr/share/minecraft-pi/"
RDL_DIR="./deb/${BASE_DIR}/dockerless"
build()
{
cd "$1"
mkdir -p build
cd build
cmake ..
make -j$(nproc)
make install DESTDIR=../../minecraft-pi
cd ../../
return 0;
}
# Clone & cd into the repo
if [ ! -d minecraft-pi-reborn ]; then
git clone https://gitea.thebrokenrail.com/TheBrokenRail/minecraft-pi-reborn
fi
cd minecraft-pi-reborn
# Install dependencies
sudo apt-get install -y --no-install-recommends $CORE_DEPS $RT_DEPS $DEV_DEPS
# Get unmodded MCPI
if [ ! -d minecraft-pi ]; then
mkdir -p minecraft-pi
curl "${URL}" | tar -xz --strip-components 1 -C minecraft-pi
fi
# Apply patches
git apply ../dockerless.diff 2>/dev/null
# Build mods
build launcher
build mods
cp ./launcher/src/run.sh ./minecraft-pi/
rm -rf deb
mkdir -p ./deb/DEBIAN/
mkdir -p ${RDL_DIR}
mkdir -p ./deb/usr/share/minecraft-pi/client/
mkdir -p ./deb/usr/bin/
cp -r ./minecraft-pi/{api/,data/,lib/,mods/} "${RDL_DIR}"
cp -r ./minecraft-pi/{launcher,minecraft-pi,run.sh,*.txt} "${RDL_DIR}"
cp ./debian/client/common/usr/share/minecraft-pi/client/features "./deb/${BASE_DIR}/client/"
echo "
#!/bin/sh
cd ${BASE_DIR}/dockerless/ && sh ./run.sh
" > ./deb/usr/bin/minecraft-pi
chmod a+x ./deb/usr/bin/minecraft-pi
echo "
Package: mcpirdl
Version: 0.1.1
Maintainer: Alvarito050506 <[email protected]>
Description: MCPI-Reboorn Dockerless build. Unsupported.
Architecture: armhf
Depends: libgles1, libx11-6, zlib1g, libfreeimage3, libglfw3, libxfixes3, libpng12-0, tk
Conflicts: minecraft-pi, minecraft-pi-reborn-virgl, minecraft-pi-reborn-native
" > ./deb/DEBIAN/control
dpkg -b ./deb/ mcpirdl-unsupported.deb
diff --git a/launcher/src/run.sh b/launcher/src/run.sh
index 9bc3d43..08cfe33 100755
--- a/launcher/src/run.sh
+++ b/launcher/src/run.sh
@@ -2,34 +2,50 @@
set -e
-# Check Root
-if [ ! "$(id -u)" = '0' ]; then
- echo 'Must Run As Root' 1>&2
- exit 1
+# All Feature Flags
+export AVAILABLE_FEATURES="$(tr '\n' ' ' < /usr/share/minecraft-pi/client/features)"
+
+# Print Feature Flags Option
+if [ "$1" = "--print-features" ]; then
+ echo "${AVAILABLE_FEATURES}"
+ exit 0
fi
-# Check
-if ! id user > /dev/null 2>&1; then
- # Create User Groups
- if [ -z "${USER_GID+x}" ]; then
- USER_GID='1000'
- fi
- groupadd --force --gid "${USER_GID}" user
-
- # Create User
- if [ -z "${USER_UID+x}" ]; then
- USER_UID='1000'
- fi
- useradd --shell /bin/sh --home-dir /home --no-create-home --uid "${USER_UID}" --gid "${USER_GID}" user
-
- # Add Other Groups
- if [ ! -z "${USER_OTHER_GIDS+x}" ]; then
- for gid in ${USER_OTHER_GIDS}; do
- groupadd --force --gid "${gid}" "group-${gid}"
- usermod -aG "${gid}" user
- done
- fi
+# Export Important Variables
+export ZENITY_CLASS='Minecraft - Pi edition'
+
+# Ensure Features Are Selected
+if [ -z "${MCPI_FEATURES+x}" ]; then
+ MCPI_FEATURES="$(eval "zenity --class \"${ZENITY_CLASS}\" --list --checklist --width 400 --height 400 --column 'Enabled' --column 'Feature' ${AVAILABLE_FEATURES}")"
+fi
+if [ -z "${MCPI_RENDER_DISTANCE+x}" ]; then
+ MCPI_RENDER_DISTANCE="$(zenity --class "${ZENITY_CLASS}" --list --radiolist --width 400 --height 400 --text 'Minecraft Render Distance:' --column 'Selected' --column 'Name' FALSE 'Far' FALSE 'Normal' TRUE 'Short' FALSE 'Tiny')"
+fi
+if [ -z "${MCPI_USERNAME+x}" ]; then
+ MCPI_USERNAME="$(zenity --class "${ZENITY_CLASS}" --entry --text 'Minecraft Username:' --entry-text 'StevePi')"
fi
+export MCPI_FEATURES
+export MCPI_RENDER_DISTANCE
+export MCPI_USERNAME
+export MCPI_MODE="native"
-# Start
-exec gosu user ./launcher
\ No newline at end of file
+# Prepare Environment
+export USER_HOME="${HOME}"
+export USER_UID="$(id -u)"
+export USER_GID="$(id -g)"
+get_gid() {
+ echo "$(getent group "$1" | cut -d : -f 3)"
+}
+export USER_OTHER_GIDS="$(get_gid video) $(get_gid render)"
+
+# Run
+set +e
+./launcher
+RET=$?
+set -e
+
+# Handle Crash
+if [ ${RET} -ne 0 ]; then
+ zenity --class "${ZENITY_CLASS}" --error --no-wrap --text 'Minecraft: Pi Edition has crashed!\n\nExit Code: '${RET}'\n\n<a href="file:///tmp/minecraft-pi">Open Log Folder</a>\n<a href="https://gitea.thebrokenrail.com/TheBrokenRail/minecraft-pi-reborn/src/branch/master/docs/TROUBLESHOOTING.md">Open Troubleshooting Guide</a>'
+ exit ${RET}
+fi
diff --git a/mods/CMakeLists.txt b/mods/CMakeLists.txt
index 97ac219..f5f1d37 100644
--- a/mods/CMakeLists.txt
+++ b/mods/CMakeLists.txt
@@ -13,7 +13,7 @@ add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
add_subdirectory(../libreborn libreborn)
# Find GLFW
-find_package(glfw3 3.3 REQUIRED)
+find_package(glfw3 3.2 REQUIRED)
## Mods
@@ -62,4 +62,4 @@ add_library(init SHARED src/init/init.c)
target_link_libraries(init compat server game_mode camera input misc options textures chat test)
## Install Mods
-install(TARGETS init compat readdir feature screenshot override server game_mode camera input misc options textures chat test DESTINATION /mods)
\ No newline at end of file
+install(TARGETS init compat readdir feature screenshot override server game_mode camera input misc options textures chat test DESTINATION /mods)
diff --git a/mods/src/compat/compat.c b/mods/src/compat/compat.c
index d47d024..88e2056 100644
--- a/mods/src/compat/compat.c
+++ b/mods/src/compat/compat.c
@@ -333,7 +333,9 @@ HOOK(SDL_WM_GrabInput, SDL_GrabMode, (SDL_GrabMode mode)) {
} else {
if (mode != SDL_GRAB_QUERY && mode != SDL_WM_GrabInput(SDL_GRAB_QUERY)) {
glfwSetInputMode(glfw_window, GLFW_CURSOR, mode == SDL_GRAB_OFF ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED);
+#ifdef GLFW_RAW_MOUSE_MOTION
glfwSetInputMode(glfw_window, GLFW_RAW_MOUSE_MOTION, mode == SDL_GRAB_OFF ? GLFW_FALSE : GLFW_TRUE);
+#endif
// GLFW Cursor Hiding is Broken
Display *x11_display = glfwGetX11Display();
@@ -428,4 +430,4 @@ void init_compat() {
is_server = mode == 2;
// Video is Handled By GLFW Not SDL
setenv("SDL_VIDEODRIVER", "dummy", 1);
-}
\ No newline at end of file
+}
diff --git a/mods/src/test/test.c b/mods/src/test/test.c
index 04af386..56723ba 100644
--- a/mods/src/test/test.c
+++ b/mods/src/test/test.c
@@ -26,22 +26,22 @@ struct timespec32 {
void run_tests() {
// Test clock_gettime64
{
+#ifdef SYS_clock_gettime64
struct timespec64 ts64;
long out = syscall(SYS_clock_gettime64, CLOCK_MONOTONIC, &ts64);
if (out != 0) {
- if (errno == ENOSYS) {
- // clock_gettime64 Unsupported, Testing clock_gettime
- struct timespec32 ts32;
- out = syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &ts32);
- if (out != 0) {
- // Failure
- ERR("Unable To Run clock_gettime Syscall: %s", strerror(errno));
- }
- } else {
- // Failure
- ERR("Unable To Run clock_gettime64 Syscall: %s", strerror(errno));
- }
+ // Failure
+ ERR("Unable To Run clock_gettime64 Syscall: %s", strerror(errno));
}
+#else
+ struct timespec32 ts32;
+ long out = syscall(SYS_clock_gettime, CLOCK_MONOTONIC, &ts32);
+ if (out != 0) {
+ // Failure
+ ERR("Unable To Run clock_gettime Syscall: %s", strerror(errno));
+ }
+
+#endif
}
// Test ~/.minecraft-pi Permissions
@@ -57,4 +57,4 @@ void run_tests() {
ERR("%s", "Invalid ~/.minecraft-pi Permissions");
}
}
-}
\ No newline at end of file
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment