Items

interface Items(source)

Vanilla items and custom items from all plugins supported by Mimic. Get it via Mimic.items. To make your own plugin's items available here, implement ItemProvider instead.

Quick start

Key excalibur = Key.key("mmoitems:sword/excalibur");

// Check the ID read from a config
if (!items.hasItem(excalibur)) { ... }

// Create an item for the player
ItemStack sword = items.createItem(excalibur, 1, player);

// Identify an item
if (items.isItem(player.getInventory().getItemInMainHand(), excalibur)) { ... }

IDs

Items are identified by Key, which consists of a namespace and a path:

  • The namespace is the ID of the plugin providing the item: minecraft, mmoitems, craftengine.

  • The path is the item within that plugin: diamond, sword/excalibur, default/palm_log.

The namespace is required, there is no search over all plugins. Note that Key.key("excalibur") turns into minecraft:excalibur, so validate item IDs read from configs with hasItem or against getAllItems.

Ownership

An item belongs to the plugin with the highest priority that recognizes it, and vanilla items belong to minecraft. So a custom item is never recognized as the vanilla item it is built on: a ruby built on a diamond is not minecraft:diamond. To check the vanilla item regardless of plugins, use ItemStack.getType.

Rules

  • createItem must be called on the main thread, other methods may be called from any thread.

  • Item IDs may be unknown until their plugins finish loading, and may change when a plugin reloads. Don't validate configs in onLoad, and don't keep created stacks across reloads.

  • null or false means "not possible": the item doesn't exist, no plugin recognizes it, or the payload is invalid.

Since

0.11.0

Functions

Link copied to clipboard
open fun createItem(itemId: Key): ItemStack?

Creates a new stack with a single item with itemId.

open fun createItem(itemId: Key, amount: Int): ItemStack?

Creates a new stack of the item with itemId and the given amount.

open fun createItem(itemId: Key, amount: Int, player: Player?): ItemStack?

Creates a new stack of the item with itemId and the given amount for the player.

abstract fun createItem(itemId: Key, amount: Int = 1, player: Player? = null, payload: String? = null): ItemStack?

Creates a new stack of the item with itemId. The caller owns the returned stack.

Link copied to clipboard
abstract fun getAllItems(): List<Key>

Returns IDs of all items of all providers. Use it for config validation and tab completion. IDs are sorted by provider priority, then in the order the provider returns them.

Link copied to clipboard
abstract fun getItemId(item: ItemStack): Key?

Returns ID of the item in the provider owning it, or null if no provider recognizes the item.

Link copied to clipboard
abstract fun hasItem(itemId: Key): Boolean

Returns true if the item with itemId exists.

Link copied to clipboard
abstract fun isItem(item: ItemStack, itemId: Key): Boolean

Returns true if the item has itemId. Same as getItemId(item) == itemId: amount, stats, durability and lore of the stack are ignored.