Skip to content

Integrating PackSquash with ItemsAdder

Alejandro González edited this page Nov 16, 2024 · 5 revisions

ItemsAdder is a popular plugin that generates resource packs, so some users wonder how to get it to work with PackSquash.

To address these questions, @.efina has graciously shared a step-by-step guide on how to use PackSquash with the resource pack generated by ItemsAdder over Discord. Feel free to read it below or check out the Discord thread where it was posted!

1. Disable IA's unzip protection

First, set up ItemsAdder's config.yml to disable unzip protection. This file is under the plugins/ItemsAdder folder.

ItemsAdder configuration screenshot

Tip

It is advisable, but not required, to disable compress-png-files and compress-json-files. PackSquash already does size optimizations, so repeating them is a waste of time.

Tip

ItemsAdder will automatically upload and set up the server to use the generated pack when selecting the auto-external-host hosting strategy, which conflicts with post-processing that pack with programs like PackSquash. Therefore, only the no-host, self-host, or external-host strategies can be used:

  • no-host/external-host: the workflow is the same, but the ZIP created by IA is replaced by the ZIP created by PackSquash.
  • self-host: replace the ZIP file generated by ItemsAdder with the ZIP file optimized by PackSquash. IA will serve the latter instead.

We recommend using either no-host or external-host for production environments, as they are more scalable options.

2. Apply & make IA resource pack

Go to the server console and type /iareload to reload the configuration changes. Then use /iazip to create a resource pack ZIP file.

ItemsAdder iazip and iareload output

3. Unzip & PackSquash!

After generating the ZIP with ItemsAdder, unzip it to a directory of your choice. IA will put the generated ZIP at plugins/ItemsAdder/output/generated.zip. Next, use the packsquash command to compress the pack, publish it to your hosting, and you are done!

Tip

At this point, you can adjust the PackSquash zip_spec_conformance_level option to protect your pack from extraction, if desired.

Linux terminal walkthrough

Assuming that the working directory matches the directory where IA's generated.zip file is, it can be unzipped as shown below.

Unzipping IA's zip file

📘 Command help

  • ls: list the directory contents.
  • unzip: decompress an archive, in this case to the current directory.

After the extraction, PackSquash can be run as usual. Please note that a suitable options file is required.

Running PackSquash

📘 Command help

  • cat packsquash.toml: read the packsquash.toml file. In the shown options file, pack_directory = '.' means that the pack content is under the current directory, and output_file_path = 'pack.zip' that the optimized pack will be put at a file named pack.zip in the current directory.

Linux shell script

Running the above commands manually each time a pack is generated is cumbersome. To help with that, you can use the following simple shell script to automatically optimize the pack generated by ItemsAdder with PackSquash, which you can copy and paste to a text file.

Tip

Remember to make the script executable with chmod +x SCRIPT_FILE before running it with a command like ./SCRIPT_FILE, where SCRIPT_FILE is the name of the script file.

#!/bin/bash

# Path to the ItemsAdder generated ZIP file. Change accordingly
IA_RESOURCEPACK="plugins/ItemsAdder/output/generated.zip"

PACKSQUASH_VERSION=v0.4.0

# Set to true when using self-host hosting to replace the IA
# generated ZIP file with the result of PackSquash, to make IA
# automagically host the pack generated by PackSquash
AUTO_WRITEBACK=false

# Check unzip command is available
if ! command -v unzip &> /dev/null; then
  echo "Can't find unzip command!"
  exit 1
fi

# Check wget command is available
if ! command -v wget &> /dev/null; then
  echo "Can't find wget command!"
  exit 1
fi

# Check the resource pack path is set
if [ -z "${IA_RESOURCEPACK}" ]; then
  echo "Missing resource pack path!"
  exit 1
fi

# Check whether the packsquash command exists. If not, download the CLI version
if ! command -v packsquash &> /dev/null; then
  if [ ! -f "packsquash" ]; then
    echo "packsquash command not found, downloading CLI version..."
    wget -O packsquash-cli.zip "https://github.com/ComunidadAylas/PackSquash/releases/download/${PACKSQUASH_VERSION}/PackSquash.CLI.executable.$([[ "$(uname -m)" == "x86_64" ]] && echo "x86_64" || echo "aarch64")-unknown-linux-musl.zip"
    unzip packsquash-cli.zip
    rm packsquash-cli.zip
    chmod +x packsquash
    PACKSQUASH_COMMAND="./packsquash"
  else
    PACKSQUASH_COMMAND="./packsquash"
  fi
else
  PACKSQUASH_COMMAND="packsquash"
fi

# Check if the packsquash config exists. If not, make a default one
if [ ! -f "packsquash.toml" ]; then
  echo "PackSquash config does not exist, making a default one..."
  echo -e "pack_directory = 'workdir'\noutput_file_path = 'pack.zip'" > packsquash.toml
fi

# Do process

echo "Clean up workdir..."
rm -r workdir &> /dev/null

echo "Copy IA resource pack into current directory..."
cp "$IA_RESOURCEPACK" .

echo "Extract contents..."
unzip "$IA_RESOURCEPACK" -d "workdir"

echo "Optimize pack..."
$PACKSQUASH_COMMAND packsquash.toml

if [ "$AUTO_WRITEBACK" = true ]; then
  echo "Copying result to ItemsAdder output directory..."
  cp -r pack.zip "$IA_RESOURCEPACK"
fi

echo "Done!"