# Callbacks, part 3 of 3

Part 3 of 3 of [Callbacks](https://bloxd.io/docs/callbacks.md). It covers onPlayerMoveItemIntoIdxs to tick. [llms.txt](https://bloxd.io/docs/llms.txt) lists every part.

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

Return "preventChange" to prevent the movement

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player moving the item |
| start | `number` | The start index of the range |
| end | `number` | The end index of the range |
| moveIdx | `number` | The index of the item being moved |
| itemAmount | `number` | The 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:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player moving the item |
| itemName | `string` | The name of the item being moved |
| itemAmount | `number` | The amount of the item being moved |
| fromIdx | `number` | The index which the item is being moved from |
| movementType | `string` | The type of movement that occurred |


### Returns:
`void \| "preventChange"`

## onPlayerOpenedChest
Called when a player opens a chest

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player that opened the chest |
| x | `number` | The x coordinate of the chest that was opened |
| y | `number` | The y coordinate of the chest that was opened |
| z | `number` | The z coordinate of the chest that was opened |
| isMoonstoneChest | `boolean` | Whether the chest is a moonstone chest |
| isIronChest | `boolean` | Whether the chest is an iron chest |

## onPlayerPickedUpItem
Called when a player picks up an item

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player that picked up the item |
| itemName | `string` | The name of the item that was picked up |
| itemAmount | `number` | The amount of the item that was picked up |
| itemEntityId | `EntityId` | The entityId of the item that was picked up |

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

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` |  |
| emoteId | `string` |  |

## onPlayerPotionEffect
Called when a player is affected by a new potion effect

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| initiatorId | `string` | The id of the player who initiated the potion effect |
| targetId | `string` | The 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:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player pressing the button |
| buttonId | `string` | The id of the button pressed |

## onPlayerReleasedButton
Called when a player releases a custom button

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player releasing the button |
| buttonId | `string` | The id of the button released |

## onPlayerRequestChunk
Called when a player requests a chunk

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player requesting the chunk |
| chunkX | `number` | The x coordinate of the chunk being requested |
| chunkY | `number` | The y coordinate of the chunk being requested |
| chunkZ | `number` | The z coordinate of the chunk being requested |
| chunkId | `string` | The 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:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player that selected the inventory slot |
| slotIndex | `number` | The index of the inventory slot that was selected |

## onPlayerSpawnMob
Called when a mob is spawned by a player

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player who spawned the mob |
| mobId | `MobId` | The id of the mob |
| mobType | `MobType` | The type of mob |
| x | `number` | The x coordinate of the mob |
| y | `number` | The y coordinate of the mob |
| z | `number` | The z coordinate of the mob |
| mobHerdId | `MobHerdId` | The herd id of the mob |
| playSoundOnSpawn | `boolean` | Whether to play a sound on spawn |

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

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player who spawned the vehicle |
| vehicleEId | `EntityId` | The id of the vehicle |
| vehicleType | `MeshEntityVehicleType` | The type of vehicle |
| x | `number` | The x coordinate of the vehicle |
| y | `number` | The y coordinate of the vehicle |
| z | `number` | The z coordinate of the vehicle |

## onPlayerStartChargingItem
Called when a player starts charging an item

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player charging the item |
| itemName | `string` | The 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:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` |  |
| rodName | `string` |  |
| x | `number` |  |
| y | `number` |  |
| z | `number` |  |
| caughtItemName | `ItemName` |  |


### Returns:
`void \| "preventDrop" \| "preventItemGrant"`

## onPlayerSwapInvenSlots
Return "preventChange" to prevent the swap

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player swapping the inventory slots |
| i | `number` | The index of the first slot |
| j | `number` | The index of the second slot |


### Returns:
`void \| "preventChange"`

## onPlayerThrowableHitTerrain
Called when a player's thrown projectile hits the terrain

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player that threw the throwable item |
| throwableName | `ThrowableItem` | The name of the throwable item |
| thrownEntityId | `EntityId` | The id of the entity which hit the terrain |

## onPlayerToggledShopMenu
Called when a player opens or closes the shop menu

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player whose shop menu changed |
| isOpen | `boolean` | Whether the shop menu is now open |

## onPlayerUsedThrowable
Called when a player uses a throwable item

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player using the throwable item |
| throwableName | `ThrowableItem` | The name of the throwable item |
| thrownEntityId | `EntityId` | The 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:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `string` | The id of the player that requested to respawn |


### Returns:
`true \| void \| number[]`

## onTaskClaimed
Called when a player claims a task

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `string` | The id of the player claiming the task |
| taskId | `any` | The id of the task being claimed |
| isPromoTask | `any` | Whether the task is a promo task |
| claimedRewards | `any` | The 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:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player pressing the touchscreen action button |
| touchDown | `boolean` | Whether the touchscreen action button was pressed or released |

## onUiRequestResponded
Called when a player responds to a UI request.



### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `PlayerId` | The id of the player responding to the UI request. |
| id | `UiRequestId` | The id of the UI request. |
| response | `boolean` | The response to the UI request. |

## onVehicleDespawned
Called when a vehicle is despawned

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| vehicleEId | `EntityId` | The id of the vehicle despawned |
| vehicleType | `MeshEntityVehicleType` | The type of vehicle despawned |

## onWorldAttemptChangeBlock
Called before the world changes a block.

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

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| x | `number` | The block's x coordinate |
| y | `number` | The block's y coordinate |
| z | `number` | The block's z coordinate |
| fromBlock | `BlockName` | The current block |
| toBlock | `BlockName` | The proposed block |
| initiatorDbId | `string \| null` | The player who caused the change, or null for game code |
| extraInfo | `WorldBlockChangedInfo` | More 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:
| Parameter | Type | Description |
|-----------|------|-------------|
| mobId | `MobId` | The 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:
| Parameter | Type | Description |
|-----------|------|-------------|
| mobType | `MobType` | The type of mob |
| x | `number` | The potential x coordinate of the mob |
| y | `number` | The potential y coordinate of the mob |
| z | `number` | The 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:
| Parameter | Type | Description |
|-----------|------|-------------|
| vehicleType | `MeshEntityVehicleType` | The type of vehicle |
| x | `number` | The potential x coordinate of the vehicle |
| y | `number` | The potential y coordinate of the vehicle |
| z | `number` | The 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:
| Parameter | Type | Description |
|-----------|------|-------------|
| x | `number` | The x coordinate of the block |
| y | `number` | The y coordinate of the block |
| z | `number` | The z coordinate of the block |
| fromBlock | `BlockName` | The old block that was replaced |
| toBlock | `BlockName` | The new block that was placed |
| initiatorDbId | `string \| null` | The id of the player who updated the block |
| extraInfo | `WorldBlockChangedInfo` | Extra info about the block change |
| dropsPrevented | `boolean` | Whether earlier notifications prevented drops; false during World Code validation |


### Returns:
`void \| "preventChange" \| "preventDrop"`

## onWorldSpawnMob
Called when a mob is spawned by the world

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| mobId | `MobId` | The id of the mob |
| mobType | `MobType` | The type of mob |
| x | `number` | The x coordinate of the mob |
| y | `number` | The y coordinate of the mob |
| z | `number` | The z coordinate of the mob |
| mobHerdId | `MobHerdId` | The herd id of the mob |
| playSoundOnSpawn | `boolean` | Whether to play a sound on spawn |

## onWorldSpawnVehicle
Called when a vehicle is spawned by the world

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| vehicleEId | `EntityId` | The id of the vehicle |
| vehicleType | `MeshEntityVehicleType` | The type of vehicle |
| x | `number` | The x coordinate of the vehicle |
| y | `number` | The y coordinate of the vehicle |
| z | `number` | The z coordinate of the vehicle |

## playerCommand
Called when a player sends a command

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| playerId | `string` | The id of the player that sent the command |
| command | `string` | The command that the player sent |


### Returns:
`boolean`

## tick
Called every tick, 20 times per second

### Parameters:
| Parameter | Type | Description |
|-----------|------|-------------|
| ms | `number` | The fixed timestep, can be used as "milliseconds since last tick" |
