Skip to content
benjamin edited this page Mar 23, 2018 · 4 revisions
This is a detailed documentation of all the hooks available in ModPE

attackHook

function attackHook(attacker, victim) { }
  • Called when an entity is attacked.
  • (Entity) attacker: The entity who attacked.
  • (Entity) victim: The entity who got attacked.

projectileHitBlockHook

function projectileHitBlockHook(projectile, blockX, blockY, blockZ, side) {  }
  • Called when a projectile like an arrow or a snowball hits a block

projectileHitEntityHook

function projectileHitEntityHook(projectile, targetEntity)
  • Called when a projectile like an arrow or a snowball hits a mob

blockEventHook

function blockEventHook(x, y, z, type, data) { }
  • No information available

chatHook

function chatHook(text) { }
  • Called when something has been said in chat
  • (String) text: The message

chatReceiveHook

function chatReceiveHook(str, sender) { }
  • No information available

deathHook

function deathHook(attacker, victim) { }
  • Called when an entity dies.
  • (Entity) attacker: The entity who killed.
  • (Entity) victim: The entity who died.

destroyBlock

function destroyBlock(x, y, z, side) { }
  • Called when a block is destroyed.
  • (Integer) x, y, z: The coordinates of the destroyed block.
  • (Integer) side: The side in which the block is destroyed.
  • Note: When this function is called, the block is ABOUT to be destroyed. After this function is called, the block will be destroyed.

entityAddedHook

function entityAddedHook(entity) { }
  • Called when an entity is added to the game.
  • (Entity) entity: The entity.

entityRemovedHook

function entityRemovedHook(entity) { }
  • Called when an entity is removed from the world.
  • (Entity) entity: The entity.

eatHook

function eatHook(foodpoints, saturationratio) { }

playerAddExpHook(player, experienceAdded)

function playerAddExpHook(player, experienceAdded)
  • Gets called when the player collects xp

playerAddExpHook(player, experienceAdded)

function playerExpLevelChangeHook(player, levelsAdded)
  • Gets called when the players level changes

levelEventHook(player, eventType, x, y, z, data)

function levelEventHook(player, eventType, x, y, z, data) { }
  • Called when a door gets opened or closed. (data: 0 = closing, 1 = opening, 2 = open)

leaveGame

function leaveGame() { }
  • Called when the user exits a world.
  • Accepts no parameters

levelEventHook

function levelEventHook(player, eventType, x, y, z, data) { }
  • No information available

modTick

function modTick() { }
  • Called every game tick. A game tick is 1/20 of a second. (Called 20 times in a second.)
  • Accepts no parameters

newLevel

function newLevel(hasLevel) { }
  • Called when the user starts loading a level.
  • hasLevel: ?

procCmd

function procCmd(cmd) { }
  • Called when a command is entered. (Chat text with "/" prefix.)
  • (String) cmd: The command, with arguments and "/" omitted.

selectLevelHook

function selectLevelHook() { }
  • No information available

serverMessageReceiveHook

function serverMessageReceiveHook(str) { }
  • No information available

startDestroyBlock

function startDestroyBlock(x, y, z, side) { }
  • No information available

useItem

function useItem(x, y, z, itemId, blockId, side, itemDamage, blockDamage) { }
  • Called when a block is tapped.
  • (Integer) x, y, z: The coordinates of the block tapped.
  • (Integer) itemId: The ID of the item held by the player.
  • (Integer) blockId: The ID of the block tapped.
  • (Integer) side: Side of the block tapped.
  • (Integer) itemDamage: Damage value of the item held.
  • (Integer) blockDamage: Damage value of the block tapped.

attackHook(attacker, victim);
blockEventHook(x, y, z, type, data);
chatReceiveHook(str, sender);
deathHook(attacker, victim);
destroyBlock(x, y, z, side);
entityAddedHook(entity);
entityRemovedHook(entity);
leaveGame();
levelEventHook(player, eventType, x, y, z, data);
modTick();
newLevel(hasLevel);
procCmd(cmd);
selectLevelHook();
serverMessageReceiveHook(str);
startDestroyBlock(x, y, z, side);
useItem(x, y, z, itemId, blockId, side, itemDamage, blockDamage);

Clone this wiki locally