From aa7b997697a9e7276e6f10c80b2958930f35cda3 Mon Sep 17 00:00:00 2001 From: chblodg Date: Sun, 6 Feb 2022 10:45:25 -0800 Subject: [PATCH] Adding support for crafting tweaks and resource packs (#1336) Co-authored-by: christopher blodgett Co-authored-by: Geoff Bourne Co-authored-by: Floyd Everest --- DEVELOPMENT.md | 22 ++- README.md | 44 +++++- scripts/start-setupVanillaTweaks | 148 +++++++++++------- .../vanillatweaks_file/docker-compose.yml | 9 +- .../vanillatweaks_file/verify.sh | 4 + .../vanillatweaks_file/vt-craftingtweaks.json | 12 ++ ...weaks-datapacks.json => vt-datapacks.json} | 0 .../vanillatweaks_file/vt-resourcepacks.json | 8 + .../docker-compose.yml | 6 +- .../vanillatweaks_sharecode/verify.sh | 4 + 10 files changed, 189 insertions(+), 68 deletions(-) create mode 100644 tests/setuponlytests/vanillatweaks_file/verify.sh create mode 100644 tests/setuponlytests/vanillatweaks_file/vt-craftingtweaks.json rename tests/setuponlytests/vanillatweaks_file/{vanillatweaks-datapacks.json => vt-datapacks.json} (100%) create mode 100644 tests/setuponlytests/vanillatweaks_file/vt-resourcepacks.json create mode 100644 tests/setuponlytests/vanillatweaks_sharecode/verify.sh diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 6fbce060..ce2df038 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -15,8 +15,24 @@ Individual scripts can be iteratively developed, debugged, and tested using the First, build a baseline of the image to include the packages needed by existing or new scripts: -```shell script -docker build -t mc-dev . +PowerShell: +```powershell +$env:IMAGE_TO_TEST="mc-dev" +docker build -t $env:IMAGE_TO_TEST . +pushd tests/setuponlytests/vanillatweaks_file/ +docker-compose run mc +docker-compose down --remove-orphans +popd +``` + +Bash: +```bash +export IMAGE_TO_TEST=mc-dev +docker build -t $IMAGE_TO_TEST . +pushd tests/setuponlytests/vanillatweaks_file/ +docker-compose run mc +docker-compose down --remove-orphans +popd ``` Using the baseline image, an interactive container can be started to iteratively run the scripts to be developed. By attaching the current workspace directory, you can use the local editor of your choice to iteratively modify scripts while using the container to run them. @@ -116,4 +132,4 @@ for b in "${branches[@]}"; do git merge -s ours -m "Track latest from master" master git push origin done -``` \ No newline at end of file +``` diff --git a/README.md b/README.md index 853664c0..e7ba4c33 100644 --- a/README.md +++ b/README.md @@ -896,6 +896,9 @@ Datapacks will be placed in `/data/$LEVEL/datapacks` VanillaTweaks datapacks can be installed with a share code from the website UI **OR** a json file to specify packs to download and install. +Datapacks will be placed in `/data/$LEVEL/datapacks` +Resourcepacks will be placed in `/data/resourcepacks` + Accepted Parameters: - `VANILLATWEAKS_FILE` @@ -906,13 +909,19 @@ Accepted Parameters: - `REMOVE_OLD_VANILLATWEAKS_EXCLUDE` Example of expected Vanillatweaks sharecode: + **Note**: ResourcePacks, DataPacks, and CraftingTweaks all have separate sharecodes ```yaml -VANILLATWEAKS_SHARECODE: MGr52E +VANILLATWEAKS_SHARECODE: MGr52E,tF1zL2,LnEDwT ``` Example of expected Vanillatweaks file format: +```yaml +VANILLATWEAKS_FILE: /config/vt-datapacks.json,/config/vt-craftingtweaks.json,/config/vt-resourcepacks.json +``` + +Datapacks Json: ```json { "version": "1.18", @@ -920,18 +929,39 @@ Example of expected Vanillatweaks file format: "survival": [ "graves", "multiplayer sleep", - "afk display", - "armor statues", - "unlock all recipes", - "fast leaf decay", - "coordinates hud" ], "items": ["armored elytra"] } } ``` -Datapacks will be placed in `/data/$LEVEL/datapacks` +Resourcepacks Json: +```json +{ + "type": "resourcepacks", + "version": "1.18", + "packs": { + "aesthetic": ["CherryPicking", "BlackNetherBricks", "AlternateBlockDestruction"] + }, + "result": "ok" +} +``` + +CraftingTweaks Json: +```json +{ + "type": "craftingtweaks", + "version": "1.18", + "packs": { + "quality of life": [ + "dropper to dispenser", + "double slabs", + "back to blocks" + ] + }, + "result": "ok" +} +``` ## Server configuration diff --git a/scripts/start-setupVanillaTweaks b/scripts/start-setupVanillaTweaks index 4da67423..2e78d619 100644 --- a/scripts/start-setupVanillaTweaks +++ b/scripts/start-setupVanillaTweaks @@ -12,73 +12,115 @@ set -e -o pipefail . "${SCRIPTS:-/}start-utils" isDebugging && set -x -out_dir=/data/${LEVEL:-world}/datapacks +VT_VERSION="" +DATAPACKS_DIR="/data/${LEVEL:-world}/datapacks" +RESOURCEPACKS_DIR="/data/resourcepacks" # Remove old VANILLATWEAKS -if isTrue "${REMOVE_OLD_VANILLATWEAKS}" && [ -z "${VANILLATWEAKS_FILE}" ]; then - if [ -d "$out_dir" ]; then - find "$out_dir" -mindepth 1 -maxdepth ${REMOVE_OLD_VANILLATWEAKS_DEPTH:-16} -wholename "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_VANILLATWEAKS_EXCLUDE:-}" -delete +if isTrue "${REMOVE_OLD_VANILLATWEAKS}"; then + # NOTE: datapacks include crafting tweaks. + if [ -d "$DATAPACKS_DIR" ]; then + find "$DATAPACKS_DIR" -mindepth 1 -maxdepth ${REMOVE_OLD_VANILLATWEAKS_DEPTH:-16} -wholename "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_VANILLATWEAKS_EXCLUDE:-}" -delete + fi + if [ -d "$RESOURCEPACKS_DIR" ]; then + find "$RESOURCEPACKS_DIR" -mindepth 1 -maxdepth ${REMOVE_OLD_VANILLATWEAKS_DEPTH:-16} -wholename "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_VANILLATWEAKS_EXCLUDE:-}" -delete fi fi +# Gets the download url and downloads the actual files. +getUrlAndDownload(){ + VT_FILE=$1 + URL_SUFFIX=$2 + OUTPUT_FILE=$3 + PACKS=$(jq -jc '.packs // empty' $VT_FILE) + if [ ! "$PACKS" ]; then + log "ERROR: unable to retrieve ${URL_SUFFIX} from ${VT_FILE}" + exit 2 + fi + + ZIPDATA_URL="https://vanillatweaks.net/assets/server/zip${URL_SUFFIX}.php" + DOWNLOAD_URL=$(curl -X POST -F "packs=${PACKS}" -F "version=${VT_VERSION}" $ZIPDATA_URL | jq -r '.link // empty') + if [ ! "$DOWNLOAD_URL" ]; then + log "ERROR: unable to retrieve ${URL_SUFFIX} packs from vanillatweaks.net!" + exit 2 + fi + + if ! get -o $OUTPUT_FILE "https://vanillatweaks.net${DOWNLOAD_URL}"; then + log "ERROR: failed to download ${URL_SUFFIX} from ${DOWNLOAD_URL}" + exit 2 + fi +} + +# Datapacks Handler +downloadDatapacks(){ + VT_FILE=$1 + URL_SUFFIX="datapacks" + OUTPUT_FILE="/tmp/vanillatweaks.zip" + getUrlAndDownload $VT_FILE $URL_SUFFIX $OUTPUT_FILE + mkdir -p "$DATAPACKS_DIR" + if ! unzip -o -d "$DATAPACKS_DIR" $OUTPUT_FILE; then + log "ERROR: failed to unzip the datapacks ${DATAPACKS} from ${OUTPUT_FILE}" + fi + rm -f $OUTPUT_FILE +} + +# Crafting Tweaks Handler +downloadCraftingtweaks(){ + VT_FILE=$1 + mkdir -p "$DATAPACKS_DIR" + getUrlAndDownload $VT_FILE "craftingtweaks" "${DATAPACKS_DIR}/craftingtweaks.zip" +} + +# Resourcepacks Handler +downloadResourcepacks(){ + VT_FILE=$1 + mkdir -p "$RESOURCEPACKS_DIR" + getUrlAndDownload $VT_FILE "resourcepacks" "${RESOURCEPACKS_DIR}/resourcepacks.zip" +} + # Example: VANILLATWEAKS_SHARECODE=MGr52E # Code generated from the UI website, typically a alphanumeric 6 digit code. if [[ "$VANILLATWEAKS_SHARECODE" ]]; then - VANILLATWEAKS_FILE=/tmp/vanillatweaksfile.json - SHARECODE_LOOKUP_URL="https://vanillatweaks.net/assets/server/sharecode.php?code=${VANILLATWEAKS_SHARECODE}" - curl -f $SHARECODE_LOOKUP_URL -o $VANILLATWEAKS_FILE - if [ ! -f "$VANILLATWEAKS_FILE" ]; then - log "ERROR: Unable to use share code provided to retreive vanillatweaks file" - exit 2 - fi + VANILLATWEAKS_FILE=() + for SHARECODE in ${VANILLATWEAKS_SHARECODE//,/ }; do + TMP_FILE="/tmp/${SHARECODE}.json" + SHARECODE_LOOKUP_URL="https://vanillatweaks.net/assets/server/sharecode.php?code=${SHARECODE}" + if ! get -o "$TMP_FILE" "$SHARECODE_LOOKUP_URL"; then + log "ERROR: Unable to use ${SHARECODE} share code provided to retrieve vanillatweaks file" + exit 2 + fi + VANILLATWEAKS_FILE+="${TMP_FILE}," + done fi -# Use vanillatweaks file to specify VT and datapacks +# Use vanillatweaks file to specify VT and datapacks and crafting tweaks if [[ "$VANILLATWEAKS_FILE" ]]; then - if [ ! -f "$VANILLATWEAKS_FILE" ]; then - log "ERROR: given VANILLATWEAKS_FILE file does not exist" - exit 2 - fi + for VT_FILE in ${VANILLATWEAKS_FILE//,/ }; do + if [ ! -f "$VT_FILE" ]; then + log "ERROR: given VANILLATWEAKS_FILE file does not exist" + exit 2 + fi - PACKS=$(jq -jc '.packs' $VANILLATWEAKS_FILE) - if [ ! "$PACKS" ]; then - log "ERROR: unable to retrieve packs from $VANILLATWEAKS_FILE" - exit 2 - fi + VT_VERSION=$(jq -jc '.version // empty' $VT_FILE) + if [ ! "$VT_VERSION" ]; then + log "ERROR: unable to retrieve version from $VT_FILE" + exit 2 + fi - VT_VERSION=$(jq -jc '.version' $VANILLATWEAKS_FILE) - if [ ! "$VT_VERSION" ]; then - log "ERROR: unable to retrieve version from $VANILLATWEAKS_FILE" - exit 2 - fi -fi + TYPE=$(jq -jc '.type // empty' $VT_FILE) + if [[ "$TYPE" = "datapacks" ]]; then + downloadDatapacks $VT_FILE + elif [[ "$TYPE" = "craftingtweaks" ]]; then + downloadCraftingtweaks $VT_FILE + elif [[ "$TYPE" = "resourcepacks" ]]; then + downloadResourcepacks $VT_FILE + fi -# Download and unzip packs -if [[ "$PACKS" ]] && [[ "$VT_VERSION" ]]; then - VT_ZIPDATA_URL=https://vanillatweaks.net/assets/server/zipdatapacks.php - DOWNLOAD_URL=$(curl -X POST -F "packs=${PACKS}" -F "version=${VT_VERSION}" $VT_ZIPDATA_URL | jq -r '.link') - if [ ! "$DOWNLOAD_URL" ]; then - log "ERROR: unable to retrieve DOWNLOAD_URL from vanillatweaks.net!" - exit 2 - fi - - TEMPZIP=/tmp/vanillatweaks.zip - if ! get -o $TEMPZIP "https://vanillatweaks.net${DOWNLOAD_URL}"; then - log "ERROR: failed to download from ${DOWNLOAD_URL}" - exit 2 - fi - - mkdir -p "$out_dir" - if ! unzip -o -d "$out_dir" $TEMPZIP; then - log "ERROR: failed to unzip the ${PACKS} from ${$TEMPZIP}" - fi - - # clean up files time! - rm -f $TEMPZIP - # cleans up temp vanilla tweaks file download to get stored packs - if [[ "$VANILLATWEAKS_SHARECODE" ]]; then - rm -f $VANILLATWEAKS_FILE - fi + # cleans up temp vanilla tweaks file download to get stored packs + if [[ "$VANILLATWEAKS_SHARECODE" ]]; then + rm -f $VT_FILE + fi + done fi exec "${SCRIPTS:-/}start-setupDatapack" "$@" diff --git a/tests/setuponlytests/vanillatweaks_file/docker-compose.yml b/tests/setuponlytests/vanillatweaks_file/docker-compose.yml index b33292ee..494fb6f1 100644 --- a/tests/setuponlytests/vanillatweaks_file/docker-compose.yml +++ b/tests/setuponlytests/vanillatweaks_file/docker-compose.yml @@ -8,7 +8,10 @@ services: EULA: "TRUE" SETUP_ONLY: "TRUE" VERSION: ${MINECRAFT_VERSION:-LATEST} - VANILLATWEAKS_FILE: /config/vanillatweaks-datapacks.json - REMOVE_OLD_VANILLATWEAKS: "TRUE" + VANILLATWEAKS_FILE: /config/vt-datapacks.json,/config/vt-craftingtweaks.json,/config/vt-resourcepacks.json + REMOVE_OLD_VANILLATWEAKS: "FALSE" volumes: - - ./vanillatweaks-datapacks.json:/config/vanillatweaks-datapacks.json:ro + - ./data:/data + - ./vt-datapacks.json:/config/vt-datapacks.json:ro + - ./vt-craftingtweaks.json:/config/vt-craftingtweaks.json:ro + - ./vt-resourcepacks.json:/config/vt-resourcepacks.json:ro diff --git a/tests/setuponlytests/vanillatweaks_file/verify.sh b/tests/setuponlytests/vanillatweaks_file/verify.sh new file mode 100644 index 00000000..be7c0136 --- /dev/null +++ b/tests/setuponlytests/vanillatweaks_file/verify.sh @@ -0,0 +1,4 @@ +mc-image-helper assert fileExists "/data/world/datapacks/afk*" +mc-image-helper assert fileExists "/data/world/datapacks/graves*" +mc-image-helper assert fileExists "/data/world/datapacks/craftingtweaks*" +mc-image-helper assert fileExists "/data/resourcepacks/resourcepacks*" diff --git a/tests/setuponlytests/vanillatweaks_file/vt-craftingtweaks.json b/tests/setuponlytests/vanillatweaks_file/vt-craftingtweaks.json new file mode 100644 index 00000000..12d65f4b --- /dev/null +++ b/tests/setuponlytests/vanillatweaks_file/vt-craftingtweaks.json @@ -0,0 +1,12 @@ +{ + "type": "craftingtweaks", + "version": "1.18", + "packs": { + "quality of life": [ + "dropper to dispenser", + "double slabs", + "back to blocks" + ] + }, + "result": "ok" +} \ No newline at end of file diff --git a/tests/setuponlytests/vanillatweaks_file/vanillatweaks-datapacks.json b/tests/setuponlytests/vanillatweaks_file/vt-datapacks.json similarity index 100% rename from tests/setuponlytests/vanillatweaks_file/vanillatweaks-datapacks.json rename to tests/setuponlytests/vanillatweaks_file/vt-datapacks.json diff --git a/tests/setuponlytests/vanillatweaks_file/vt-resourcepacks.json b/tests/setuponlytests/vanillatweaks_file/vt-resourcepacks.json new file mode 100644 index 00000000..3917caf9 --- /dev/null +++ b/tests/setuponlytests/vanillatweaks_file/vt-resourcepacks.json @@ -0,0 +1,8 @@ +{ + "type": "resourcepacks", + "version": "1.18", + "packs": { + "aesthetic": ["CherryPicking", "BlackNetherBricks", "AlternateBlockDestruction"] + }, + "result": "ok" +} \ No newline at end of file diff --git a/tests/setuponlytests/vanillatweaks_sharecode/docker-compose.yml b/tests/setuponlytests/vanillatweaks_sharecode/docker-compose.yml index 66eac5b5..4e9b27ca 100644 --- a/tests/setuponlytests/vanillatweaks_sharecode/docker-compose.yml +++ b/tests/setuponlytests/vanillatweaks_sharecode/docker-compose.yml @@ -8,5 +8,7 @@ services: EULA: "TRUE" SETUP_ONLY: "TRUE" VERSION: ${MINECRAFT_VERSION:-LATEST} - VANILLATWEAKS_SHARECODE: MGr52E - REMOVE_OLD_VANILLATWEAKS: "TRUE" + VANILLATWEAKS_SHARECODE: MGr52E,tF1zL2,LnEDwT + REMOVE_OLD_VANILLATWEAKS: "FALSE" + volumes: + - ./data:/data diff --git a/tests/setuponlytests/vanillatweaks_sharecode/verify.sh b/tests/setuponlytests/vanillatweaks_sharecode/verify.sh new file mode 100644 index 00000000..be7c0136 --- /dev/null +++ b/tests/setuponlytests/vanillatweaks_sharecode/verify.sh @@ -0,0 +1,4 @@ +mc-image-helper assert fileExists "/data/world/datapacks/afk*" +mc-image-helper assert fileExists "/data/world/datapacks/graves*" +mc-image-helper assert fileExists "/data/world/datapacks/craftingtweaks*" +mc-image-helper assert fileExists "/data/resourcepacks/resourcepacks*"