#!/usr/bin/env bash # Build, swap the jar under a stopped instance, relaunch, wait for the title screen. # # The jar is NOT hot-swappable: NeoForge holds every mod jar open for the whole # session, so overwriting it in place under a running game leaves the archive # valid on disk but invalid to the running JVM. The symptom is silent - # "could not find module cmmodular:armor/socket/arm_left substituting with # empty module" - and every part built on it vanishes off the wearer. Hence the # kill/copy/relaunch, every time, with no shortcut. set -uo pipefail REPO=/home/themiro/code.dev/create-mekanism-modular INST=/home/themiro/.var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/instances/Abdelpak-Delta-testing/minecraft JAR=cmmodular-1.4.0.jar cd "$REPO" || exit 1 # `gradlew build` fails on this toolchain: the :test task cannot be created # ("Type T not present"). `jar` is the only target we need anyway. ./gradlew jar -q --console=plain 2>&1 | grep -vi 'warning\|restricted' [ -f "build/libs/$JAR" ] || { echo "build produced no jar"; exit 1; } pid=$(for p in $(pgrep -x java 2>/dev/null); do tr '\0' ' ' < /proc/$p/cmdline 2>/dev/null \ | grep -q 'PrismLauncher/instances/Abdelpak-Delta-testing' && echo "$p"; done | head -1) if [ -n "$pid" ]; then kill "$pid" for _ in $(seq 1 40); do kill -0 "$pid" 2>/dev/null || break; sleep 0.5; done kill -0 "$pid" 2>/dev/null && kill -9 "$pid" sleep 2 fi cp "build/libs/$JAR" "$INST/mods/$JAR" || exit 1 unzip -t "$INST/mods/$JAR" >/dev/null || { echo "deployed jar is corrupt"; exit 1; } : > "$INST/logs/latest.log" 2>/dev/null cd /tmp && setsid flatpak run org.prismlauncher.PrismLauncher \ --launch Abdelpak-Delta-testing >/dev/null 2>&1 < /dev/null & for _ in $(seq 1 120); do grep -qi 'Sound engine started\|OpenAL initialized' "$INST/logs/latest.log" 2>/dev/null && { echo "ready (title screen)" grep -i 'could not find module\|substituting with empty' "$INST/logs/latest.log" | tail -5 exit 0; } sleep 5 done echo "timed out waiting for the title screen"