Skip to content

Resource Transformers

Trin Wasinger edited this page Sep 22, 2026 · 10 revisions

Important

Resource Transformers may not work with all target programs depending on how they load data! See compatibility notes below.

Overview

Resource Transformers are a utility for programmatically modifying static assets bundled into a running JAR (or ZIP) file. Most methods require passing any outer class to target the owning JAR and an absolute string path (using /) to the resource within.

Operations

All methods below can be found in io.github.sianabeeblebrox.specter.Resources and may throw exceptions if something goes wrong.

read(), write(), and delete()

Most methods work with byte[]; however, there's overloads for UTF-8 encoded Strings (or readString() since return type can't be overloaded). write() will automatically create directories and files as needed and has overloads for appending to existing content instead of overwriting it.

transform() and copy()

transform() applies a byte[] -> byte[] mapping to a given resource in place, and copy() applies the transform to data copied from one path to another.

Several built-in mapping helpers are provided in io.github.sianabeeblebrox.specter.Resources.ResourceTransformer:

  • noop() - an identity mapping, useful for copying data unchanged
  • replaceFirst()/replaceAll() - Regex replacement of a textual resource supporting direct substitution or callbacks
  • json() - allows manipulating JSON data as an object (Map, List, String, Double, etc...) or returning completely new data
  • image() - for processing a resource as a java.awt.image.BufferedImage

Examples

Overwriting a Text File

Minecraft title screen with splash text uwu
Resources.write(net.minecraft.client.Minecraft, '/assets/minecraft/texts/splashes.txt', 'uwu')

Grayscaling a Texture

Grayscaled Minecraft Creeper
Resources.transform(net.minecraft.client.Minecraft, '/assets/minecraft/textures/entity/creeper/creeper.png', Resources.ResourceTransformer.image { image ->
    final BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY)
    final Graphics2D g2d = result.createGraphics()
    g2d.drawImage(image, 0, 0, null)
    g2d.dispose()

    return result
})

Modifying a JSON File

Modified Minecraft crafting recipe giving Netherite Block instead of an ingot
Resources.transform(net.minecraft.client.Minecraft, '/data/minecraft/recipe/netherite_ingot.json', Resources.ResourceTransformer.json { json ->
    json.result.id = 'minecraft:netherite_block'
    json
})

Compatibility

Resource Transformers modify an in-memory java.nio.file.FileSystem of the zipped JAR contents and should work with programs that also use the java.nio.file.* API to load resources. Below is a list of know (in)compatibilities:

  • Minecraft Java Edition - works with resources bundled in the JAR, but not those downloaded externally (e.g. sounds)

Notes

  • The Resources class is fully self-contained and can be used independent of the rest of Specter!
  • For more details, see the Javadoc.

Clone this wiki locally