This page as Markdown: https://bloxd.io/docs/callbacks.md. Every page of these docs, for AI agents: https://bloxd.io/docs/llms.txt

Callbacks

Players can use World Code in custom worlds get functions they've written to run when game events happen. These special functions are called callbacks. The world code can be viewed by pressing F8 by default. Initially the world code will have this comment, which can be removed:

tick onClose onPlayerJoin onPlayerLeave onPlayerJump onRespawnRequest
playerCommand onPlayerChat onPlayerAttemptChangeBlock onPlayerChangeBlock
onPlayerDropItem onPlayerPickedUpItem onPlayerSelectInventorySlot
onBlockStand onBlockStandStart onBlockStandStop onPlayerAttemptCraft
onPlayerCraft onPlayerAttemptOpenChest onPlayerOpenedChest
onPlayerMoveItemOutOfInventory onPlayerMoveInvenItem onPlayerMoveItemIntoIdxs
onPlayerSwapInvenSlots onPlayerMoveInvenItemWithAmt onPlayerAttemptAltAction
onPlayerAltAction onPlayerClick onPlayerClickUp onClientOptionUpdated
onMobSettingUpdated onInventoryUpdated onChestUpdated
onWorldAttemptChangeBlock onWorldChangeBlock onCreateBloxdMeshEntity
onEntityCollision onPlayerAttemptSpawnMob onWorldAttemptSpawnMob
onPlayerSpawnMob onWorldSpawnMob onWorldAttemptDespawnMob onMobDespawned
onPlayerAttemptSpawnVehicle onWorldAttemptSpawnVehicle onPlayerSpawnVehicle
onWorldSpawnVehicle onVehicleDespawned onEntityDeleted onPlayerAttack
onPlayerDamagingOtherPlayer onPlayerDamagingMob onMobDamagingPlayer
onMobDamagingOtherMob onAttemptKillPlayer onPlayerKilledOtherPlayer
onMobKilledPlayer onPlayerKilledMob onMobKilledOtherMob onPlayerPotionEffect
onPlayerDamagingMeshEntity onPlayerBreakMeshEntity onPlayerUsedThrowable
onPlayerThrowableHitTerrain onTouchscreenActionButton onTaskClaimed
onChunkLoaded onPlayerRequestChunk onItemDropCreated
onPlayerStartChargingItem onPlayerFinishChargingItem onPlayerAttemptFish
onPlayerSucceededFishCatch onPlayerFailedFishCatch onPlayerFinishQTE
onPlayerToggledShopMenu onPlayerPlayedEmote onPlayerEnteredVehicle
onPlayerExitedVehicle onPlayerBoughtShopItem onPlayerPressedButton
onPlayerReleasedButton onUiRequestResponded doPeriodicSave

To use a callback, just assign a function to it in the world code!
tick = () => {}			 or			 function tick() {}

You can use api.setCallbackValueFallback("callbackName", defaultValue) to set a default value to be returned by your callback code if it throws an error.

doPeriodicSave

Called every so often.

You should save custom db values/s3 objects here.

Persisted items ARE saved on graceful shutdown (e.g. uncaught error, update, etc),

but this helps prevent large data-loss on non-graceful shutdowns.

Parameters:

ParameterTypeDescription

onAttemptKillPlayer

Called when a player is about to be killed

Return "preventDeath" to prevent the player from being killed

Parameters:

ParameterTypeDescription
killedPlayerPlayerIdThe id of the player being killed
attackingLifeformLifeformIdThe optional id of the lifeform attacking the player

Returns:

void \| "preventDeath"

onBlockStand

Called when a player stands on a block

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that stood on the block
xnumberThe x coordinate of the block that was stood on
ynumberThe y coordinate of the block that was stood on
znumberThe z coordinate of the block that was stood on
blockNameBlockNameThe name of the block that was stood on

onBlockStandStart

Called when a player enters a block. Only called once per block until the player leaves the block.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that entered the block
xnumberThe x coordinate of the block that was entered
ynumberThe y coordinate of the block that was entered
znumberThe z coordinate of the block that was entered
blockNameBlockNameThe name of the block that was entered

onBlockStandStop

Called when a player leaves a block.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that left the block
xnumberThe x coordinate of the block that was left
ynumberThe y coordinate of the block that was left
znumberThe z coordinate of the block that was left
blockNameBlockNameThe name of the block that was left

onChestUpdated

Called when a chest is updated by a player

x, y, z, will be null if isMoonstoneChest is true

Parameters:

ParameterTypeDescription
initiatorEIdPlayerIdThe id of the player who updated the chest
isMoonstoneChestbooleanWhether the chest is a moonstone chest
xnumber | nullThe x coordinate of the chest
ynumber | nullThe y coordinate of the chest
znumber | nullThe z coordinate of the chest

onChunkLoaded

Called when a chunk is first loaded

API Methods that modify the chunk like setBlock cannot be used here to make

persisted changes, and will introduce client-server desync most cases,

but might have some creative uses if you know what you're doing.

For most use cases, consider using another callback e.g. tick.

Parameters:

ParameterTypeDescription
chunkIdstringThe id of the chunk being loaded
chunkLoadedChunkThe chunk being loaded, which can be modified by this callback * For world code callbacks this value will always be null.
wasPersistedChunkbooleanWhether the chunk was persisted

onClientOptionUpdated

Called when a client option is updated

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player whose option was updated
optionClientOptionThe option that was updated
valueanyThe new value of the option, always null for custom code

onClose

Called when the lobby is shutting down

Parameters:

ParameterTypeDescription
serverIsShuttingDownbooleanWhether the server is shutting down

onCreateBloxdMeshEntity

Called when a mesh entity is created

Parameters:

ParameterTypeDescription
eIdEntityIdThe id of the mesh entity
typestringThe type of mesh entity
initiatorIdEntityId | nullThe id of the entity that created the mesh entity, if any

onEntityCollision

Called when a entity collides with another entity

Parameters:

ParameterTypeDescription
eIdEntityIdThe id of the entity
otherEIdEntityIdThe id of the other entity

onEntityDeleted

Called when any non-player entity is deleted, after any type specific callback such as "onMobDespawned".

Not called when an item drop is picked up or expires, or when a throwable expires or hits something.

Parameters:

ParameterTypeDescription
eIdEntityIdThe id of the entity deleted
entityTypeEntityTypeThe type of the entity deleted

onInventoryUpdated

Called when a player's inventory is updated

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player whose inventory was updated

onItemDropCreated

Called when an item drop is created

Parameters:

ParameterTypeDescription
itemEIdEntityIdThe id of the item drop
itemNamestringThe name of the item dropped
itemAmountnumberThe amount dropped
xnumberThe x coordinate of the item drop
ynumberThe y coordinate of the item drop
znumberThe z coordinate of the item drop

onMobDamagingOtherMob

Called when a mob is damaging another mob

Return "preventDamage" to prevent damage

Return number to change damage dealt to that amount

Parameters:

ParameterTypeDescription
attackingMobMobIdthe id of the mob attacking
damagedMobMobIdthe id of the mob being damaged
damageDealtnumberthe amount of damage dealt
withItemstringthe item used to attack
damageInfoDamageInfowhat dealt the hit: a melee swing, an explosion, a projectile, etc.

Returns:

number \| void \| "preventDamage"

onMobDamagingPlayer

Called when a mob is damaging a player

Return "preventDamage" to prevent damage

Return number to change damage dealt to that amount

Parameters:

ParameterTypeDescription
attackingMobMobIdthe id of the mob damaging the player
damagedPlayerPlayerIdthe id of the player being damaged
damageDealtnumberthe amount of damage dealt
withItemstringthe item used to attack
damageInfoDamageInfowhat dealt the hit: a melee swing, an explosion, a projectile, etc.

Returns:

number \| void \| "preventDamage"

onMobDespawned

Called when a mob is despawned

Parameters:

ParameterTypeDescription
mobIdMobIdThe id of the mob despawned

onMobKilledOtherMob

Called when a mob kills another mob

Return "preventDrop" to prevent the mob from dropping items

Parameters:

ParameterTypeDescription
attackingMobMobIdThe id of the mob attacking
killedMobMobIdThe id of the mob killed
damageDealtnumberThe amount of damage dealt
withItemstringThe item used to attack

Returns:

void \| "preventDrop"

onMobKilledPlayer

Called when a mob kills a player

Return "keepInventory" to not drop the player's inventory

Parameters:

ParameterTypeDescription
attackingMobanyThe id of the mob attacking
killedPlayeranyThe id of the player killed
damageDealtanyThe amount of damage dealt
withItemanyThe item used to attack

Returns:

void \| "keepInventory"

onMobSettingUpdated

Called when a mob setting is updated

Parameters:

ParameterTypeDescription
mobIdMobIdThe id of the mob whose setting was updated
settingMobSettingThe setting that was updated
valueanyThe new value of the setting

onPlayerAltAction

Called when player completes an alt action. Right click, the interact bind (E by default) and a mobile tap all arrive here; a left click does not, so this is the callback to use for anything a player should have to choose to do rather than trigger by swinging.

Keeps firing while the input is held, roughly every 50-150ms. That is harmless for anything idempotent, but an interaction that grants an item, charges a currency or advances a conversation has to swallow the repeats itself - open shops with toggle off, and debounce the rest per player.

The co-ordinates will be undefined if there is no targeted block (and block will be "Air")

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player completing the alt action
xnumberThe x coordinate of the targeted block
ynumberThe y coordinate of the targeted block
znumberThe z coordinate of the targeted block
blockBlockNameThe name of the targeted block
targetEIdEntityId | nullThe id of the targeted entity

onPlayerAttack

Called when a player attacks another player

Parameters:

ParameterTypeDescription
playerIdstringThe id of the player attacking

onPlayerAttemptAltAction

Called when player alt actions (right click on pc).

The co-ordinates will be undefined if there is no targeted block (and block will be "Air")

Some actions can be prevented by returning "preventAction",

but this may not work as well for certain actions which the game client predicts to succeed -

test it to see if it works for your use case, feel free to report any broken ones.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player attempting the alt action
xnumberThe x coordinate of the targeted block
ynumberThe y coordinate of the targeted block
znumberThe z coordinate of the targeted block
blockBlockNameThe name of the targeted block
targetEIdEntityId | nullThe id of the targeted entity

Returns:

void \| "preventAction"

onPlayerAttemptChangeBlock

Called before a player changes a block.

Return "preventChange" to stop it. Then onPlayerChangeBlock will not run.

Growing EZ placements validate at request time and again at completion; keep validation free of rewards or charges.

When placing, fromBlock is Air, or the slab a matching slab completes. When breaking, toBlock is Air.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe player trying to change the block
xnumberThe block's x coordinate
ynumberThe block's y coordinate
znumberThe block's z coordinate
fromBlockBlockNameThe current block
toBlockBlockNameThe proposed block
droppedItemBlockName | nullThe item that would drop
fromBlockInfoMultiBlockInfoThe current multiblock info
toBlockInfoMultiBlockInfoThe proposed multiblock info

Returns:

void \| "preventChange"

onPlayerAttemptCraft

Called when a player attempts to craft an item

Return "preventCraft" to prevent a craft from happening

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that is attempting to craft the item
itemNamestringThe name of the item that is being crafted
craftingIdxnumberThe index of the used recipe in the item's recipe list
craftTimesnumberThe number of times the craft recipe is used at once (e.g. shift held while crafting)

Returns:

void \| "preventCraft"

onPlayerAttemptFish

Called once when a fishing hook first enters water. Coordinates are the bob's position at water entry.

Return "preventFish" to cancel, or { caughtItemName?, biteDelayMs?, qte? } to select the fish and override the rod's bite delay

and nine-second timed-click QTE. Default delays are Rusty 7–9 seconds, Sturdy 5–7, and Carbon/other rods 2–4.

The selected fish is fixed for the attempt; omitting caughtItemName uses the engine's default fish selection.

Parameters:

ParameterTypeDescription
playerIdPlayerId
rodNamestring
xnumber
ynumber
znumber

Returns:

void \| FishingAttemptOptions \| "preventFish"

onPlayerAttemptOpenChest

Called when a player attempts to open a chest

Return "preventOpen" to prevent the player from opening the chest

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that is attempting to open the chest
xnumberThe x coordinate of the chest that the player is attempting to open
ynumberThe y coordinate of the chest that the player is attempting to open
znumberThe z coordinate of the chest that the player is attempting to open
isMoonstoneChestbooleanWhether the chest is a moonstone chest
isIronChestbooleanWhether the chest is an iron chest

Returns:

void \| "preventOpen"

onPlayerAttemptSpawnMob

Called when a player attempts to spawn a mob, e.g. using a spawn orb.

Return "preventSpawn" to prevent the mob from spawning.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player
mobTypeMobTypeThe type of mob
xnumberThe potential x coordinate of the mob
ynumberThe potential y coordinate of the mob
znumberThe potential z coordinate of the mob

Returns:

void \| "preventSpawn"

onPlayerAttemptSpawnVehicle

Called when a vehicle is spawned on a player's behalf.

Return "preventSpawn" to prevent the vehicle from spawning.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player
vehicleTypeMeshEntityVehicleTypeThe type of vehicle
xnumberThe potential x coordinate of the vehicle
ynumberThe potential y coordinate of the vehicle
znumberThe potential z coordinate of the vehicle

Returns:

void \| "preventSpawn"

onPlayerBoughtShopItem

Called after a player successfully buys a shop item

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that bought the item
categoryKeyShopCategoryKeyThe shop category key
itemKeyShopItemKeyThe shop item key
itemBoughtShopItemThe resolved shop item (with per-player overrides applied, internal properties stripped)
userInputstringThe user input provided, if the item has a userInput config

onPlayerBreakMeshEntity

Called when a player breaks a mesh entity

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player breaking the mesh entity
entityIdEntityIdThe id of the mesh entity being broken

onPlayerChangeBlock

In World Code, called once after all attempt callbacks allow a player block change, before the block is set.

The current block and its data are still available. Return "preventChange" to cancel the request.

Return "preventDrop" to stop the engine item drop, or [x, y, z] to set its position.

Drop returns do not skip built-in validation or change notifications; any "preventDrop" takes precedence over a position.

A block written here with api.setBlock is preserved, with normal drops/inventory charges unless the request is cancelled.

Cancellation does not undo your own script effects. Built-in change effects run after this callback.

For growing EZ placements this runs at request time only; completion validates again without repeating this callback.

Writing the target yourself completes that EZ request immediately, without delayed growth or a growth refund.

Native games/plugins receive uninterrupted before-commit notifications and must veto in onPlayerAttemptChangeBlock.

When placing, fromBlock is Air, or the slab a matching slab completes. When breaking, toBlock is Air.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that changed the block
xnumberThe x coordinate of the block that was changed
ynumberThe y coordinate of the block that was changed
znumberThe z coordinate of the block that was changed
fromBlockBlockNameThe old block that was replaced
toBlockBlockNameThe new block that was placed
droppedItemBlockName | nullThe item that was dropped
fromBlockInfoMultiBlockInfoThe info of the old block that was replaced
toBlockInfoMultiBlockInfoThe info of the new block that was placed
dropsPreventedbooleanWhether earlier notifications prevented drops; false during World Code validation

Returns:

void \| "preventChange" \| "preventDrop" \| [number, number, number]

onPlayerChat

Called when a player sends a chat message

Return false or null to prevent the broadcast of the message.

Return a string or CustomTextStyling to add a prefix to message.

Return for most flexibility: an object where keys are playerIds -

the value for a playerId being false means that player won't receive the message.

Otherwise playerId values should be an object with (optional) keys

prefixContent and chatContent to modify the prefix and the chat.

CustomTextStyling[] prefixContent is expected, e.g. [["prefix"]] or [[{ str: "prefix" }]].

World code is not permitted to specify chatContent, it will be ignored.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that sent the message
chatMessagestringThe message that the player sent
channelNamestringThe name of the channel that the message was sent in

Returns:

boolean \| void \| ChatTags \| OnPlayerChatObjectResponse

onPlayerClick

Called when a player clicks

Don't have important functionality depending on wasAltClick,

as it'll always be false for touchscreen players.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player clicking
wasAltClickbooleanWhether the click was an alt click (e.g. right click
xnumber
ynumber
znumber
blockBlockName
targetEIdEntityId | null

onPlayerClickUp

Called when a player releases a click (mouse-up on desktop, touch-end on mobile).

Fires for both primary and secondary click releases.

Keep in mind wasAltClick will always be false for touchscreen players.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player releasing click
wasAltClickbooleanWhether the released click was an alt click (e.g. right click
xnumber
ynumber
znumber
blockBlockName
targetEIdEntityId | null

onPlayerCraft

Called when a player crafts an item

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that crafted the item
itemNamestringThe name of the item that was crafted
craftingIdxnumberThe index of the used recipe in the item's recipe list
recipeRecipesForItem[number]The recipe that was used to craft the item
craftTimesnumberThe number of times the craft recipe is used at once (e.g. shift held while crafting)

onPlayerDamagingMeshEntity

Called when a player is damaging a mesh entity

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player damaging the mesh entity
damagedIdEntityIdThe id of the mesh entity being damaged
damageDealtnumberThe amount of damage dealt
withItemstringThe item used to attack

onPlayerDamagingMob

Called when a player is damaging a mob

Return "preventDamage" to prevent damage

Return number to change damage dealt to that amount

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player damaging the mob
mobIdMobIdThe id of the mob being damaged
damageDealtnumberThe amount of damage dealt
withItemstringThe item used to attack
damagerDbIdPlayerDbIdThe database id of the player attacking
damageInfoDamageInfoWhat dealt the hit: a melee swing, an explosion, a projectile, etc.

Returns:

number \| void \| "preventDamage"

onPlayerDamagingOtherPlayer

Called when a player is damaging another player

Return "preventDamage" to prevent damage

Return number to change damage dealt to that amount

Sometimes the damager will have left the game (e.g. spikes placer);

in this case, attackingPlayer will be the damagedPlayer,

but we pass damagerDbId for use cases where it's important.

Parameters:

ParameterTypeDescription
attackingPlayerPlayerIdThe id of the player attacking
damagedPlayerPlayerIdThe id of the player being damaged
damageDealtnumberThe amount of damage dealt
withItemstringThe item used to attack
bodyPartHitLifeformBodyPartThe body part hit
damagerDbIdPlayerDbIdThe database id of the player attacking
damageInfoDamageInfoWhat dealt the hit: a melee swing, an explosion, a projectile, etc.

Returns:

number \| void \| "preventDamage"

onPlayerDropItem

Called when a player drops an item

Return "preventDrop" to prevent the player from dropping the item at all.

Return "allowButNoDroppedItemCreated" to allow discarding items without dropping them.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that dropped the item
xnumberThe x coordinate of the item that was dropped
ynumberThe y coordinate of the item that was dropped
znumberThe z coordinate of the item that was dropped
itemNameItemNameThe name of the item that was dropped
itemAmountnumberThe amount of the item that was dropped
fromIdxnumberThe index of the item that was dropped from the player's inventory

Returns:

void \| "preventDrop" \| "allowButNoDroppedItemCreated"

onPlayerEnteredVehicle

Called when a player enters a vehicle

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that entered the vehicle
vehicleTypeMeshEntityVehicleTypeThe type of the vehicle
vehicleEIdEntityIdThe id of the vehicle

onPlayerExitedVehicle

Called when a player exits a vehicle

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that exited the vehicle
vehicleTypeMeshEntityVehicleTypeThe type of the vehicle
vehicleEIdEntityIdThe id of the vehicle

onPlayerFailedFishCatch

Called after the fishing QTE fails or its time window expires, after removing the bob/session.

Coordinates are the fishing position captured at water entry. Retracting, switching rods, dying, and leaving cancel silently.

caughtItemName is the item selected for the failed attempt; no reward is given.

Parameters:

ParameterTypeDescription
playerIdPlayerId
rodNamestring
xnumber
ynumber
znumber
caughtItemNameItemName

onPlayerFinishChargingItem

Called when a player finishes charging an item

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player charging the item
usedbooleanWhether the item was used
itemNamestringThe name of the charged item
durationnumberThe duration of the charge

onPlayerFinishQTE

Parameters:

ParameterTypeDescription
playerIdPlayerId
qteIdQTERequestId
resultboolean

onPlayerJoin

Called when a player joins the lobby

Parameters:

ParameterTypeDescription
playerIdstringThe id of the player that joined
fromGameResetbooleanWhether this call is from a game reset (used by SessionBasedGame)

onPlayerJump

Called when a player jumps

Parameters:

ParameterTypeDescription
playerIdstringThe id of the player that jumped

onPlayerKilledMob

Called when a player kills a mob

Return "preventDrop" to prevent the mob from dropping items

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player killed
mobIdMobIdThe id of the mob that killed the player
damageDealtnumberThe amount of damage dealt
withItemstringThe item used to attack

Returns:

void \| "preventDrop"

onPlayerKilledOtherPlayer

Called when a player kills another player

Return "keepInventory" to not drop the player's inventory

Parameters:

ParameterTypeDescription
attackingPlayerstringThe id of the player attacking
killedPlayerstringThe id of the player killed
damageDealtnumberThe amount of damage dealt
withItemstringThe item used to attack

Returns:

void \| "keepInventory"

onPlayerLeave

Called when a player leaves the lobby

Parameters:

ParameterTypeDescription
playerIdstringThe id of the player that left
serverIsShuttingDownbooleanWhether the server is shutting down

onPlayerMoveInvenItem

Called for all types of inventory item movement.

Certain methods of moving item can result in splitting a stack

into multiple slots. (e.g. shift-click).

toStartIdx and toEndIdx provide the min and max idxs moved into.

Return "preventChange" to prevent item movement.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player moving the item
fromIdxnumberThe index that the item is being moved from
toStartIdxnumberThe start index that the item is being moved into
toEndIdxnumberThe end index that the item is being moved into
amtnumberThe amount of the item being moved

Returns:

void \| "preventChange"

onPlayerMoveInvenItemWithAmt

Return "preventChange" to prevent the movement

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player moving the item
inumberThe index of the first slot
jnumberThe index of the second slot
amtnumberThe amount of the item being moved

Returns:

void \| "preventChange"

onPlayerMoveItemIntoIdxs

Called when a player moves an item into an index within a range of inventory slots

Return "preventChange" to prevent the movement

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player moving the item
startnumberThe start index of the range
endnumberThe end index of the range
moveIdxnumberThe index of the item being moved
itemAmountnumberThe amount of the item being moved

Returns:

void \| "preventChange"

onPlayerMoveItemOutOfInventory

Called when a player moves an item out of their inventory

Return "preventChange" to prevent the movement

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player moving the item
itemNamestringThe name of the item being moved
itemAmountnumberThe amount of the item being moved
fromIdxnumberThe index which the item is being moved from
movementTypestringThe type of movement that occurred

Returns:

void \| "preventChange"

onPlayerOpenedChest

Called when a player opens a chest

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that opened the chest
xnumberThe x coordinate of the chest that was opened
ynumberThe y coordinate of the chest that was opened
znumberThe z coordinate of the chest that was opened
isMoonstoneChestbooleanWhether the chest is a moonstone chest
isIronChestbooleanWhether the chest is an iron chest

onPlayerPickedUpItem

Called when a player picks up an item

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that picked up the item
itemNamestringThe name of the item that was picked up
itemAmountnumberThe amount of the item that was picked up
itemEntityIdEntityIdThe entityId of the item that was picked up

onPlayerPlayedEmote

/** Called after a player plays an emote from the emote wheel. */

Parameters:

ParameterTypeDescription
playerIdPlayerId
emoteIdstring

onPlayerPotionEffect

Called when a player is affected by a new potion effect

Parameters:

ParameterTypeDescription
initiatorIdstringThe id of the player who initiated the potion effect
targetIdstringThe id of the player who has started being affected
effectName"Damage" | "Speed" | "Damage Reduction" | "Invisible" | "Jump Boost" | "Knockback" | "Poisoned" | "Slowness" | "Weakness" | "Cleansed" | "Instant Damage" | "Health Regen" | "Healing Pulse" | "Instant Health" | "Haste" | "Shield" | "Double Jump" | "Heat Resistance" | "Thief" | "X-Ray Vision" | "Mining Yield" | "Brain Rot" | "Aura" | "Wall Climbing" | "Air Walk" | "Pickpocketer" | "Lifesteal" | "Bounciness" | "Blindness" | "Poopy" | "Glowing" | "Night Vision"The name of the potion effect

Returns:

void \| "preventEffect"

onPlayerPressedButton

Called when a player presses a custom button

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player pressing the button
buttonIdstringThe id of the button pressed

onPlayerReleasedButton

Called when a player releases a custom button

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player releasing the button
buttonIdstringThe id of the button released

onPlayerRequestChunk

Called when a player requests a chunk

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player requesting the chunk
chunkXnumberThe x coordinate of the chunk being requested
chunkYnumberThe y coordinate of the chunk being requested
chunkZnumberThe z coordinate of the chunk being requested
chunkIdstringThe id of the chunk being requested

onPlayerSelectInventorySlot

Called when a player selects a different inventory slot.

This will be called eventually when you have already set the slot using

api.setSelectedInventorySlotI so be careful not to cause an infinite loop doing this.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that selected the inventory slot
slotIndexnumberThe index of the inventory slot that was selected

onPlayerSpawnMob

Called when a mob is spawned by a player

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player who spawned the mob
mobIdMobIdThe id of the mob
mobTypeMobTypeThe type of mob
xnumberThe x coordinate of the mob
ynumberThe y coordinate of the mob
znumberThe z coordinate of the mob
mobHerdIdMobHerdIdThe herd id of the mob
playSoundOnSpawnbooleanWhether to play a sound on spawn

onPlayerSpawnVehicle

Called when a vehicle is spawned by a player, e.g. by placing a boat

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player who spawned the vehicle
vehicleEIdEntityIdThe id of the vehicle
vehicleTypeMeshEntityVehicleTypeThe type of vehicle
xnumberThe x coordinate of the vehicle
ynumberThe y coordinate of the vehicle
znumberThe z coordinate of the vehicle

onPlayerStartChargingItem

Called when a player starts charging an item

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player charging the item
itemNamestringThe name of the item being charged

Returns:

void \| "preventCharge"

onPlayerSucceededFishCatch

Called after the fishing QTE succeeds and the bob/session have been removed.

Coordinates are the fishing position captured at water entry. caughtItemName is the item selected for the attempt.

Returning nothing gives one of that item, or drops it if the inventory is full.

Return "preventDrop" to suppress the default reward and award custom catches here instead.

Return "preventItemGrant" to deliver the item yourself while keeping the default catch effects.

Parameters:

ParameterTypeDescription
playerIdPlayerId
rodNamestring
xnumber
ynumber
znumber
caughtItemNameItemName

Returns:

void \| "preventDrop" \| "preventItemGrant"

onPlayerSwapInvenSlots

Return "preventChange" to prevent the swap

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player swapping the inventory slots
inumberThe index of the first slot
jnumberThe index of the second slot

Returns:

void \| "preventChange"

onPlayerThrowableHitTerrain

Called when a player's thrown projectile hits the terrain

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player that threw the throwable item
throwableNameThrowableItemThe name of the throwable item
thrownEntityIdEntityIdThe id of the entity which hit the terrain

onPlayerToggledShopMenu

Called when a player opens or closes the shop menu

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player whose shop menu changed
isOpenbooleanWhether the shop menu is now open

onPlayerUsedThrowable

Called when a player uses a throwable item

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player using the throwable item
throwableNameThrowableItemThe name of the throwable item
thrownEntityIdEntityIdThe id of the projectile created by the player

onRespawnRequest

Called when a player requests to respawn.

Optionally return the respawn location. Defaults to [0, 0, 0].

Return true to handle yourself (good for async,

but be careful that the player isn't at the place they died,

as they could pick up their old items or hit the player they were fighting).

Parameters:

ParameterTypeDescription
playerIdstringThe id of the player that requested to respawn

Returns:

true \| void \| number[]

onTaskClaimed

Called when a player claims a task

Parameters:

ParameterTypeDescription
playerIdstringThe id of the player claiming the task
taskIdanyThe id of the task being claimed
isPromoTaskanyWhether the task is a promo task
claimedRewardsanyThe rewards claimed by the player

Returns:

any

onTouchscreenActionButton

Set client option touchscreenActionButton to take effect

Called when a player presses the touchscreen action button

Called for both touchDown and touchUp

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player pressing the touchscreen action button
touchDownbooleanWhether the touchscreen action button was pressed or released

onUiRequestResponded

Called when a player responds to a UI request.

Parameters:

ParameterTypeDescription
playerIdPlayerIdThe id of the player responding to the UI request.
idUiRequestIdThe id of the UI request.
responsebooleanThe response to the UI request.

onVehicleDespawned

Called when a vehicle is despawned

Parameters:

ParameterTypeDescription
vehicleEIdEntityIdThe id of the vehicle despawned
vehicleTypeMeshEntityVehicleTypeThe type of vehicle despawned

onWorldAttemptChangeBlock

Called before the world changes a block.

Return "preventChange" to stop it. Then onWorldChangeBlock will not run.

Parameters:

ParameterTypeDescription
xnumberThe block's x coordinate
ynumberThe block's y coordinate
znumberThe block's z coordinate
fromBlockBlockNameThe current block
toBlockBlockNameThe proposed block
initiatorDbIdstring | nullThe player who caused the change, or null for game code
extraInfoWorldBlockChangedInfoMore information about the change

Returns:

void \| "preventChange"

onWorldAttemptDespawnMob

Called when a mob is despawned by the world.

Return "preventDespawn" to prevent the mob from despawning.

Parameters:

ParameterTypeDescription
mobIdMobIdThe id of the mob despawned

Returns:

void \| "preventDespawn"

onWorldAttemptSpawnMob

Called when the world attempts to spawn a mob.

Return "preventSpawn" to prevent the mob from spawning.

Parameters:

ParameterTypeDescription
mobTypeMobTypeThe type of mob
xnumberThe potential x coordinate of the mob
ynumberThe potential y coordinate of the mob
znumberThe potential z coordinate of the mob

Returns:

void \| "preventSpawn"

onWorldAttemptSpawnVehicle

Called when the world attempts to spawn a vehicle.

Return "preventSpawn" to prevent the vehicle from spawning.

Parameters:

ParameterTypeDescription
vehicleTypeMeshEntityVehicleTypeThe type of vehicle
xnumberThe potential x coordinate of the vehicle
ynumberThe potential y coordinate of the vehicle
znumberThe potential z coordinate of the vehicle

Returns:

void \| "preventSpawn"

onWorldChangeBlock

In World Code, called after all attempt callbacks allow a world block change, before the block is set.

Read the old block/data here; return "preventChange" to cancel the request, or "preventDrop" to stop its engine item drop.

Drop prevention does not skip built-in validation or change notifications.

Blocks/data written here are preserved. Cancelling the original request does not undo your script effects.

Native games/plugins receive uninterrupted before-commit notifications and must veto in onWorldAttemptChangeBlock.

initiatorDbId is null for game code, such as a growing sapling.

Parameters:

ParameterTypeDescription
xnumberThe x coordinate of the block
ynumberThe y coordinate of the block
znumberThe z coordinate of the block
fromBlockBlockNameThe old block that was replaced
toBlockBlockNameThe new block that was placed
initiatorDbIdstring | nullThe id of the player who updated the block
extraInfoWorldBlockChangedInfoExtra info about the block change
dropsPreventedbooleanWhether earlier notifications prevented drops; false during World Code validation

Returns:

void \| "preventChange" \| "preventDrop"

onWorldSpawnMob

Called when a mob is spawned by the world

Parameters:

ParameterTypeDescription
mobIdMobIdThe id of the mob
mobTypeMobTypeThe type of mob
xnumberThe x coordinate of the mob
ynumberThe y coordinate of the mob
znumberThe z coordinate of the mob
mobHerdIdMobHerdIdThe herd id of the mob
playSoundOnSpawnbooleanWhether to play a sound on spawn

onWorldSpawnVehicle

Called when a vehicle is spawned by the world

Parameters:

ParameterTypeDescription
vehicleEIdEntityIdThe id of the vehicle
vehicleTypeMeshEntityVehicleTypeThe type of vehicle
xnumberThe x coordinate of the vehicle
ynumberThe y coordinate of the vehicle
znumberThe z coordinate of the vehicle

playerCommand

Called when a player sends a command

Parameters:

ParameterTypeDescription
playerIdstringThe id of the player that sent the command
commandstringThe command that the player sent

Returns:

boolean

tick

Called every tick, 20 times per second

Parameters:

ParameterTypeDescription
msnumberThe fixed timestep, can be used as "milliseconds since last tick"
Logo