Skip to content

ResourcePackBuilder

Namespace Mc.Scripting.Content · Kind class (sealed)

public sealed class ResourcePackBuilder

Builds the resource pack zip that goes with custom content: item definitions, models, textures, language files and the block state remap of custom blocks. The output is deterministic (sorted entries, fixed timestamps), so the same input gives the same SHA-1 and clients keep their cached copy until something changes.

Example

var pack = ResourcePackBuilder.Create("myplugin")
.Description("My plugin")
.AddItem(ruby, PackImage.Solid(0xFFE0115F))
.AddCustomBlock(rubyOre, PackImage.Checker(0xFF8B0A3C, 0xFFE0115F))
.AddLang("en_us", new Dictionary<string, string> { ["item.myplugin.ruby"] = "Ruby" })
.Build();
pack.SendTo(player); // hosted by ResourcePackHost (content.pack_host_port), or pack.ToResourcePack(yourUrl)
Member Description
string Name { get; } The pack name.
public string Name { get; }

The pack name.

Member Description
ResourcePackBuilder AddCustomBlock(CustomBlock block, byte[] png) Gives the block state of a registered custom block a cube model with one texture.
ResourcePackBuilder AddCustomBlockModel(CustomBlock block, string modelId) Points the block state of a registered custom block at a model of the pack (written by ResourcePackBuilder.AddModel or ResourcePackBuilder.AddFile).
ResourcePackBuilder AddFile(string path, byte[] content) Adds (or replaces) a file of the pack.
ResourcePackBuilder AddFile(string path, string text) Adds (or replaces) a text file of the pack.
ResourcePackBuilder AddItem(string itemModelId, byte[] png) Adds a flat item: the item definition, a item/generated model and the texture, all named after the item model id.
ResourcePackBuilder AddItem(CustomItem item, byte[] png) Adds a flat item for a custom item (its CustomItem.ModelId names the model).
ResourcePackBuilder AddItemDefinition(string itemModelId, string json) Adds an item definition (assets/<namespace>/items/<path>.json): what a stack with this item_model looks like.
AddLang Adds a language file (assets/<namespace>/lang/<locale>.json).
ResourcePackBuilder AddModel(string modelId, string json) Adds a model (assets/<namespace>/models/<path>.json).
ResourcePackBuilder AddTexture(string textureId, byte[] png) Adds a texture (assets/<namespace>/textures/<path>.png).
ResourcePackFile Build() Builds the zip and its SHA-1.
ResourcePackBuilder Description(string description) Sets the description shown in the pack list.
ResourcePackBuilder PackFormat(int format) Sets the resource pack format number written to pack.mcmeta (97 for 26.3).
static ResourcePackBuilder Create(string name) Starts a pack.
public ResourcePackBuilder AddCustomBlock(CustomBlock block, byte[] png)

Gives the block state of a registered custom block a cube model with one texture. Writes the block state file of the note block with every variant: the custom ones point at the new model, all others keep the vanilla model.

Parameters

Name Type Description
block CustomBlock The registered block.
png byte[] The texture of all six faces.

Returns ResourcePackBuilder: This builder.

public ResourcePackBuilder AddCustomBlockModel(CustomBlock block, string modelId)

Points the block state of a registered custom block at a model of the pack (written by ResourcePackBuilder.AddModel or ResourcePackBuilder.AddFile).

Parameters

Name Type Description
block CustomBlock The registered block.
modelId string The block model id.

Returns ResourcePackBuilder: This builder.

public ResourcePackBuilder AddFile(string path, byte[] content)

Adds (or replaces) a file of the pack.

Parameters

Name Type Description
path string The path inside the zip, assets/myplugin/models/item/ruby.json.
content byte[] The bytes.

Returns ResourcePackBuilder: This builder.

public ResourcePackBuilder AddFile(string path, string text)

Adds (or replaces) a text file of the pack.

Parameters

Name Type Description
path string The path inside the zip.
text string The content (UTF-8).

Returns ResourcePackBuilder: This builder.

public ResourcePackBuilder AddItem(string itemModelId, byte[] png)

Adds a flat item: the item definition, a item/generated model and the texture, all named after the item model id.

Parameters

Name Type Description
itemModelId string The item model id the stacks carry (CustomItem.Model), "myplugin:ruby".
png byte[] The texture.

Returns ResourcePackBuilder: This builder.

public ResourcePackBuilder AddItem(CustomItem item, byte[] png)

Adds a flat item for a custom item (its CustomItem.ModelId names the model).

Parameters

Name Type Description
item CustomItem The item (with a model id).
png byte[] The texture.

Returns ResourcePackBuilder: This builder.

public ResourcePackBuilder AddItemDefinition(string itemModelId, string json)

Adds an item definition (assets/<namespace>/items/<path>.json): what a stack with this item_model looks like.

Parameters

Name Type Description
itemModelId string The item model id, "myplugin:ruby".
json string The definition JSON ({"model":{"type":"minecraft:model","model":"myplugin:item/ruby"}}).

Returns ResourcePackBuilder: This builder.

public ResourcePackBuilder AddLang(string locale, IReadOnlyDictionary<string, string> entries, string? namespaceId = null)

Adds a language file (assets/<namespace>/lang/<locale>.json).

Parameters

Name Type Description
locale string The locale, "en_us".
entries IReadOnlyDictionary<string, string> Translation key to text.
namespaceId string? = null The namespace folder (default: the pack name).

Returns ResourcePackBuilder: This builder.

public ResourcePackBuilder AddModel(string modelId, string json)

Adds a model (assets/<namespace>/models/<path>.json).

Parameters

Name Type Description
modelId string The model id, "myplugin:item/ruby".
json string The model JSON.

Returns ResourcePackBuilder: This builder.

public ResourcePackBuilder AddTexture(string textureId, byte[] png)

Adds a texture (assets/<namespace>/textures/<path>.png).

Parameters

Name Type Description
textureId string The texture id, "myplugin:item/ruby".
png byte[] The PNG file (see PackImage for generated ones).

Returns ResourcePackBuilder: This builder.

public ResourcePackFile Build()

Builds the zip and its SHA-1.

Returns ResourcePackFile: The pack.

public ResourcePackBuilder Description(string description)

Sets the description shown in the pack list.

Parameters

Name Type Description
description string The text.

Returns ResourcePackBuilder: This builder.

public ResourcePackBuilder PackFormat(int format)

Sets the resource pack format number written to pack.mcmeta (97 for 26.3).

Parameters

Name Type Description
format int The number.

Returns ResourcePackBuilder: This builder.

public static ResourcePackBuilder Create(string name)

Starts a pack.

Parameters

Name Type Description
name string The pack name (also the seed of its id: a pack of the same name replaces the one a client already has).

Returns ResourcePackBuilder: The builder.

CustomBlock · CustomItem · ResourcePackFile