EffectiveItem

abstract class EffectiveItem

Base class for every custom item in the framework.

A subclass defines an item declaratively by overriding editMeta, getMaterial and getNamespacedData. On construction the item registers itself under its unique namespaced name (see getNamespacedName); creating a duplicate name throws.

Every stack produced by createItemStack carries the item's namespaced name in its persistent data (under ITEM_KEY), so a plain ItemStack can later be matched back to its EffectiveItem via getNamespacedKeyByItem / equalByNamespacedKey.

Behaviours are opt-in through the make* / add* methods, each backed by a dedicated Effective* interface (clickable, throwable, durable, wearable, craftable, droppable, …).

Declaring an item

object ExampleItem : EffectiveItem() {
override fun editMeta(meta: ItemMeta) {
meta.setDisplayName("§fExample item")
}
override fun getMaterial() = Material.FIREWORK_STAR
override fun getNamespacedData() = ExamplePlugin.instance to "example"

// Register behaviours here; call this from onEnable().
fun init() {
// makeThrowable { event -> ... } / makeDurable(3) / addClickHandler(...) / ...
}
}

Picking a base material

If the item uses a custom texture from a resource pack (via a custom model/item model), prefer Material.FIREWORK_STAR as the base: it has virtually no vanilla use or behaviour, so overriding its model won't collide with a commonly-used item or trigger unwanted vanilla mechanics. Use a "real" material only when you want that material's own look/behaviour.

A Kotlin object is lazy — its code runs only when something first references it. Call the item's init() from onEnable so the class is actually loaded at startup; otherwise it is never constructed and its behaviours (click/throw/…) are never wired up. A telltale sign of a forgotten init() is the item simply not showing up (e.g. missing from /egive).

override fun onEnable() {
ExampleItem.init()
}

(Loading also registers it under its getNamespacedName; two items with the same name throw.)

Textures

A getResourcePackData texture reaches the player only if the plugin enables its resource pack: call EffectiveResourcepack.addServerResourcepack(this, "", "") in onEnable after every item's init(). Without it the item exists (it's in /egive) but renders with the base material's look.

A built-in /egive <item> <player> command can hand out any registered item in-game.

Inheritors

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion
Link copied to clipboard
data class ResourcePackData(val texturePath: String? = null, val textureBytes: ByteArray? = null, val modelPath: String? = null, val modelJson: String? = null)

Resource-pack data for the item. Provide a model via modelPath (path to a model JSON inside the jar) or modelJson (the model JSON content itself); if both are null a default item/generated model is built from the texture. The texture comes from texturePath (a file inside the jar) or textureBytes (raw PNG bytes, e.g. generated at runtime); both are optional — omit them when the supplied model brings its own textures. modelJson takes precedence over modelPath, and textureBytes over texturePath.

Functions

Link copied to clipboard
fun addBrewRecipe(inputIngredient: ItemStack, inputBasePotionMeta: PotionMeta, fuelUse: Int, cookingTime: Int)

Registers a brewing-stand recipe that yields this item.

Link copied to clipboard
fun addClickHandler(click: EffectiveAbstractInteract.Click, callback: InteractCallback, ifRightClickOpenContainer: Boolean = false, cooldownData: EffectiveAbstractInteract.CooldownData<EffectiveClickable.EventsCallOptions>? = null)

Registers a click handler for stacks of this custom item (matched by key). To instead handle a plain vanilla Material, register through EffectiveClickable.addClickHandler with a non-custom stack.

Link copied to clipboard
fun additionalKey(name: String): NamespacedKey

Resolves the persistent-data key for the declared additional arg name — use it to read the per-stack value via EffectiveDataContainerUtils. See getAdditionalArgs for the full flow.

Link copied to clipboard
fun addShapelessCraft(ingredients: List<Any>)

Registers a shapeless recipe that yields this item.

Link copied to clipboard
fun addToLoot(dropChance: (Player?) -> Double, lootTables: List<LootTables>?, blocks: List<Material>?, entities: List<EntityType>?, amount: (Player?) -> IntRange? = null)

Makes this item drop from the given sources.

Link copied to clipboard
fun createItemStack(): ItemStack

Creates a single stack of this item, fully finalized (meta, identity, behaviours).

fun createItemStack(amount: Int): ItemStack

Creates a stack of amount copies of this item.

fun createItemStack(additionalArgs: List<String>): ItemStack
fun createItemStack(amount: Int, additionalArgs: List<String>): ItemStack
Link copied to clipboard
open fun createItemStackCallback(item: ItemStack)

Hook run on the finished stack after meta, identity and behaviours are applied.

Link copied to clipboard
abstract fun editMeta(meta: ItemMeta)

Configures the stack's meta (name, lore, model, …). Called during every createItemStack.

Link copied to clipboard
fun equalByNamespacedKey(item: ItemStack): Boolean

Whether item is a stack of this item (matched by namespaced key).

Whether effectiveItem is the same registered item as this one.

Link copied to clipboard

Declares extra, per-stack parameters this item accepts — values baked into an individual stack's persistent data at creation time, so two stacks of the same item can carry different settings (e.g. a "radius" or "power" tuned per stack).

Link copied to clipboard
fun getAdditionalArgsNamespacedKeys(): List<Pair<NamespacedKey, PersistentDataType<*, *>>>?

Namespaced keys backing this item's getAdditionalArgs (key → PDC type), or null if none.

Link copied to clipboard
abstract fun getMaterial(): Material

The base Material the item is built from.

Link copied to clipboard
abstract fun getNamespacedData(): Pair<JavaPlugin, String>

Owning plugin and a plugin-unique id; together they form the getNamespacedName.

Link copied to clipboard

Unique identity of the item as "<plugin-name>/<id>", both lowercased.

Link copied to clipboard

Optional resource-pack texture/model info for this item. When non-null, the framework generates the pack model/texture for it, and createItemStack automatically sets the stack's item_model to <plugin-namespace>:<id> so the custom texture shows — unless editMeta already set one.

Link copied to clipboard
fun makeDurable(maxUses: Int)

Gives this item a durability bar acting as a limited-use counter.

Link copied to clipboard
fun makeThrowable(velocity: Double = 1.5, consumeOnThrow: Boolean = true, throwSound: Sound? = Sound.ENTITY_SNOWBALL_THROW, onHit: (ProjectileHitEvent) -> Unit)

Makes this item throwable: right-clicking launches a snowball carrying the item, and onHit runs when it lands. The projectile is identified by the item stored inside it.

Link copied to clipboard

Prevents this item from being dropped, and keeps it in the inventory on death.

Link copied to clipboard

Allows this item to be equipped to the head slot (right-click or helmet-slot drag).

Link copied to clipboard

Whether the getAdditionalArgs values are appended to the item's lore automatically.