Skip to content

Commit aa7b997

Browse files
shotahchristopher blodgettitzgfleverest
authored
Adding support for crafting tweaks and resource packs (#1336)
Co-authored-by: christopher blodgett <christopher.blodgett@gmail.com> Co-authored-by: Geoff Bourne <itzgeoff@gmail.com> Co-authored-by: Floyd Everest <me@floydeverest.com>
1 parent eb6c7c9 commit aa7b997

File tree

10 files changed

+183
-62
lines changed

10 files changed

+183
-62
lines changed

DEVELOPMENT.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,24 @@ Individual scripts can be iteratively developed, debugged, and tested using the
1515

1616
First, build a baseline of the image to include the packages needed by existing or new scripts:
1717

18-
```shell script
19-
docker build -t mc-dev .
18+
PowerShell:
19+
```powershell
20+
$env:IMAGE_TO_TEST="mc-dev"
21+
docker build -t $env:IMAGE_TO_TEST .
22+
pushd tests/setuponlytests/vanillatweaks_file/
23+
docker-compose run mc
24+
docker-compose down --remove-orphans
25+
popd
26+
```
27+
28+
Bash:
29+
```bash
30+
export IMAGE_TO_TEST=mc-dev
31+
docker build -t $IMAGE_TO_TEST .
32+
pushd tests/setuponlytests/vanillatweaks_file/
33+
docker-compose run mc
34+
docker-compose down --remove-orphans
35+
popd
2036
```
2137

2238
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
116132
git merge -s ours -m "Track latest from master" master
117133
git push origin
118134
done
119-
```
135+
```

README.md

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,9 @@ Datapacks will be placed in `/data/$LEVEL/datapacks`
896896

897897
VanillaTweaks datapacks can be installed with a share code from the website UI **OR** a json file to specify packs to download and install.
898898

899+
Datapacks will be placed in `/data/$LEVEL/datapacks`
900+
Resourcepacks will be placed in `/data/resourcepacks`
901+
899902
Accepted Parameters:
900903

901904
- `VANILLATWEAKS_FILE`
@@ -906,32 +909,59 @@ Accepted Parameters:
906909
- `REMOVE_OLD_VANILLATWEAKS_EXCLUDE`
907910

908911
Example of expected Vanillatweaks sharecode:
912+
**Note**: ResourcePacks, DataPacks, and CraftingTweaks all have separate sharecodes
909913

910914
```yaml
911-
VANILLATWEAKS_SHARECODE: MGr52E
915+
VANILLATWEAKS_SHARECODE: MGr52E,tF1zL2,LnEDwT
912916
```
913917
914918
Example of expected Vanillatweaks file format:
915919
920+
```yaml
921+
VANILLATWEAKS_FILE: /config/vt-datapacks.json,/config/vt-craftingtweaks.json,/config/vt-resourcepacks.json
922+
```
923+
924+
Datapacks Json:
916925
```json
917926
{
918927
"version": "1.18",
919928
"packs": {
920929
"survival": [
921930
"graves",
922931
"multiplayer sleep",
923-
"afk display",
924-
"armor statues",
925-
"unlock all recipes",
926-
"fast leaf decay",
927-
"coordinates hud"
928932
],
929933
"items": ["armored elytra"]
930934
}
931935
}
932936
```
933937

934-
Datapacks will be placed in `/data/$LEVEL/datapacks`
938+
Resourcepacks Json:
939+
```json
940+
{
941+
"type": "resourcepacks",
942+
"version": "1.18",
943+
"packs": {
944+
"aesthetic": ["CherryPicking", "BlackNetherBricks", "AlternateBlockDestruction"]
945+
},
946+
"result": "ok"
947+
}
948+
```
949+
950+
CraftingTweaks Json:
951+
```json
952+
{
953+
"type": "craftingtweaks",
954+
"version": "1.18",
955+
"packs": {
956+
"quality of life": [
957+
"dropper to dispenser",
958+
"double slabs",
959+
"back to blocks"
960+
]
961+
},
962+
"result": "ok"
963+
}
964+
```
935965

936966
## Server configuration
937967

scripts/start-setupVanillaTweaks

Lines changed: 89 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,73 +12,115 @@ set -e -o pipefail
1212
. "${SCRIPTS:-/}start-utils"
1313
isDebugging && set -x
1414

15-
out_dir=/data/${LEVEL:-world}/datapacks
15+
VT_VERSION=""
16+
DATAPACKS_DIR="/data/${LEVEL:-world}/datapacks"
17+
RESOURCEPACKS_DIR="/data/resourcepacks"
1618

1719
# Remove old VANILLATWEAKS
18-
if isTrue "${REMOVE_OLD_VANILLATWEAKS}" && [ -z "${VANILLATWEAKS_FILE}" ]; then
19-
if [ -d "$out_dir" ]; then
20-
find "$out_dir" -mindepth 1 -maxdepth ${REMOVE_OLD_VANILLATWEAKS_DEPTH:-16} -wholename "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_VANILLATWEAKS_EXCLUDE:-}" -delete
20+
if isTrue "${REMOVE_OLD_VANILLATWEAKS}"; then
21+
# NOTE: datapacks include crafting tweaks.
22+
if [ -d "$DATAPACKS_DIR" ]; then
23+
find "$DATAPACKS_DIR" -mindepth 1 -maxdepth ${REMOVE_OLD_VANILLATWEAKS_DEPTH:-16} -wholename "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_VANILLATWEAKS_EXCLUDE:-}" -delete
24+
fi
25+
if [ -d "$RESOURCEPACKS_DIR" ]; then
26+
find "$RESOURCEPACKS_DIR" -mindepth 1 -maxdepth ${REMOVE_OLD_VANILLATWEAKS_DEPTH:-16} -wholename "${REMOVE_OLD_VANILLATWEAKS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_VANILLATWEAKS_EXCLUDE:-}" -delete
2127
fi
2228
fi
2329

24-
# Example: VANILLATWEAKS_SHARECODE=MGr52E
25-
# Code generated from the UI website, typically a alphanumeric 6 digit code.
26-
if [[ "$VANILLATWEAKS_SHARECODE" ]]; then
27-
VANILLATWEAKS_FILE=/tmp/vanillatweaksfile.json
28-
SHARECODE_LOOKUP_URL="https://vanillatweaks.net/assets/server/sharecode.php?code=${VANILLATWEAKS_SHARECODE}"
29-
curl -f $SHARECODE_LOOKUP_URL -o $VANILLATWEAKS_FILE
30-
if [ ! -f "$VANILLATWEAKS_FILE" ]; then
31-
log "ERROR: Unable to use share code provided to retreive vanillatweaks file"
30+
# Gets the download url and downloads the actual files.
31+
getUrlAndDownload(){
32+
VT_FILE=$1
33+
URL_SUFFIX=$2
34+
OUTPUT_FILE=$3
35+
PACKS=$(jq -jc '.packs // empty' $VT_FILE)
36+
if [ ! "$PACKS" ]; then
37+
log "ERROR: unable to retrieve ${URL_SUFFIX} from ${VT_FILE}"
3238
exit 2
3339
fi
34-
fi
3540

36-
# Use vanillatweaks file to specify VT and datapacks
37-
if [[ "$VANILLATWEAKS_FILE" ]]; then
38-
if [ ! -f "$VANILLATWEAKS_FILE" ]; then
39-
log "ERROR: given VANILLATWEAKS_FILE file does not exist"
41+
ZIPDATA_URL="https://vanillatweaks.net/assets/server/zip${URL_SUFFIX}.php"
42+
DOWNLOAD_URL=$(curl -X POST -F "packs=${PACKS}" -F "version=${VT_VERSION}" $ZIPDATA_URL | jq -r '.link // empty')
43+
if [ ! "$DOWNLOAD_URL" ]; then
44+
log "ERROR: unable to retrieve ${URL_SUFFIX} packs from vanillatweaks.net!"
4045
exit 2
4146
fi
4247

43-
PACKS=$(jq -jc '.packs' $VANILLATWEAKS_FILE)
44-
if [ ! "$PACKS" ]; then
45-
log "ERROR: unable to retrieve packs from $VANILLATWEAKS_FILE"
48+
if ! get -o $OUTPUT_FILE "https://vanillatweaks.net${DOWNLOAD_URL}"; then
49+
log "ERROR: failed to download ${URL_SUFFIX} from ${DOWNLOAD_URL}"
4650
exit 2
4751
fi
52+
}
4853

49-
VT_VERSION=$(jq -jc '.version' $VANILLATWEAKS_FILE)
50-
if [ ! "$VT_VERSION" ]; then
51-
log "ERROR: unable to retrieve version from $VANILLATWEAKS_FILE"
52-
exit 2
54+
# Datapacks Handler
55+
downloadDatapacks(){
56+
VT_FILE=$1
57+
URL_SUFFIX="datapacks"
58+
OUTPUT_FILE="/tmp/vanillatweaks.zip"
59+
getUrlAndDownload $VT_FILE $URL_SUFFIX $OUTPUT_FILE
60+
mkdir -p "$DATAPACKS_DIR"
61+
if ! unzip -o -d "$DATAPACKS_DIR" $OUTPUT_FILE; then
62+
log "ERROR: failed to unzip the datapacks ${DATAPACKS} from ${OUTPUT_FILE}"
5363
fi
64+
rm -f $OUTPUT_FILE
65+
}
66+
67+
# Crafting Tweaks Handler
68+
downloadCraftingtweaks(){
69+
VT_FILE=$1
70+
mkdir -p "$DATAPACKS_DIR"
71+
getUrlAndDownload $VT_FILE "craftingtweaks" "${DATAPACKS_DIR}/craftingtweaks.zip"
72+
}
73+
74+
# Resourcepacks Handler
75+
downloadResourcepacks(){
76+
VT_FILE=$1
77+
mkdir -p "$RESOURCEPACKS_DIR"
78+
getUrlAndDownload $VT_FILE "resourcepacks" "${RESOURCEPACKS_DIR}/resourcepacks.zip"
79+
}
80+
81+
# Example: VANILLATWEAKS_SHARECODE=MGr52E
82+
# Code generated from the UI website, typically a alphanumeric 6 digit code.
83+
if [[ "$VANILLATWEAKS_SHARECODE" ]]; then
84+
VANILLATWEAKS_FILE=()
85+
for SHARECODE in ${VANILLATWEAKS_SHARECODE//,/ }; do
86+
TMP_FILE="/tmp/${SHARECODE}.json"
87+
SHARECODE_LOOKUP_URL="https://vanillatweaks.net/assets/server/sharecode.php?code=${SHARECODE}"
88+
if ! get -o "$TMP_FILE" "$SHARECODE_LOOKUP_URL"; then
89+
log "ERROR: Unable to use ${SHARECODE} share code provided to retrieve vanillatweaks file"
90+
exit 2
91+
fi
92+
VANILLATWEAKS_FILE+="${TMP_FILE},"
93+
done
5494
fi
5595

56-
# Download and unzip packs
57-
if [[ "$PACKS" ]] && [[ "$VT_VERSION" ]]; then
58-
VT_ZIPDATA_URL=https://vanillatweaks.net/assets/server/zipdatapacks.php
59-
DOWNLOAD_URL=$(curl -X POST -F "packs=${PACKS}" -F "version=${VT_VERSION}" $VT_ZIPDATA_URL | jq -r '.link')
60-
if [ ! "$DOWNLOAD_URL" ]; then
61-
log "ERROR: unable to retrieve DOWNLOAD_URL from vanillatweaks.net!"
62-
exit 2
63-
fi
96+
# Use vanillatweaks file to specify VT and datapacks and crafting tweaks
97+
if [[ "$VANILLATWEAKS_FILE" ]]; then
98+
for VT_FILE in ${VANILLATWEAKS_FILE//,/ }; do
99+
if [ ! -f "$VT_FILE" ]; then
100+
log "ERROR: given VANILLATWEAKS_FILE file does not exist"
101+
exit 2
102+
fi
64103

65-
TEMPZIP=/tmp/vanillatweaks.zip
66-
if ! get -o $TEMPZIP "https://vanillatweaks.net${DOWNLOAD_URL}"; then
67-
log "ERROR: failed to download from ${DOWNLOAD_URL}"
68-
exit 2
69-
fi
104+
VT_VERSION=$(jq -jc '.version // empty' $VT_FILE)
105+
if [ ! "$VT_VERSION" ]; then
106+
log "ERROR: unable to retrieve version from $VT_FILE"
107+
exit 2
108+
fi
70109

71-
mkdir -p "$out_dir"
72-
if ! unzip -o -d "$out_dir" $TEMPZIP; then
73-
log "ERROR: failed to unzip the ${PACKS} from ${$TEMPZIP}"
74-
fi
110+
TYPE=$(jq -jc '.type // empty' $VT_FILE)
111+
if [[ "$TYPE" = "datapacks" ]]; then
112+
downloadDatapacks $VT_FILE
113+
elif [[ "$TYPE" = "craftingtweaks" ]]; then
114+
downloadCraftingtweaks $VT_FILE
115+
elif [[ "$TYPE" = "resourcepacks" ]]; then
116+
downloadResourcepacks $VT_FILE
117+
fi
75118

76-
# clean up files time!
77-
rm -f $TEMPZIP
78-
# cleans up temp vanilla tweaks file download to get stored packs
79-
if [[ "$VANILLATWEAKS_SHARECODE" ]]; then
80-
rm -f $VANILLATWEAKS_FILE
81-
fi
119+
# cleans up temp vanilla tweaks file download to get stored packs
120+
if [[ "$VANILLATWEAKS_SHARECODE" ]]; then
121+
rm -f $VT_FILE
122+
fi
123+
done
82124
fi
83125

84126
exec "${SCRIPTS:-/}start-setupDatapack" "$@"

tests/setuponlytests/vanillatweaks_file/docker-compose.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ services:
88
EULA: "TRUE"
99
SETUP_ONLY: "TRUE"
1010
VERSION: ${MINECRAFT_VERSION:-LATEST}
11-
VANILLATWEAKS_FILE: /config/vanillatweaks-datapacks.json
12-
REMOVE_OLD_VANILLATWEAKS: "TRUE"
11+
VANILLATWEAKS_FILE: /config/vt-datapacks.json,/config/vt-craftingtweaks.json,/config/vt-resourcepacks.json
12+
REMOVE_OLD_VANILLATWEAKS: "FALSE"
1313
volumes:
14-
- ./vanillatweaks-datapacks.json:/config/vanillatweaks-datapacks.json:ro
14+
- ./data:/data
15+
- ./vt-datapacks.json:/config/vt-datapacks.json:ro
16+
- ./vt-craftingtweaks.json:/config/vt-craftingtweaks.json:ro
17+
- ./vt-resourcepacks.json:/config/vt-resourcepacks.json:ro
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mc-image-helper assert fileExists "/data/world/datapacks/afk*"
2+
mc-image-helper assert fileExists "/data/world/datapacks/graves*"
3+
mc-image-helper assert fileExists "/data/world/datapacks/craftingtweaks*"
4+
mc-image-helper assert fileExists "/data/resourcepacks/resourcepacks*"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"type": "craftingtweaks",
3+
"version": "1.18",
4+
"packs": {
5+
"quality of life": [
6+
"dropper to dispenser",
7+
"double slabs",
8+
"back to blocks"
9+
]
10+
},
11+
"result": "ok"
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"type": "resourcepacks",
3+
"version": "1.18",
4+
"packs": {
5+
"aesthetic": ["CherryPicking", "BlackNetherBricks", "AlternateBlockDestruction"]
6+
},
7+
"result": "ok"
8+
}

tests/setuponlytests/vanillatweaks_sharecode/docker-compose.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ services:
88
EULA: "TRUE"
99
SETUP_ONLY: "TRUE"
1010
VERSION: ${MINECRAFT_VERSION:-LATEST}
11-
VANILLATWEAKS_SHARECODE: MGr52E
12-
REMOVE_OLD_VANILLATWEAKS: "TRUE"
11+
VANILLATWEAKS_SHARECODE: MGr52E,tF1zL2,LnEDwT
12+
REMOVE_OLD_VANILLATWEAKS: "FALSE"
13+
volumes:
14+
- ./data:/data
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mc-image-helper assert fileExists "/data/world/datapacks/afk*"
2+
mc-image-helper assert fileExists "/data/world/datapacks/graves*"
3+
mc-image-helper assert fileExists "/data/world/datapacks/craftingtweaks*"
4+
mc-image-helper assert fileExists "/data/resourcepacks/resourcepacks*"

0 commit comments

Comments
 (0)