From 22f7807ad090b63b020c44e9727c1ab0095db254 Mon Sep 17 00:00:00 2001 From: Kas-tle <26531652+Kas-tle@users.noreply.github.com> Date: Sat, 22 Oct 2022 07:38:07 +0000 Subject: [PATCH] doc sprite maps; use curl --- .github/workflows/conversion-request.yml | 4 +- .gitignore | 4 +- README.md | 28 ++++++++- converter.sh | 72 ++++++++++++------------ 4 files changed, 68 insertions(+), 40 deletions(-) diff --git a/.github/workflows/conversion-request.yml b/.github/workflows/conversion-request.yml index 154b6cf..0763b8f 100644 --- a/.github/workflows/conversion-request.yml +++ b/.github/workflows/conversion-request.yml @@ -83,10 +83,10 @@ jobs: cp converter.sh staging/ cd staging chmod +x converter.sh - wget "${PACK_URL}" -O input_pack.zip + COLUMNS=$COLUMNS-1 curl --no-styled-output -#L -o input_pack.zip "${PACK_URL}" MERGE_PACK_FILE="${MERGE_PACK_URL}" if [ "${MERGE_PACK_URL}" != "null" ]; then - wget "${MERGE_PACK_URL}" -O merge_pack.zip + COLUMNS=$COLUMNS-1 curl --no-styled-output -#L -o merge_pack.zip "${MERGE_PACK_URL}" MERGE_PACK_FILE="merge_pack.zip" fi ./converter.sh input_pack.zip -w "false" -m ${MERGE_PACK_FILE} -a ${ATTACHABLE_MATERIAL} -b ${BLOCK_MATERIAL} -f ${DEFAULT_PACK_URL} -v ${DEFAULT_ASSETS_VERSION} diff --git a/.gitignore b/.gitignore index da62f51..26490a8 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,6 @@ parents.json spritesheet.json item_mappings.json item_texture.json -spritesheet/ \ No newline at end of file +spritesheet/ +sprites.json +sprite_hashmap.json \ No newline at end of file diff --git a/README.md b/README.md index 3d0a5c6..2f60774 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,32 @@ For example: ``` ./converter.sh MyResourcePack.zip -w "false" -m "MyBedrock.mcpack" -a "entity_alphatest_one_sided" -b "alpha_test" -f "null" -v "1.18.2" ``` + +If you prepare 2D sprites for your 3D models, you can provide the converter with mappings for these sprites to be incorporated into item_texture.json and the exported Geyser mappings. To do so, simply include a file called `sprites.json` in the root of your Java resource pack. The format of this file is as follows: +``` +{ + "leather": [ + { + "custom_model_data": 1, + "sprite": "textures/path/to/bedrock_rp/texture1" + }, + { + "custom_model_data": 2, + "sprite": "textures/path/to/bedrock_rp/texture2" + } + ], + "diamond_axe": [ + { + "damage_predicate": 2, + "unbreakable": true, + "sprite": "textures/path/to/bedrock_rp/texture3" + } + ] +} +``` + +When utilizing this feature, you should also use the merge feature to combine the converted pack with an existing Bedrock resource pack containing the specificed sprite textures. + ### Github Actions You may also run the converter through Github Actions in this repository by creating an issue with the [Pack Conversion](https://github.com/Kas-tle/java2bedrock.sh/issues/new?assignees=&labels=conversion&template=pack-conversion.yml&title=%5BPack%5D%3A+) template. You are only required to enter the link to the Java pack, though the options described above may also be configured. Your pack will then be queued for conversion by Github Actions. After conversion is complete, the Github Actions bot will reply to your issue with a link to download your converted pack and associated mappings file. Included in the bundle is a behavior pack and addon to view the models in single player, as well as a configuration file containing the paths to the models converted from the Java resource pack and their corresponding identifiers in the Bedrock resource pack. @@ -39,7 +65,7 @@ The packs generated by this script can currently only be used in Bedrock Edition /give @p geysercmd:gmdl_xxxxxxx /replaceitem entity @p slot.armor.head 0 geysercmd:gmdl_xxxxxxx ``` -The `xxxxxxx` term corresponds to the short hash assigned to the model. These are written to config.json, which can be found in the target directory, along with packaged and non-packaged versions of the output assets. This will specify the corresponding item and nbt for each input predicate. The short hash is constructed by combining the model's path with the item's custom model data, damage, and damaged predicates, taking the md5 hash of this string, and keeping only the first 7 characters. As a result, this hash value will remain the same accross conversions. +The `xxxxxxx` term corresponds to the short hash assigned to the model. These are written to config.json, which can be found in the target directory, along with packaged and non-packaged versions of the output assets. This will specify the corresponding item and nbt for each input predicate. The short hash is constructed by combining the predicate entry's item, custom model data, damage, and damaged predicates, taking the md5 hash of this string, and keeping only the first 7 characters. As a result, this hash value will remain the same accross conversions. Also note that this script requires: - [jq](https://stedolan.github.io/jq/download/) (1.6+) diff --git a/converter.sh b/converter.sh index 2d6d8d3..ef02b00 100755 --- a/converter.sh +++ b/converter.sh @@ -140,9 +140,9 @@ if test -d "./assets/minecraft/models/block"; then confarg2="./assets/minecraft/ status_message process "Downloading the latest geyser item mappings" printf "\e[3m\e[37m" echo -wget -nv --show-progress -O item_mappings.json https://raw.githubusercontent.com/GeyserMC/mappings/master/items.json +COLUMNS=$COLUMNS-1 curl --no-styled-output -#L -o item_mappings.json https://raw.githubusercontent.com/GeyserMC/mappings/master/items.json echo -wget -nv --show-progress -O item_texture.json https://raw.githubusercontent.com/Kas-tle/java2bedrockMappings/main/item_texture.json +COLUMNS=$COLUMNS-1 curl --no-styled-output -#L -o item_texture.json https://raw.githubusercontent.com/Kas-tle/java2bedrockMappings/main/item_texture.json echo printf "${C_CLOSE}" @@ -255,14 +255,14 @@ def gtest($input_g): ' parents.json config.json | sponge config.json # obtain hashes of all model file paths to ensure consistent model naming -jq -r '.[] | [.geyserID,("c" + (.nbt.CustomModelData | tostring) + "_d" + (.nbt.Damage | tostring) + "_u" + (.nbt.Unbreakable | tostring))] | @tsv | gsub("\\t";",")' config.json > paths.csv +jq -r '.[] | [.geyserID, (.item + "_c" + (.nbt.CustomModelData | tostring) + "_d" + (.nbt.Damage | tostring) + "_u" + (.nbt.Unbreakable | tostring))] | @tsv | gsub("\\t";",")' config.json > paths.csv function write_hash () { - local hash=$(echo -n "${1}" | md5sum | head -c 7) && echo "${2},${hash}" >> hashes.csv + local hash=$(echo -n "${1}" | md5sum | head -c 7) && echo "${2},${hash}" >> "${3}" } -while IFS=, read -r gid file - do write_hash "${file}" "${gid}" & +while IFS=, read -r gid predicate + do write_hash "${predicate}" "${gid}" "hashes.csv" & done < paths.csv > /dev/null jq -cR 'split(",")' hashes.csv | jq -s 'map({(.[0]): .[1]}) | add' > hashmap.json @@ -390,7 +390,9 @@ if [[ ${fallback_pack} != none ]] && [[ ! -f default_assets.zip ]] then status_message process "Now downloading the fallback resource pack:" printf "\e[3m\e[37m" - wget -nv --show-progress -O default_assets.zip https://github.com/InventivetalentDev/minecraft-assets/zipball/refs/tags/${default_asset_version:=1.19.2} + echo + COLUMNS=$COLUMNS-1 curl --no-styled-output -#L -o default_assets.zip https://github.com/InventivetalentDev/minecraft-assets/zipball/refs/tags/${default_asset_version:=1.19.2} + echo printf "${C_CLOSE}" status_message completion "Fallback resources downloaded" fi @@ -398,7 +400,9 @@ fi if [[ ${fallback_pack} != null && ${fallback_pack} != none ]] then printf "\e[3m\e[37m" - wget -nv --show-progress -O provided_assets.zip "${fallback_pack}" + echo + COLUMNS=$COLUMNS-1 curl --no-styled-output -#L -o provided_assets.zip "${fallback_pack}" + echo printf "${C_CLOSE}" status_message completion "Provided resources downloaded" mkdir ./providedassetholding @@ -1013,52 +1017,48 @@ jq ' # Add sprites if sprites.json exists in the root pack if [ -f sprites.json ]; then status_message process "Adding provided sprite paths from sprites.json" + jq -r ' + to_entries + | map(.key as $item | .value | map(. += {"item": $item})) + | add[] + | [((.item | split(":")[-1]) + "_c" + (.custom_model_data | tostring) + "_d" + (.damage_predicate | tostring) + "_u" + (.unbreakable | tostring)), .sprite] + | @tsv + | gsub("\\t";",") + ' sprites.json > sprites.csv + + while IFS=, read -r predicate icon + do write_hash "${predicate}" "${icon}" "sprite_hashes.csv" & + done < sprites.csv > /dev/null + + jq -cR 'split(",")' sprite_hashes.csv | jq -s 'map({("gmdl_" + .[1]): {"textures": .[0]}}) | add' > sprite_hashmap.json + jq -s ' - .[1] as $ind - | ((.[0] | INDEX(.path_hash)) - | map_values( - .nbt.CustomModelData as $custom_model_data - | .nbt.Damage as $damage - | .nbt.Unbreakable as $unbreakable - | { - "textures": ($ind[(.item)][]?) - | select(.custommodeldata == ($custom_model_data)) - | select(.damage == ($damage)) - | select(.unbreakable == ($unbreakable)) - | .sprite - } - )) as $icon_sprites - | .[2] + .[0] as $icon_sprites + | .[1] | .texture_data += $icon_sprites - ' config.json sprites.json ./target/rp/textures/item_texture.json | sponge ./target/rp/textures/item_texture.json + ' sprite_hashmap.json ./target/rp/textures/item_texture.json | sponge ./target/rp/textures/item_texture.json jq -s ' { "format_version": "1", "items": - (.[1] as $ind | .[0].items | to_entries | map( + ((.[0] | keys | map({(.): (.)}) | add) as $sprites | .[1].items | to_entries | map( (.key | split(":")[1]) as $item | .value | {("minecraft:" + $item): (map( .name as $name | .icon as $icon - | .custom_model_data as $custom_model_data - | .damage_predicate as $damage_predicate - | .unbreakable as $unbreakable - | (if ( - (([((($ind[($item)][])? | .custommodeldata) // null)] | index($custom_model_data)) == null) or - (([((($ind[($item)][])? | .damage) // null)] | index($damage_predicate)) == null) or - (([((($ind[($item)][])? | .unbreakable) // null)] | index($unbreakable)) == null) - ) then $icon else $name end) as $new_icon - | .icon = $new_icon + | .icon = ($sprites[($name)] // $icon) ))} ) | add) } - ' ./target/geyser_mappings.json sprites.json | sponge ./target/geyser_mappings.json + ' sprite_hashmap.json ./target/geyser_mappings.json | sponge ./target/geyser_mappings.json + + rm -f sprites.json && rm -f sprites.csv && rm -f sprite_hashes.csv && rm -f sprite_hashmap.json fi # cleanup status_message critical "Deleting scratch files" -rm -rf spritesheet && rm -rf assets && rm -f pack.mcmeta && rm -f sprites.json && rm -f pack.png && rm -f parents.json && rm -f all.csv && rm -f pa.csv && rm -f *.temp && rm -f item_mappings.json && rm -f item_texture.json && rm paths.csv && rm hashes.csv && rm hashmap.json && rm count.csv +rm -rf spritesheet && rm -rf assets && rm -f pack.mcmeta && rm -f pack.png && rm -f parents.json && rm -f all.csv && rm -f pa.csv && rm -f *.temp && rm -f item_mappings.json && rm -f item_texture.json && rm paths.csv && rm hashes.csv && rm hashmap.json && rm count.csv status_message process "Compressing output packs" mkdir ./target/packaged