> ## Documentation Index
> Fetch the complete documentation index at: https://items.lodemc.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Resource pack API

> Add your plugin's textures, models and other files to the resource pack Lode Items builds and sends, so players download one pack.

Lode Items builds one resource pack, hosts it and sends it to players. Your plugin can add its own files to that pack, so you don't need to build, host or send a pack of your own, and players download one pack instead of two.

Pack methods are static methods on `org.lodemc.api.pack.LodePack`.

## Adding files

Add a **contributor** in your plugin's `onLoad`. Lode Items calls it every time it builds the pack: when the server starts and on every `/lodeitems reload`.

```java theme={null}
import org.lodemc.api.pack.LodePack;

@Override
public void onLoad() {
    LodePack.addContributor(this, files -> {
        Path folder = getDataFolder().toPath().resolve("textures");
        Key texture = files.texture(Key.key("myplugin", "item/wand"), folder.resolve("wand.png"));
        Key model = files.model(texture, "{\"parent\":\"minecraft:item/handheld\",\"textures\":{\"layer0\":\"" + texture.asString() + "\"}}");
        files.itemModel(Key.key("myplugin", "wand"), model);
    });
}
```

Any stack with the `item_model` component set to `myplugin:wand` then shows the wand:

```java theme={null}
ItemStack wand = new ItemStack(Material.STICK);
wand.setData(DataComponentTypes.ITEM_MODEL, Key.key("myplugin", "wand"));
```

If you add a contributor later than `onLoad`, or your files change, call `LodePack.rebuild()`.

**addContributor(Plugin plugin, PackContributor contributor)** `void`

Adds a contributor. `PackContributor` has one method, `contribute(PackFiles files)`, so a lambda works. It's removed when `plugin` disables. If a contributor throws an exception, the error is logged and its files are left out; the rest of the pack is still built.

**removeContributors(Plugin plugin)** `void`

Removes every contributor `plugin` added.

**rebuild()** `void`

Reads `items/` again and rebuilds the pack, like `/lodeitems reload`. The pack is sent again to online players if it changed.

## PackFiles

What a contributor writes into. Paths are paths inside the pack, such as `assets/myplugin/textures/item/wand.png`.

| Method | Returns | What it does |
| - | - | - |
| `add(String path, byte[] bytes)` | | Adds a file |
| `add(String path, Path file)` | | Adds a file from disk |
| `addText(String path, String text)` | | Adds a text file |
| `texture(Key key, Path file)` | `Key` | Adds a `.png` as `assets/<namespace>/textures/<path>.png`, with its `.png.mcmeta` animation file if there's one beside it. Returns `key`, which is how models refer to the texture. |
| `model(Key key, String json)` | `Key` | Adds a model as `assets/<namespace>/models/<path>.json`. The JSON is checked. Returns `key`. |
| `itemModel(Key key, Key model)` | `Key` | Adds an item model definition, `assets/<namespace>/items/<path>.json`, that shows `model`. Stacks with `item_model` set to `key` look like it. Returns `key`. |

Rules for what goes in:

* **Only files under `assets/` are used.** Lode Items writes `pack.mcmeta` itself.
* **Lode Items' own files win a clash.** Clashes are logged in the console. Use your own namespace and you won't have any.
* **Some files are combined instead**: `sounds.json`, and files in `lang/`, `font/` and `atlases/`, because the game combines those across packs too.
* The block atlas only reads textures in `textures/block/` and the item atlas in `textures/item/`, so put textures there unless you add an atlas file.

> [!TIP]
>
> To ship files that owners put in `items/` for your plugin, find them with [`ContentEntry.resolveAsset`](https://items.lodemc.net/api/config#finding-files-next-to-the-yaml) and add them here. See the [spells example](https://items.lodemc.net/api/config.md#example-a-new-kind-of-content).

## Reading the pack

**file()** `Path`

The pack as last built, `plugins/LodeItems/pack.zip`.

**sha1()** `String`

The SHA-1 of the pack as last built, or `null` before the first build.

**hasPack(Player player)** `boolean`

Whether `player`'s client has loaded the pack. Bedrock players never have. Use it to show your custom looks only to players who can see them.

[`PackBuiltEvent`](https://items.lodemc.net/api/events#packbuiltevent) fires after every build.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.