Files
PixelPics/tools/update-cem-models.sh
T

47 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Updates the bundled CEM entity-model set (the only asset PixelPics vendors itself).
#
# Source: the CEM Template Loader data (Ewan Howell / wynem) — vanilla Java entity models as JSON,
# already correctly posed. These ultimately mirror Mojang's hardcoded Java EntityModel classes.
#
# NOTE: this set is now only the FALLBACK (rest-pose geometry) for entity types missing from the vanilla
# client dump (+ the elytra fallback). Mob AND block-entity models come from that dump — regenerate it
# with tools/update-vanilla-models.sh <version> on every Minecraft update.
#
# Usage: tools/update-cem-models.sh # update if newer
# tools/update-cem-models.sh --force # always overwrite
set -euo pipefail
URL="https://wynem.com/assets/json/cem_template_models.json"
DEST="$(cd "$(dirname "$0")/.." && pwd)/src/main/resources/cem/cem_template_models.json"
TMP="$(mktemp)"
trap 'rm -f "$TMP"' EXIT
echo "Fetching $URL ..."
curl -fsSL "$URL" -o "$TMP"
# Validate + read versions/counts.
read -r NEW_VER NEW_COUNT < <(python3 -c "
import json,sys
d=json.load(open('$TMP'))
assert 'models' in d and len(d['models'])>50, 'unexpected structure'
print(d.get('version','?'), len(d['models']))
")
CUR_VER="(none)"
if [ -f "$DEST" ]; then
CUR_VER="$(python3 -c "import json;print(json.load(open('$DEST')).get('version','?'))" 2>/dev/null || echo '?')"
fi
echo "Current: $CUR_VER Remote: $NEW_VER ($NEW_COUNT models)"
if [ "${1:-}" != "--force" ] && [ "$CUR_VER" = "$NEW_VER" ]; then
echo "Already up to date. (use --force to overwrite)"
exit 0
fi
mkdir -p "$(dirname "$DEST")"
cp "$TMP" "$DEST"
echo "Updated -> $DEST (version $NEW_VER, $NEW_COUNT models)"
echo "Rebuild/redeploy the plugin to apply."