Fandom

Minecraft Mod Custom Stuff Wiki

Item Function Triggers

175pages on
this wiki
Add New Page
Comments22 Share

Below you can find a list of triggers for items that can be used to add functionality to your custom items. For block triggers, refer to the Block Function Triggers page.

Table of Triggers

Trigger Name Description Functions and Variables
onBlockStartBreak This trigger is called when you start mining a block with your item. mod, config, itemstack, position, player, and world
onBlockDestroyed This trigger is called when you break a block using your item. This is the event you want to use for damaging your tools. mod, config, itemstack, position, player, and world
onCreated This trigger is called when you craft a custom item. mod, config, itemstack, world, and player
onDroppedByPlayer This trigger is called when a player drops the item. It should not trigger when dropped through triggers. mod, config, itemstack, world, and player
onEaten This trigger is called when an item is used until maxUsingDuration attribute is meet. This is not required for food unless you want secondary effects or want a container back. mod, config, itemstack, world, and player
onHitEntity This trigger is called when you hit an entity with a custom item. Any functions such as getHealth will be called AFTER damage is dealt but before the entity is removed. mod, config, itemstack, player, living, and world
onLeftClickLiving This trigger is called when you left click (or hit) a living entity (non-player) with a custom item. Any functions such as getHealth will be called BEFORE damage is applied. mod, config, itemstack, player, living, and world
onLeftClickPlayer This trigger is called when you left click (or hit) a player with a custom item. The interactPlayer functions are the same as player except that player affects the one holding the item while interactPlayer affects the one hit with the item. mod, config, itemstack, player, interactPlayer, and world
onRightClick This trigger is called when the player right clicks using the item. This will be called even if right clicking on air. To make it activate when right clicking a block instead, use one of the onUse variants. mod, config, itemstack, player, and world
onStoppedUsing This trigger is called when the player stops using the item. With the help of tickCount, you can make an item do something after "charging up", similar to a bow. mod, config, itemstack, world, player and tickCount
onUpdate This trigger is called every tick (will be based on an attribute in a future update) as long as the item is in the player's inventory. mod, config, itemstack, world, player, slotId, and isCurrentItem
onUse This trigger is called when you right click a block with the item. It is called AFTER that block's activated event is called. This trigger might not activate if block has an activated event. (untested) mod, config, itemstack, player, world, position, side, hitX, and hitY
onUseFirst This trigger is also called when you right click a block with the item. It is called BEFORE that block's activated event is called. This might prevent the block's activated event from triggering. (untested) mod, config, itemstack, player, world, position, side, hitX, and hitY
onUseOnPlayer This trigger is called when you right click a player with the item. mod, config, itemstack, living, and world
onUseOnEntity This trigger is called when you right click an entity with the item. Combined with living.shear(); you can make your own custom shearing tools. mod, config, itemstack, player, and world
onUsing This trigger is called ever tick while the item is in use (ex. while blocking or eating). mod, config, itemstack, player, world, and tickCount

Examples

Damage the item every time you break a block:

onBlockDestroyed = "player.damageItem(player.getCurrentSlot(), 1);";

Get a tin can (custom item) back when you eat the food item:

onEaten = "player.add(config.getItemId("tinCanID"), 1, 0);"

Checking block id for debugging purposes:

onUseFirst = "player.sendMessage('This block is '+ world.getBlockId(position) + ':' + world.getBlockMetadata(position) + '.');";

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.