Repository navigation
API Item Callbacks
Each callback is an optional table with action = function(ctx) ... end. Use the item action context, except harvest and mining-speed queries, which use the small query context documented below. Overrides expose ctx:base() and require the Java agent on existing Minecraft or mod content.
On this page
| Return | Effect |
|---|---|
"pass" or nil
|
Continue normal handling/fallback. |
"handled" |
Complete the interaction successfully. |
"deny" |
Refuse the interaction and suppress applicable fallback use. |
Booleans are invalid interaction results. Handler exceptions or invalid results are reported and disable the handler for the current registration.
Prefer the read-only betamoon.callbackResults.pass, .handled, and .deny constants in callback code. The literal strings in the table remain accepted.
Runs before the targeted block's normal activation. Receives a block target. Mutable context; return an interaction outcome. A handled result intercepts activation.
onUseFirst = { action = function(ctx)
return betamoon.callbackResults.pass
end }Handles use against a block after earlier first-use/block handling permits item use. ctx.target.kind is "block"; position and face identify the clicked target. Return an interaction outcome.
onUseOnBlock = { action = function(ctx)
return ctx.target.block:rotate("clockwise")
and betamoon.callbackResults.handled
or betamoon.callbackResults.pass
end }Handles ordinary/fallback right-click use. Target is normally "miss"; use ctx:rayTrace() to explicitly inspect a block ahead. Return an interaction outcome.
onUse = { action = function(ctx)
return betamoon.callbackResults.handled
end }Handles interaction with an entity. ctx.target.kind is "entity", ctx.target.entity and ctx.entity expose it. Mutable context; return an interaction outcome.
onUseOnEntity = { action = function(ctx)
return betamoon.callbackResults.pass
end }Notifies a successful hit using this item. Adds target entity access. Mutable context.
onHitEntity = { action = function(ctx)
local isPlayer = ctx.entity:isPlayer()
end }Notifies destruction of a block using this item. Includes integer blockId for the destroyed block. Mutable context.
onBlockDestroyed = { action = function(ctx)
betamoon.chat:send("Destroyed %d", ctx.blockId)
end }Notifies crafting this item. Uses item context with player/stack where available. Mutable context.
onCrafted = { action = function(ctx)
betamoon.chat:send("Crafted item %d", ctx.stack.id)
end }Queries whether the item can harvest a block. Return boolean or nil for the material/tool fallback. Context fields are itemId and block = { id, damage }; no world/player/stack live access is provided.
canHarvest = { action = function(ctx)
if ctx.block.id == 49 then return true end
return nil
end }Queries mining speed for a block. Same query context as canHarvest. Return a finite number 0–100000, or nil for normal speed. Invalid results fall back and disable the handler.
getMiningSpeed = { action = function(ctx)
if ctx.block.id == 1 then return 8 end
return nil
end }Runs for stacks in an inventory at the configured interval.
onInventoryTick = {
interval = 20, when = "selected",
action = function(ctx)
local count = ctx.stack:getCount()
end
}| Field | Type | Default / meaning |
|---|---|---|
action |
function(ctx) | Required callback. |
interval |
integer 1–1000000 | 1 tick; filters world tick cadence. |
when |
string |
always or selected; default always. |
Adds slot (native inventory slot index), selected (boolean), and entity (inventory holder). Player access exists only for a player holder.
Examples: Item interactions, targeted actions, tool queries.
- Installation
- Install scripts
- Getting started
- VS Code and LuaLS
- Examples
- Reload and compatibility
- Troubleshooting
- Changelog
Scripts and shared values
- Script lifecycle
- Packaged Lua mods
- Modules
- References and stacks
- Queries
- Overrides
- Minecraft constants
- Chat and positions
- Structured data
- Script configuration
- Particles
Blocks and items
- Multiblocks
- Blocks
- Block state and placement
- Block shapes and rendering
- Block callbacks
- Block ticks and redstone
- Items
- Fluids
- Item callbacks
- Tools and armor
- Materials
- Textures
Entities
- Entities
- Entity access and movement
- Entity lifecycle and data
- Entity health and loot
- Entity inventories and relationships
- Projectiles and pickups
- Entity presentation and sounds
- Living entities and AI
- Entity parts and sensors
Assets and audio
- Assets
- Models and animations
- Built-in Minecraft models
- Model appearances
- Blockbench workflow
- Audio
- Texture-pack overrides
Events and world actions
World generation
World systems
Inventories and screens
Recipes