Skip to content

7. Items (ItemMapper)

zawarka03 edited this page Jul 28, 2026 · 1 revision

Monolith API seamlessly integrates custom blocks with Bukkit's ItemStack system using Persistent Data Containers (PDC).

7.1. Converting Definitions to Items

You can generate an ItemStack representing a custom block. The API automatically applies the block's display name and embeds its identifier within the item's PDC.

// Kotlin Example
import io.github.zawarka03.monolithAPI.MonolithAPI
import io.github.zawarka03.monolithAPI.api.block.BlockDefinition
import org.bukkit.inventory.ItemStack

val definition: BlockDefinition = ... // Your custom block definition

// Generate the ItemStack
val item: ItemStack = MonolithAPI.api.items.toItem(definition)

// Give the item to a player
player.inventory.addItem(item)

7.2. Retrieving Definitions from Items

Conversely, you can inspect an ItemStack to determine if it represents a custom block and retrieve its corresponding BlockDefinition.

// Java Example
import io.github.zawarka03.monolithAPI.MonolithAPI;
import io.github.zawarka03.monolithAPI.api.block.BlockDefinition;
import org.bukkit.inventory.ItemStack;

public void checkItem(ItemStack item) {
    // Attempt to retrieve the definition
    BlockDefinition definition = MonolithAPI.api().items().fromItem(item);

    if (definition != null) {
        System.out.println("This item is a custom block: " + definition.getIdentifier());
    } else {
        System.out.println("This is a standard vanilla item.");
    }
}

Clone this wiki locally