From eef1020ad8b5ceba780fe8fd9db1161b78999ce5 Mon Sep 17 00:00:00 2001 From: CodeAsm Date: Fri, 12 Sep 2025 18:31:03 +0200 Subject: [PATCH] automate vanilla registry extraction on linux * Adding a simple check if someone has read the readme * semi automate the registeries generation. still requires manually downloading server.jar for eula purposes * The mods have spoken: no spelling mistakes allowed. * mention extract_registries script in readme --------- Co-authored-by: p2r3 <41925384+p2r3@users.noreply.github.com> --- README.md | 2 +- build.sh | 8 +++++ extract_registries.sh | 73 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100755 extract_registries.sh diff --git a/README.md b/README.md index 4d877ad..84b432f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ For PC x86_64 platforms, grab the [latest build binary](https://github.com/p2r3/ For microcontrollers, see the section on **compilation** below. ## Compilation -Before compiling, you'll need to dump registry data from a vanilla Minecraft server. Create a folder called `notchian` here, and put a Minecraft server JAR in it. Then, follow [this guide](https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Data_Generators) to dump all of the registries. Finally, run `build_registries.js` with `node`, `bun`, or `deno`. +Before compiling, you'll need to dump registry data from a vanilla Minecraft server. On Linux, this can be done automatically using the `extract_registries.sh` script. Otherwise, the manual process is as follows: create a folder called `notchian` here, and put a Minecraft server JAR in it. Then, follow [this guide](https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Data_Generators) to dump all of the registries. Finally, run `build_registries.js` with `node`, `bun`, or `deno`. - To target Linux, install `gcc` and run `build.sh` - To target Windows, install `gcc` and run `build.bat` diff --git a/build.sh b/build.sh index fd5d22b..fb941c1 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,11 @@ +#!/usr/bin/env bash + +if [ ! -f "include/registries.h" ]; then + echo "Error: 'include/registries.h' is missing." + echo "Please follow the 'Compilation' section of the README to generate it." + exit 1 +fi + rm bareiron gcc src/*.c -O3 -Iinclude -o bareiron ./bareiron diff --git a/extract_registries.sh b/extract_registries.sh new file mode 100755 index 0000000..f6654dc --- /dev/null +++ b/extract_registries.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +set -euo pipefail + +REQUIRED_MAJOR=21 +SERVER_JAR="${SERVER_JAR:-server.jar}" +NOTCHIAN_DIR="notchian" +JS_RUNTIME="" + +get_java_version() { + java -version 2>&1 | awk -F[\".] '/version/ {print $2}' +} + +check_java() { + if ! command -v java >/dev/null 2>&1; then + echo "Java not found in PATH." + exit 1 + fi + + local major + major="$(get_java_version)" + + if (( major < REQUIRED_MAJOR )); then + echo "Java $REQUIRED_MAJOR or newer required, but found Java $major." + exit 1 + fi +} + +prepare_notchian_dir() { + if [[ ! -d "$NOTCHIAN_DIR" ]]; then + echo "Creating $NOTCHIAN_DIR directory..." + mkdir -p "$NOTCHIAN_DIR" + fi + cd "$NOTCHIAN_DIR" +} + +dump_registries() { + if [[ ! -f "$SERVER_JAR" ]]; then + echo "No server.jar found (looked for $SERVER_JAR)." + echo "Please download the server.jar from https://www.minecraft.net/en-us/download/server" + echo "and place it in the notchian directory." + exit 1 + fi + + java -DbundlerMainClass="net.minecraft.data.Main" -jar "$SERVER_JAR" --all +} + +detect_js_runtime() { + if command -v node >/dev/null 2>&1; then + JS_RUNTIME="node" + elif command -v bun >/dev/null 2>&1; then + JS_RUNTIME="bun" + elif command -v deno >/dev/null 2>&1; then + JS_RUNTIME="deno run" + else + echo "No JavaScript runtime found (Node.js, Bun, or Deno)." + exit 1 + fi +} + +run_js_script() { + local script="$1" + if [[ -z "$JS_RUNTIME" ]]; then + detect_js_runtime + fi + echo "Running $script with $JS_RUNTIME..." + $JS_RUNTIME "$script" +} + +check_java +prepare_notchian_dir +dump_registries +run_js_script "../build_registries.js" +echo "Registry dump and processing complete."