Global

Global

Members

Armor types.

Properties:
Name Type Description
boots int

3

chestplate int

1

helmet int

0

leggings int

2

Example
// prints 1
print(ArmorType.chestplate);

Integer representation of each face of a game block.

Properties:
Name Type Description
DOWN int

0

EAST int

5

NORTH int

2

SOUTH int

3

UP int

1

WEST int

4

Example
// prints 1
print(BlockFace.UP);

Chat colors for clientMessage();.

Properties:
Name Type Description
AQUA string

§b

BEGIN string

§

BLACK string

§0

BLUE string

§9

BOLD string

§l

DARK_AQUA string

§3

DARK_BLUE string

§1

DARK_GRAY string

§8

DARK_GREEN string

§2

DARK_PURPLE string

§5

DARK_RED string

§4

GOLD string

§6

GRAY string

§7

GREEN string

§a

LIGHT_PURPLE string

§d

RED string

§c

RESET string

§r

WHITE string

§f

YELLOW string

§e

Example
// you better RUN!
clientMessage(ChatColor.RED + "There's a Magma Cube behind you!" + ChatColor.RESET);

Dimension IDs.

Properties:
Name Type Description
NETHER int

1

NORMAL int

0

Example
// prints 1
print(DimensionId.NETHER);

EntityRenderType

Determines the shape of creature to render, not the skin. To change the skin see Entity.setMobSkin.

Properties:
Name Type Description
allTypes Array.<int>

[ 2, . . . 45 ]

arrow int

32

bat int

10

blaze int

18

boat int

35

chicken int

5

cow int

6

creeper int

22

egg int

30

enderman int

24

expPotion int

45

experienceOrb int

40

fallingTile int

33

fireball int

37

fishHook int

26

ghast int

17

human int

3

ironGolem int

42

item int

4

lavaSlime int

16

lightningBolt int

41

minecart int

34

mushroomCow int

7

ocelot int

43

pig int

8

player int

27

player2 int

28

sheep int

9

silverfish int

21

skeleton int

19

slime int

23

smallFireball int

38

snowGolem int

44

snowball int

29

spider int

20

squid int

36

thrownPotion int

31

tnt int

2

unknown1 int

25

villager int

12

villagerZombie int

39

wolf int

11

zombie int

14

zombiePigman int

15

Example
// make all pigs look like cows
function entityAddedHook(entity) {
  if (Entity.getEntityTypeId(entity) === EntityType.PIG) {
    Entity.setRenderType(entity, EntityRenderType.cow);
    // don't forget the skin!
    Entity.setMobSkin(entity, "mob/cow.png");
  }
}

Entity type variants.

Properties:
Name Type Description
ARROW int

80

BAT int

19

BLAZE int

43

BOAT int

90

CAVE_SPIDER int

40

CHICKEN int

10

COW int

11

CREEPER int

33

EGG int

82

ENDERMAN int

38

EXPERIENCE_ORB int

69

EXPERIENCE_POTION int

68

FALLING_BLOCK int

66

FIREBALL int

85

FISHING_HOOK int

77

GHAST int

41

IRON_GOLEM int

20

ITEM int

64

LAVA_SLIME int

42

LIGHTNING_BOLT int

93

MINECART int

84

MUSHROOM_COW int

16

OCELOT int

22

PAINTING int

83

PIG int

12

PIG_ZOMBIE int

36

PLAYER int

63

PRIMED_TNT int

65

RABBIT int

18

SHEEP int

13

SILVERFISH int

39

SKELETON int

34

SLIME int

37

SMALL_FIREBALL int

94

SNOWBALL int

81

SNOW_GOLEM int

21

SPIDER int

35

SQUID int

17

THROWN_POTION int

86

VILLAGER int

15

WOLF int

14

ZOMBIE int

32

ZOMBIE_VILLAGER int

44

Example
// spawn a creeper on your head
var x = Player.getX();
var y = Player.getY();
var z = Player.getZ();
Level.spawnMob(x, y, z, EntityType.CREEPER, "mob/creeper.png");

Item category variants.

Properties:
Name Type Description
DECORATION int

8

FOOD int

4

INTERNAL int

-1

MATERIAL int

1

TOOL int

2

Example
// prints 4
print(ItemCategory.FOOD);

Effects (think potions) that can be applied to mobs.

Properties:
Name Type Description
absorption int

22

blindness int

15

confusion int

9

damageBoost int

5

damageResistance int

11

digSlowdown int

4

digSpeed int

3

effectIds HashMap.<int, string>

all type IDs; NOT in numerical order (i.e., `{8=jump, ..., 20=wither} )

fireResistance int

12

harm int

7

heal int

6

healthBoost int

21

hunger int

17

invisibility int

14

jump int

8

movementSlowdown int

2

movementSpeed int

1

nightVision int

16

poison int

19

regeneration int

10

saturation int

23

waterBreathing int

13

weakness int

18

wither int

20

Particle types.

See: Level.addParticle

Properties:
Name Type Description
angryVillager int

30

bubble int

1

cloud int

4

crit int

2

dripLava int

22

dripWater int

21

enchantmenttable int

32

fallingDust int

23

flame int

6

happyVillager int

31

heart int

15

hugeexplosion int

13

hugeexplosionSeed int

12

ink int

27

itemBreak int

10

largeexplode int

5

lava int

7

mobFlame int

14

portal int

18

rainSplash int

29

redstone int

9

slime int

28

smoke int

3

smoke2 int

8

snowballpoof int

11

spell int

24

spell2 int

25

spell3 int

26

splash int

19

suspendedTown int

17

terrain int

16

waterWake int

20

Example
// sprout hearts from the block you're looking at
var x = Player.getPointedBlockX();
var y = Player.getPointedBlockY();
var z = Player.getPointedBlockZ();
Level.addParticle(ParticleType.heart, x, y, z, 0, 0, 0, 1);

Methods

addItemInventory(id, quantity, damage)

Add a specified quantity of a specified item or block id to the player's inventory.

Name Type Description
id int

the item or block ID

quantity int

how much to add

damage int

the damage value of the item

Example
// sticks anyone?
addItemInventory(280, 64, 0);

bl_setMobSkin(entityId, skin)

Set the skin image for a valid MCPE entityId.

Name Type Description
entityId int

the entity ID (see: EntityType)

skin string

the skin image path (usually an image found in the ../assets/images folder of the MCPE apk)

Example
// make yourself look like a creeper
bl_setMobSkin(Player.getEntity(), "mob/creeper.png");

bl_spawnMob(x, y, z, entityId, skin){long}

Spawn a mob with a valid MCPE entityId at the specified x, y, and z coordinates using the specified skin image.

Name Type Description
x double

the x coordinate

y double

the y coordinate

z double

the z coordinate

entityId int

the entity ID (see: EntityType)

skin string

the skin image path (usually an image found in the ../assets/images folder of the MCPE apk)

Returns:
Type Description
long
  • the native entity ID of the spawned mob
Example
// spawn a skeleton
bl_spawnMob(152, 48, 73, EntityType.SKELETON, "mob/skeleton.png");

clientMessage(message)

Display a message in the chat buffer.

Name Type Description
message string

the message to display

Example
// you've been warned
clientMessage("Don't poke the Zombie Pigmen!!")

explode(x, y, z, radius, hasFire)

Cause an explosion of the specified radius with the center located at the specified x, y and z coordinates.

Name Type Description
x double

the x coordinate

y double

the y coordinate

z double

the z coordinate

radius double

the radius

hasFire boolean

if true the explosion produces fire, false otherwise

Example
// underground nuclear warhead testing
explode(127, 8, 45, 256, false);

getCarriedItem(){int}

Return the id of the item or block the player is currently holding.

Returns:
Type Description
int
  • the item or block ID
Example
// where did I put that ... ?
print("You are carrying a " + getCarriedItem() + "!");

getLevel(){Object}

THIS THROWS AN ERROR ON ANDROID; IS IT iOS ONLY???_

Returns:
Type Description
Object
  • unknown *

getPitch(entity){double}

Return the up/down head rotation of the given entity (range: -90 to 90).

Name Type Default Description
entity long Player optional

the entity to query

Returns:
Type Description
double
  • the pitch value
Example
// no shoe gazing
var pitch = getPitch(Player.getEntity()); // <-- redundant since Player is default
if (pitch < -30) {
  clientMessage("Keep your head up!!");
}

getPlayerEnt(){long}

Return the player's native entity id (NOT the same as EntityType).

Returns:
Type Description
long
  • the player's native entity id
Example
// suicide is painless...
Entity.setHealth(getPlayerEnt(), 0);

getPlayerX(){double}

Return the player's current x coordinate.

Returns:
Type Description
double
  • the player's x coordinate
Example
// where in the X am I?
var x = Math.round(getPlayerX());
ModPE.showTipMessage("Your X coordinate is: " + x);

getPlayerY(){double}

Return the player's current y coordinate.

Returns:
Type Description
double
  • the player's y coordinate
Example
// where in the Y am I?
var y = Math.round(getPlayerY());
ModPE.showTipMessage("Your Y coordinate is: " + y);

getPlayerZ(){double}

Return the player's current z coordinate.

Returns:
Type Description
double
  • the player's z coordinate
Example
// where in the Z am I?
var z = Math.round(getPlayerZ());
ModPE.showTipMessage("Your Z coordinate is: " + z);

getTile(x, y, z){int}

return the id of the block located at the specified x, y, and z coordinates

Name Type Description
x int

the x coordinate

y int

the y coordinate

z int

the z coordinate

Returns:
Type Description
int
  • the block id
Example
// what did I just step in?
function modTick() {
  var x = Math.floor(Player.getX());
  var y = Math.floor(Player.getY() - 1.6); // -1.6 = y @ feet, not head
  var z = Math.floor(Player.getZ());
  var tileId = getTile(x, y, z);
  if (tileId > 0 && tileId < 256) {
    var poo = Item.getName(tileId, 0, false);
    ModPE.showTipMessage("You just stepped in poo! (or " + poo + ")");
  }
}

getYaw(entity){double}

Return the left/right head rotation of the given entity (range: -∞ to ∞).

Name Type Default Description
entity long Player optional

the entity to query

Returns:
Type Description
double
  • the yaw value
Example

Adapted from: Anti's DebugPE mod

// determine player's cardinal or intermediate direction
function getDirection() {
  var player = getPlayerEnt();
  var yaw = getYaw(player);
  var pitch = getPitch(player);
  var direction;

  // adjust rotation for yaw < 0 || yaw >= 360
  if (yaw < 0) {
    setRot(player, yaw + 360, pitch);
  } else if (yaw >= 360) {
    setRot(player, yaw - 360, pitch);
  }

  // determine direction with fuzzy ranges
  if ((yaw >= 337.5 && yaw < 360) || (yaw >= 0 && yaw < 22.5)) {
    direction = "West";
  } else if (yaw >= 22.5 && yaw < 67.5) {
    direction = "North West";
  } else if (yaw >= 67.5 && yaw < 112.5) {
    direction = "North";
  } else if (yaw >= 112.5 && yaw < 157.5) {
    direction = "North East";
  } else if (yaw >= 157.5 && yaw < 202.5) {
    direction = "East";
  } else if (yaw >= 202.5 && yaw < 247.5) {
    direction = "South East";
  } else if (yaw >= 247.5 && yaw < 292.5) {
    direction = "South";
  } else if (yaw >= 292.5 && yaw < 337.5) {
    direction = "South West";
  }
  return direction;
}

// if you die watching the sun set, this should print "West" :-)
clientMessage(getDirection());

preventDefault()

Prevent the default action from taking place.

  • get more information about how this works and precisely what it does
  • better example or add explanatory details
Example

credit: Zhuowei Zhang

// ???
function useItem(x, y, z, itemId, blockId) {
  if (itemId === 354) { // cake
    teleportToFloor(UPWARD);
    preventDefault();
  } else if (itemId === 344) { // egg
    teleportToFloor(DOWNWARD);
    preventDefault();
  }
}

print(text)

Display the given text as a pop-up toast message.

Name Type Description
text string

the message to be displayed

Example
// onoz!!
print("The creepers are coming!");

rideAnimal(rider, target)

Make the specified rider entity ride the target entity.

Name Type Description
rider long

the rider

target long

the target

Example

credit: Zhuowei Zhang

// weeeee!
var cart = -1;
var playerX;
var playerZ;
var stairBlocks = [53, 67, 108, 109, 114, 128, 134, 135, 136, 156];
function useItem(x, y, z, itemid, blockId, side) {
  if (stairBlocks.indexOf(blockId) >= 0) {
    //spawn a minecart
    cart = Level.spawnMob(x + 0.5, y + 1, z + 0.5, 84, "mob/char.png");
    //make it invisible
    Entity.setRenderType(cart, 0);
    rideAnimal(getPlayerEnt(), cart);
    preventDefault();
    //store the chair's location: that way, when the player gets off, we can remove the cart
    playerX = x + 0.5;
    playerZ = z + 0.5;
  }
}
function modTick() {
  if (cart === -1) return;
  if (Math.abs(getPlayerX() - playerX) > 1 || Math.abs(getPlayerZ() - playerZ) > 1) {
    Entity.remove(cart);
    cart = -1;
  }
}

setNightMode(isNight)

Set whether it is night or day.

Name Type Description
isNight boolean

night if true, day if false

Example
// afraid of the dark?
if (Level.getTime() >= 18000) {
  setNightMode(false);
}

setPosition(entity, x, y, z)

Set the location of the specified entity to the specified x, y, z coordinates; If attackHook is not used, Player.getEntity() can be used as the entity parameter

Name Type Description
entity long

the entity to be teleported

x double

the x coordinate

y double

the y coordinate

z double

the z coordinate

Example

credit: Zhuowei Zhang

// teleporting? check for flies!!
var UPWARD = 1;
var DOWNWARD = -1;
function useItem(x, y, z, itemId, blockId) {
  if (itemId === 354) { // cake
    teleportToFloor(UPWARD);
    preventDefault();
  } else if (itemId === 344) { // egg
    teleportToFloor(DOWNWARD);
    preventDefault();
  }
}
function teleportToFloor(direction) {
  var currentX = Math.floor(getPlayerX());
  var currentZ = Math.floor(getPlayerZ());
  //get player's feet, so subtract 1.6 (player's height)
  var currentY = Math.floor(getPlayerY() - 1.6);
  var beginY = currentY + (direction * 2);
  for (var i = beginY; i < 128 && i >= 0; i += direction) {
    if (getTile(currentX, i, currentZ) !== 0
        && getTile(currentX, i + 1, currentZ) === 0
        && getTile(currentX, i + 2, currentZ) === 0) {
      var deltaY = (i - currentY);
      setPosition(getPlayerEnt(), currentX, getPlayerY() + deltaY + 1, currentZ);
      break;
    }
  }
}

setPositionRelative(entity, x, y, z)

Set the location of the specified entity relative to the current x, y, z coordinates. If attackHook is not used, Player.getEntity() should be used as the entity parameter

Name Type Description
entity long

the entity to be teleported

x double

the x coordinate

y double

the y coordinate

z double

the z coordinate

Example

credit: Zhuowei Zhang

// build vehicles out of blocks, fly them by tapping with an iron hoe
function modTick() {
  if (vehicleLoc === null || --vehicleSpeed > 0) return;
  vehicleSpeed = 5;
  for (var x = 0; x < vehicleMaxSize; ++x) {
    for (var y = 0; y < vehicleMaxSize; ++y) {
      for (var z = 0; z < vehicleMaxSize; ++z) {
        if (vehicleBlocks[x][y][z] != 0) {
          setTile(vehicleLoc[0] + x, vehicleLoc[1] + y, vehicleLoc[2] + z, 0);
        }
      }
    }
  }
  vehicleLoc[0] += vehicleVel[0];
  vehicleLoc[1] += vehicleVel[1];
  vehicleLoc[2] += vehicleVel[2];
  for (var x = 0; x < vehicleMaxSize; x++) {
    for (var y = 0; y < vehicleMaxSize; y++) {
      for (var z = 0; z < vehicleMaxSize; z++) {
        if (vehicleBlocks[x][y][z] != 0) {
          setTile(vehicleLoc[0] + x, vehicleLoc[1] + y, vehicleLoc[2] + z, vehicleBlocks[x][y][z]);
        }
      }
    }
  }
  setPositionRelative(getPlayerEnt(), vehicleVel[0], vehicleVel[1], vehicleVel[2]);
}

setRot(entity, yaw, pitch)

Set the rotation of the specified entity's head to the specified yaw and pitch. If attackHook is not used, Player.getEntity() should be used as the entity parameter.

Name Type Description
entity long

the target entity that will have its head rotation modified

yaw double

the desired yaw of the entity

pitch double

the desired pitch of the entity

Example
// the exorcist
var y = 0;
while (y <= 360) {
  setRot(Player.getEntity(), y, 0);
  y++;
}

setTile(x, y, z, id, damage)

Place a tile with the specified id and damage value at the specified x, y, z coordinates

Name Type Default Description
x int

the x coordinate for the tile

y int

the y coordinate for the tile

z int

the z coordinate for the tile

id int

the tile id

damage int 0 optional

the tile's damage value

Example

credit: 'Chad' via Zhuowei Zhang

// instantly grow a tree when the ground is tapped with an oak sapling.
function useItem(x,y,z,itemId,blockId,side) {
  if(itemId === 6) {

    // creates the trunk of the tree
    setTile(x,y,z,17);
    setTile(x,y+1,z,17);
    setTile(x,y+2,z,17);
    setTile(x,y+3,z,17);
    setTile(x,y+4,z,17);
    setTile(x,y+5,z,17);

    // creates the leaves of the tree
    setTile(x,y+6,z,18);
    setTile(x,y+7,z,18);
    setTile(x+1,y+6,z,18);
    setTile(x-1,y+6,z,18);
    setTile(x,y+6,z+1,18);
    setTile(x,y+6,z-1,18);
    setTile(x+1,y+5,z,18);
    setTile(x-1,y+5,z,18);
    setTile(x,y+5,z+1,18);
    setTile(x,y+5,z-1,18);
    setTile(x+1,y+4,z,18);
    setTile(x-1,y+4,z,18);
    setTile(x,y+4,z+1,18);
    setTile(x,y+4,z-1,18);
    setTile(x+1,y+5,z+1,18);
    setTile(x-1,y+5,z-1,18);
    setTile(x-1,y+5,z+1,18);
    setTile(x+1,y+5,z-1,18);
    setTile(x+2,y+5,z,18);
    setTile(x-2,y+5,z,18);
    setTile(x,y+5,z+2,18);
    setTile(x,y+5,z-2,18);
  }
}

setVelX(entity, velocity)

Set the specified entity's velocity along the X axis.

Name Type Description
entity long

the target entity

velocity double

the desired velocity

Example

credit: Zhuowei Zhang

// jetpack
var playerDir = [0, 0, 0];
var DEG_TO_RAD = Math.PI / 180;
var playerFlySpeed = 1;

function modTick() {
  if (getCarriedItem() == 280) {
    jetpackTick();
  }
}
function jetpackTick() {
  toDirectionalVector(playerDir, (getYaw() + 90) * DEG_TO_RAD, getPitch() * DEG_TO_RAD * -1);
  var player = getPlayerEnt();
  setVelX(player, playerFlySpeed * playerDir[0]);
  setVelY(player, playerFlySpeed * playerDir[1]);
  setVelZ(player, playerFlySpeed * playerDir[2]);
}
function toDirectionalVector(vector, yaw, pitch) {
  // see: http://stackoverflow.com/questions/1568568/how-to-convert-euler-angles-to-directional-vector
  vector[0] = Math.cos(yaw) * Math.cos(pitch);
  vector[1] = Math.sin(pitch);
  vector[2] = Math.sin(yaw) * Math.cos(pitch);
}

setVelY(entity, velocity)

Set the specified entity's velocity along the Y axis.

Name Type Description
entity long

the target entity

velocity double

the desired velocity

setVelZ(entity, velocity)

Set the specified entity's velocity along the Z axis.

Name Type Description
entity long

the target entity

velocity double

the desired velocity

spawnChicken(x, y, z, skin){long}

Spawn a chicken entity at the specified x, y, and z coordinates using the specified skin image.

Name Type Description
x int

the x coordinate

y int

the y coordinate

z int

the z coordinate

skin string

the skin image path (usually an image found in the ../assets/images folder of the MCPE apk)

Returns:
Type Description
long
  • the native entity ID of the spawned mob
Example

credit: 'Treebl' via Zhuowei Zhang

// yay! chickens
var tb = false;

function useItem(x, y, z, itemId, blockId, side) {
  if (itemId == 280 && !tb) { // if the item is a stick and items hasn't been initialized
    ModPE.setItem(392, "stick", 0, "Wand");
    ModPE.setFoodItem(393, "cookie", 0, 5, "Cookie");
    Player.addItemInventory(392, 5);
    Player.addItemInventory(393, 1);
    tb = true;
  } else if (itemId == 280) { // else: if the item is a stick
    Player.addItemInventory(392, 5);
    Player.addItemInventory(393, 1);
  } else if (itemId == 392) { // else: if the item is a wand
    Level.spawnChicken(x, y + 1, z, "mob/chicken.png");
  }
}

spawnCow(x, y, z, skin){long}

Spawn a cow entity at the specified x, y, and z coordinates using the specified skin image.

Name Type Description
x int

the x coordinate

y int

the y coordinate

z int

the z coordinate

skin string

the skin image path (usually an image found in the ../assets/images folder of the MCPE apk)

Returns:
Type Description
long
  • the native entity ID of the spawned mob
Example

credit: 'Treebl' via Zhuowei Zhang

// moo!
var tb = false;

function useItem(x, y, z, itemId, blockId, side) {
  if (itemId == 280 && !tb) { // if the item is a stick and items hasn't been initialized
    ModPE.setItem(392, "stick", 0, "Wand");
    ModPE.setFoodItem(393, "cookie", 0, 5, "Cookie");
    Player.addItemInventory(392, 5);
    Player.addItemInventory(393, 1);
    tb = true;
  } else if (itemId == 280) { // else: if the item is a stick
    Player.addItemInventory(392, 5);
    Player.addItemInventory(393, 1);
  } else if (itemId == 392) { // else: if the item is a wand
    Level.spawnChicken(x, y + 1, z, "mob/cow.png");
  }
}

spawnPigZombie(x, y, z, heldItemId, skin){long}

Spawn a zombie pigman entity at the specified x, y, and z coordinates using the specified skin image. The heldItemId parameter determines what the zombie pigman will be hold when spawned.

Name Type Description
x int

the x coordinate

y int

the y coordinate

z int

the z coordinate

heldItemId int

the id for the held item

skin string

the skin image path (usually an image found in the ../assets/images folder of the MCPE apk)

Returns:
Type Description
long
  • the native entity ID of the spawned mob
Example
// cannibals!!
var x = getPlayerX() + 2;
var y = getPlayerY();
var z = getPlayerZ() + 2;
var held = 320;
var img = "mob/char.png";

spawnPigZombie(x, y, z, held, img);

Type Definitions

JavaScript A logical entity with two values: true, and false.

Java An 8-bit integer value

Java A single 16-bit Unicode character

Classjava.lang.Class.<Scriptable>

Rhino JavaScript object created by the Rhino Javascript engine.

Java A double-precision 64-bit floating point

Java A single precision 32-bit floating point

HashMapjava.util.HashMap.<K, V>

Java A hash table based implementation of the Map interface. Data is stored as key-value pairs.

Java A 32-bit integer value

Java A 64-bit integer value

Rhino JavaScript objects that allow access to the MCPE library via BlockLauncher and the Rhino JavaScript engine.

Properties:
Name Type Description
NativeBlockApi Class

public static class for the Block API

NativeEntityApi Class

public static class for the Entity API

NativeItemApi Class

public static class for the Item API

NativeLevelApi Class

public static class for the Level API

NativeModPEApi Class

public static class for the ModPE API

NativePlayerApi Class

public static class for the Player API

NativeRendererApi Class

public static class for the Renderer API

NativeServerApi Class

public static class for the Server API

JavaScript According to the ECMAScript standard, there is only one number type: the double-precision 64-bit binary format IEEE 754 value (number between -(253 -1) and 253 -1).

Scriptableorg.mozilla.javascript.Scriptable

Rhino Java interface that all objects in JavaScript must implement.

ScriptableObjectorg.mozilla.javascript.ScriptableObject

Rhino This is the default implementation of the Scriptable interface in Rhino.

Java A 16-bit integer value

Java A string of characters