Custom items
Add textures, models, sounds and custom items to the server's own resource pack, and set what an item does through its components.
The server's own pack
The content module lets a script add files to the server's own resource pack: textures and GUI sprites, models and item model definitions, fonts, atlases, sounds and translations. The server builds one pack from every script's files without slowing the game, has it hosted and sends it to players like any server resource pack. Your script never sends that pack itself.
- Permission. To add files, sounds, texts and items, to call
content::commit()and to hand out custom items withcontent::create_item, your script needs the permissioncontent.pack(permissions::CONTENT_PACK) in its metadata. Reading needs none:content::item_id,content::items,content::namespace,content::packandcontent::player_pack. A script that only reacts to a custom item leavescontent.packout. - Namespace. Everything is in your own namespace, your script's name in lowercase (
content::namespace()). Another script's namespace,minecraftand the platform's namespaces are refused. - Limits per script. 4 MiB a file, 32 MiB and 4,096 files in all, 4,096 items. The whole pack keeps to the size the server's plan allows.
Add files
Add your files in on_load; the build when the server starts takes them all.
content::add_asset("assets/<namespace>/...", PackFamily::Java, &bytes)adds or replaces a file: a PNG texture, a model, an item model definition, a font, an atlas or a language file.content::register_sound(id, &ogg)registers the sound event<namespace>:<id>.content::add_translations(locale, &entries)adds translations for one locale, such asen_us.
Language keys
Language keys are shared by every pack, so your script writes only its own: keys that start with <namespace>. (shop.greeting) or <kind>.<namespace>. (item.shop.ruby, subtitles.shop.clank). The kinds are biome, block, color, effect, enchantment, entity, event, flat_world_preset, gamerule, generator, instrument, item, jukebox_song, painting, stat, stat_type, subtitles, trim_material, trim_pattern and upgrade.
Vanilla's texts and other scripts' keys are refused with ContentErrorCode::NamespaceDenied, through content::add_translations and in a lang/<locale>.json file alike. One bad key refuses the whole call or file.
Files for Bedrock players
content::add_asset(path, PackFamily::Bedrock, &bytes) puts textures, sounds, models, attachables and custom items into the server's own Bedrock pack. The server builds one Bedrock pack from every script's files together with the Java pack and gives it to Bedrock players when they join.
- Your files go into your own folders:
textures/<namespace>/,sounds/<namespace>/,models/entity/<namespace>/,animations/<namespace>/,attachables/<namespace>/orrender_controllers/<namespace>/. - In the shared files (
textures/item_texture.json,textures/terrain_texture.json,sounds/sound_definitions.json,blocks.jsonandstrawberry_items.json) you write only your own keys; the server merges every script's keys. - The server writes the pack's header (
manifest.json,pack_icon.png), its fonts and its texts. Your items' names come from your Java translations.
Build the pack
After a change while the server runs, content::commit() builds the pack again. Online Java players get the new pack once it is published, and the client reloads it (Paper's Player#setResourcePack). A Bedrock player gets it at the next login.
content::pack()tells where the build is and lists the problems of the last build. When a build fails, players keep the previous pack.content::player_pack(&player)tells whether a player has loaded the pack that is served:loadedafter they did. A new revision starts every player again atnone, thenpending. Use it, for example, to show a menu drawn with your fonts only to players who have the pack.- The player's answer is counted before
PlayerResourcePackStatusEventfires, so a handler that readsplayer_packsees the state after that answer. - The server's pack is required: a player who declines it is disconnected.
The extension event "content-ready" (events::CONTENT_READY) fires once for each pack revision that goes live, and again, with the earlier pack's revision, if the server goes back to that pack because the new one failed. event.pack_revision() and event.pack_sha1() give the revision and the SHA-1.
Register custom items
content::register_item(id, settings) registers the custom item <namespace>:<id>. The settings are TOML:
name: a text, or a table of texts by language;base: the vanilla item it is made of (minecraft:paperwhen left out);stack,rarity,glint,lore;acts_as: see below;block: the key of your custom block that the item places (see Blocks, drops and explosions);[components]: any component, in the syntax of/give, andremove_components;for: the name of a loaded script the item is shown under on the panel's content page, for a script that registers items for others. It changes only the text shown and gives no access.
The item's look is your model <namespace>:item/<id>, or a flat item drawn from your texture <namespace>:item/<id> when there is no model. The same id again replaces the item.
content::create_item("<namespace>:<id>", count)gives a stack of a custom item.content::item_id(&stack)tells which custom item a stack is.content::items()lists every custom item on the server with the script that registered it.
A custom item is not its base item
A custom item does not count as its base item in vanilla recipes and the other places that go by item id (crafting, cooking, smithing, the stonecutter, brewing, fuel, composting, trades, anvil materials, the grindstone, animal food, piglin bartering, beacon payment, enchanting lapis, the cartography table, the loom), unless its settings say acts_as = true. A ruby on a paper base is not paper in a recipe. Dyeing goes by item id too: a custom armour on a leather base can be dyed in the crafting grid only with acts_as = true.
What an item does through its components (food, tool, armour, repair, enchanting) is unchanged. To make a recipe that takes only your custom item, see Recipes.
Name another custom item
In [components], repairable and use_remainder may name a custom item (namespace:name, of any script): the anvil then repairs the item with exactly that custom item, and eating or using the item leaves that custom item. A name that is no Minecraft item and no custom item is reported as unknown-item among the problems of content::pack(), and the component is left out.
Set components on a stack
These ItemStack methods set a component by its meaning, with no bytes, and keep working when Minecraft changes how the component is encoded:
set_equippable(&Equippable { slot, asset_id, camera_overlay, dispensable, swappable, damage_on_hurt, equip_on_interact, can_be_sheared }): where the item is worn and which equipment asset draws it, for example your pack's<namespace>:hazmat. Vanilla's defaults aredispensable,swappableanddamage_on_hurton, the other two off. An asset or overlay id that is notnamespace:pathis refused with the reason.set_dyed_color(0xRRGGBB).set_unbreakable().set_glint_override(bool): the enchantment shine on or off.set_tooltip_display(hide_tooltip, &[components]): hide the whole tooltip, or only the lines of some components, such as the enchantments, "Dyed" or the attributes.
remove_component takes any of them away. For every other component, set_component takes the Java network encoding of the server's Minecraft version, the form get_components returns, and drops a value it cannot read. try_set_component does the same and returns the reason when it refuses.
Some components worth knowing:
- A custom
blocks_attackscomponent makes an item block as it says: partial blocks, its own delay, wear, bypass list and sounds. - A worn item with
mob_visibility, in the slot it is made for, changes how far the named mob types notice the wearer, as mob heads do. A value out of range is refused. - An item name can be a full text component with a translation key and a fallback. It is saved and sent unchanged, so a client without your pack shows the fallback instead of the key.
Items a game client can hold
The server refuses an item a game client cannot hold or show, and disconnects the player who sent it. When your script builds items itself, stay inside these limits:
- at most 64 items nested inside each other (a bundle in a bundle, and so on);
- a book and quill page of at most 1024 characters, and at most 100 pages;
- a written book title of at most 32 characters.
Picture glyphs
content::register_glyph(id, png, height, ascent) (permission content.pack) adds a picture glyph and returns the character chosen for your script and that id. It is the same after every restart and no other script can get it. Show it in a text component with the font <your namespace>:glyphs.
A picture is at most 256 by 256 pixels, and a script has at most 2,048 glyphs. Players cannot type these characters.
Music discs, paintings and armour trims
Your script can add music discs with their own song, paintings, and armour trim patterns and materials. Java players see them like vanilla ones: discs play in jukeboxes, paintings hang, and trims show on worn armour to everyone.
content::register_jukebox_song(JukeboxSong { key, sound_event, length_in_seconds, comparator_output }): a song;sound_eventis your registered sound or a game sound. An item'sjukebox_playablecomponent names it.content::register_painting(PaintingVariant { key, width, height, has_author }): a painting of 1 to 16 blocks each way, drawn fromassets/<namespace>/textures/painting/<key>.png. A painting item'spainting/variantcomponent names it; a plain painting item never picks it.content::register_trim_pattern(TrimPattern { key, decal })andcontent::register_trim_material(TrimMaterial { key, color }): the pattern's textures areassets/<namespace>/textures/trims/entity/humanoid/<key>.pngand.../humanoid_leggings/<key>.png, the material's paletteassets/<namespace>/textures/trims/color_palettes/<key>.png. An armour item'strimcomponent names them, andprovides_trim_materialmakes an item the material a smithing table puts on.
Each call needs content.pack and returns the entry's id, <namespace>:<key>. The texts are your own translation keys: jukebox_song.<namespace>.<key>, painting.<namespace>.<key>.title (and .author), trim_pattern.<namespace>.<key> and trim_material.<namespace>.<key>.
- Register them in
on_load, at every start: after the server takes players a registration returnsUnsupported. - A key is 1 to 64 characters of
a-z,0-9and_. At most 64 of each kind per script and 512 per server (LimitReached). - Bedrock players see a vanilla painting instead of yours, no trim, and a disc that plays nothing.
Resource packs on Play Strawberry
On a Play Strawberry server send-resource-pack, remove-resource-pack, clear-resource-packs and the raw add or remove pack packets send nothing (the console says so once per script). Add files through the content module instead.
The packets that add or remove a resource pack, and the client's answers to them, are the server's own. A packet hook does not see, cancel, change or create them, and player.reconfigure sends no pack: the reconfiguration itself runs, and the console says so once.
The server also sends the Strawberry pack (hats and ranks) to every player who joins, on top of the server's own packs. A game that needs it off calls server.set_strawberry_pack(false) in on_load; server.strawberry_pack_enabled() reads it.
With the custom-models script
The custom-models script runs on your server and builds items, blocks and moving models from requests your script sends (see Play Strawberry's tools). For mobs with animations, see Animated characters.
Furniture with storage or trades
A piece of furniture can hold a chest or open a trading window with the trades you list (an item for an item, your models allowed).
- One player at a time has a chest open. The contents are kept with the piece and handed back to the player if the piece cannot keep them.
- Trades never run out.
Vehicles with fuel
A vehicle request makes a model that a player gets on and drives. A saddled horse or camel carries it, and the rider's own game steers. It burns the fuel items its definition names while it moves, and stops when the tank is empty.
Custom blocks
A block can say how it feels: hardness (-1 cannot be broken outside creative), resistance (explosions), tool and tier, requires_tool (only the right tool gets the drops), its own sound or sounds_like a vanilla block, and pushable (pistons move it). What you leave out is a note block's.
shape=passablemakes a block without collision (a plant, a crop).statesgives a block up to 32 looks.facing=horizontalmakes four states and turns a placed block to face the player.- A
block-staterequest changes a block you already placed to another state. - These blocks give no light, and hitting and stepping on them sounds like wood.
Crops
A crop is a seed that grows through looks: stages (2 to 8), grow (seconds per stage), soil (farmland by default), optional light and water, bonemeal and seeds on or off, and harvest (an item and how many at the last stage).
- Planting is a player placing the seed on its soil, so protection scripts can refuse it.
- A crop grows while its chunk is loaded and catches up when the chunk loads again. Bone meal advances it a few stages.
- A young crop drops one seed; a ripe one drops its harvest (Fortune helps) and seeds.
- Breaking the soil pops the crop. A crop whose soil changed another way pops when its next stage is due.
- A script has up to 16 crops and a server 48.
Item refresh
When you change a model's definition, the stacks players already carry follow it the next time the player joins or a window click touches such a stack. The count, damage, anvil name, enchantments, trims, dyes and other scripts' data are kept; an enchantment is never taken away. A stack whose model was removed stays as it is.
Particle emitters
A piece of furniture (emit lines) or a place (emitter, emitter_remove) can send particles every few ticks to players near it. A script has up to 64 emitters and 200 particles a second. Over the limit an emission is skipped, so a script only slows itself.
Pack build report
In the /models item browser, an admin (custom-models:admin) opens a "Pack build" page: the state of the server's pack, its build number, size and SHA-1, and the problems of the last build that concern custom-models' own content, each with its code and why. Problems of other scripts are only counted.