Repository navigation
Resource Transformers
Important
Resource Transformers may not work with all target programs depending on how they load data! See compatibility notes below.
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.
All methods below can be found in io.github.sianabeeblebrox.specter.Resources and may throw exceptions if something goes wrong.
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() 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 ajava.awt.image.BufferedImage
Resources.write(net.minecraft.client.Minecraft, '/assets/minecraft/texts/splashes.txt', 'uwu')
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
})
Resources.transform(net.minecraft.client.Minecraft, '/data/minecraft/recipe/netherite_ingot.json', Resources.ResourceTransformer.json { json ->
json.result.id = 'minecraft:netherite_block'
json
})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)