API reference / @jsprismarine/java-packs
@jsprismarine/java-packs
Converts Bedrock resource packs into Java Edition resource packs a vanilla client can load.
convertResourcePacks(stack, target) from @jsprismarine/java-packs/convert takes a stack of Bedrock resource packs, top first, and the Java release to build for, and returns the Java pack's files, ready for writeZip from @jsprismarine/packs/zip. It reads no file and keeps no state, so the same stack and release always give the same bytes, and a caller can cache the pack by its inputs. A file, language key or sound event the stack holds more than once comes from the highest pack, as Bedrock resolves it.
import { convertResourcePacks } from '@jsprismarine/java-packs/convert';
import { writeZip } from '@jsprismarine/packs/zip';
import { NEWEST_JAVA_RELEASE } from '@jsprismarine/protocol/java/versions/javaReleases';
const { files, textures, report } = convertResourcePacks([{ name: 'Furniture', files: packFiles }], {
release: NEWEST_JAVA_RELEASE.minecraftVersion,
format: NEWEST_JAVA_RELEASE.resourcePackFormat
});
const zip = writeZip(files);What converts:
| Bedrock | Java |
|---|---|
The top pack's manifest name and description, pack_icon.png | pack.mcmeta with the release's min_format and max_format, pack.png |
PNG and TGA textures under textures/ | PNG under assets/bedrock/textures/, at the same path made a Java path, added to the block and item atlases |
A vanilla texture, such as textures/blocks/stone.png | Also the Java texture it is, such as assets/minecraft/textures/block/stone.png, with its flipbook animation |
textures/flipbook_textures.json | Each animated texture's .png.mcmeta |
texts/<locale>.lang | assets/bedrock/lang/<locale>.json, with Bedrock's keys |
sounds/sound_definitions.json and its Ogg Vorbis files | assets/bedrock/sounds.json and assets/bedrock/sounds/ |
font/glyph_XX.png | Bitmap providers in the default font over code points 0xXX00 to 0xXXFF |
A custom item's icon, through textures/item_texture.json | assets/<namespace>/items/<path>.json and a flat item model over the icon's texture |
A custom block's minecraft:material_instances, through textures/terrain_texture.json | A cube model, drawn on a borrowed vanilla state by a blockstates/ override |
A custom block's minecraft:geometry, from models/ | A block model of elements, drawn on a borrowed vanilla state the same way |
Which Java textures a vanilla Bedrock texture is comes from src/generated/vanillaTextures.json, which pnpm --filter @jsprismarine/bedrock-data run dump:java-textures generates from the pinned Java client jar and the pinned bedrock-samples resource pack. A Bedrock texture is the Java texture of the same name and size, or else every Java texture with the same pixels that no other Bedrock texture is named for. A vanilla texture no Java texture is, such as a Bedrock-only block's or a chest's, whose layout differs between the editions, is reported rather than written over a Java texture it does not fit.
A custom item converts when the third argument names it: { items: [{ model: 'furniture:chair', icon: 'chair' }] } writes the item model the server's stacks name with minecraft:item_model, drawn from the texture the highest pack's item_texture.json gives the icon's short name. An icon the stack does not hold is reported, and the client draws that item as a missing model. An item with no icon can name a block model with block instead.
A custom block converts the same way: { blocks: [{ block: 'minecraft:note_block', states }] } overrides the vanilla block's blockstates/ file. BORROWED_BLOCKS from @jsprismarine/java-packs/borrowedBlocks lists the blocks a server can lend, a note block and a tripwire, each with the property values its real blocks are sent with; the file keeps vanilla's models for those states, from src/generated/vanillaBlockstates.json, which pnpm --filter @jsprismarine/bedrock-data run dump:java-blockstates generates from the pinned client jar. Each of states names the texture short name of each material instance in terrain_texture.json, by name with * for the rest, and draws a cube over its faces' textures, or with geometry the cubes of that Bedrock geometry from the stack's models/. A geometry converts to block model elements: Bedrock's model space mirrors x, and each cube's rotation, its bones' and the state's rotation combine into one Euler rotation per element, which Java applies exactly. A cube reaching more than a block past the block's space and a face with an automatic UV are left out and reported.
A server that sends one Java pack per addon converts each addon's packs on their own, with the description and icon the fourth argument gives, and draws the custom items and blocks of every addon, with every addon's translations, in one more pack with convertCustomContent(stack, target, content). changesJavaClients(files, drawn) from @jsprismarine/java-packs/usage says whether an addon's converted pack changes what a Java client shows: it replaces a vanilla texture or the font, or holds a texture in drawn, which texturesDrawnBy(files) reads from the content pack's models. A pack that does none of these can be left out, and so can a content pack for which drawsCustomContent(files) is false: one that holds translations and no model, item definition or block states. javaLanguageOf(files, locale) from @jsprismarine/java-packs/lang reads a converted pack's keys for one Java locale, such as en_us, for a server that sends an addon's text in place of a key a client lacks. That pack's models name the textures the addons' packs hold, which Java resolves across every pack it has loaded, and javaTexturesOf(stack) names those textures from the packs' file names alone, as the conversion names them.
textures maps each Bedrock texture path to the Java texture it became, so a model written later can name it. report lists, per Bedrock pack, how many assets of each kind converted and a note for everything else: what converted with a loss, what a later step converts (models, client entities, attachables, block appearance, fog), what no vanilla Java client can show (animations, render controllers, particles, JSON UI, materials, Vibrant Visuals data, and sounds that ship as WAV or FSB), and what did not read. Bedrock resource packs for Java clients plans the rest.
JAVA_PACK_CONVERTER_VERSION goes up whenever the same stack would convert to other files, so a cache keyed by it, as the server's cache/java-packs/ is, never serves a pack an older converter wrote.
decodeTga and encodePng from @jsprismarine/java-packs/image are the image codecs the conversion uses. decodeTga reads the color-mapped, true color and grayscale TGA files Bedrock packs ship, run-length encoded or not, and says why a file does not read rather than throwing.