Members
-
ArmorType
-
Armor types.
Example
// prints 1 print(ArmorType.chestplate); -
BlockFace
-
Integer representation of each face of a game block.
Example
// prints 1 print(BlockFace.UP); -
ChatColor
-
Chat colors for
clientMessage();.Properties:
Name Type Description AQUAstring §b
BEGINstring §
BLACKstring §0
BLUEstring §9
BOLDstring §l
DARK_AQUAstring §3
DARK_BLUEstring §1
DARK_GRAYstring §8
DARK_GREENstring §2
DARK_PURPLEstring §5
DARK_REDstring §4
GOLDstring §6
GRAYstring §7
GREENstring §a
LIGHT_PURPLEstring §d
REDstring §c
RESETstring §r
WHITEstring §f
YELLOWstring §e
Example
// you better RUN! clientMessage(ChatColor.RED + "There's a Magma Cube behind you!" + ChatColor.RESET); -
DimensionId
-
Dimension IDs.
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 allTypesArray.<int> [ 2, . . . 45 ]
arrowint 32
batint 10
blazeint 18
boatint 35
chickenint 5
cowint 6
creeperint 22
eggint 30
endermanint 24
expPotionint 45
experienceOrbint 40
fallingTileint 33
fireballint 37
fishHookint 26
ghastint 17
humanint 3
ironGolemint 42
itemint 4
lavaSlimeint 16
lightningBoltint 41
minecartint 34
mushroomCowint 7
ocelotint 43
pigint 8
playerint 27
player2int 28
sheepint 9
silverfishint 21
skeletonint 19
slimeint 23
smallFireballint 38
snowGolemint 44
snowballint 29
spiderint 20
squidint 36
thrownPotionint 31
tntint 2
unknown1int 25
villagerint 12
villagerZombieint 39
wolfint 11
zombieint 14
zombiePigmanint 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"); } } -
EntityType
-
Entity type variants.
Properties:
Name Type Description ARROWint 80
BATint 19
BLAZEint 43
BOATint 90
CAVE_SPIDERint 40
CHICKENint 10
COWint 11
CREEPERint 33
EGGint 82
ENDERMANint 38
EXPERIENCE_ORBint 69
EXPERIENCE_POTIONint 68
FALLING_BLOCKint 66
FIREBALLint 85
FISHING_HOOKint 77
GHASTint 41
IRON_GOLEMint 20
ITEMint 64
LAVA_SLIMEint 42
LIGHTNING_BOLTint 93
MINECARTint 84
MUSHROOM_COWint 16
OCELOTint 22
PAINTINGint 83
PIGint 12
PIG_ZOMBIEint 36
PLAYERint 63
PRIMED_TNTint 65
RABBITint 18
SHEEPint 13
SILVERFISHint 39
SKELETONint 34
SLIMEint 37
SMALL_FIREBALLint 94
SNOWBALLint 81
SNOW_GOLEMint 21
SPIDERint 35
SQUIDint 17
THROWN_POTIONint 86
VILLAGERint 15
WOLFint 14
ZOMBIEint 32
ZOMBIE_VILLAGERint 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"); -
ItemCategory
-
Item category variants.
Properties:
Example
// prints 4 print(ItemCategory.FOOD); -
MobEffect
-
Effects (think potions) that can be applied to mobs.
Properties:
Name Type Description absorptionint 22
blindnessint 15
confusionint 9
damageBoostint 5
damageResistanceint 11
digSlowdownint 4
digSpeedint 3
effectIdsHashMap.<int, string> all type IDs; NOT in numerical order (i.e., `{8=jump, ..., 20=wither} )
fireResistanceint 12
harmint 7
healint 6
healthBoostint 21
hungerint 17
invisibilityint 14
jumpint 8
movementSlowdownint 2
movementSpeedint 1
nightVisionint 16
poisonint 19
regenerationint 10
saturationint 23
waterBreathingint 13
weaknessint 18
witherint 20
-
ParticleType
-
Particle types.
See: Level.addParticle
Properties:
Name Type Description angryVillagerint 30
bubbleint 1
cloudint 4
critint 2
dripLavaint 22
dripWaterint 21
enchantmenttableint 32
fallingDustint 23
flameint 6
happyVillagerint 31
heartint 15
hugeexplosionint 13
hugeexplosionSeedint 12
inkint 27
itemBreakint 10
largeexplodeint 5
lavaint 7
mobFlameint 14
portalint 18
rainSplashint 29
redstoneint 9
slimeint 28
smokeint 3
smoke2int 8
snowballpoofint 11
spellint 24
spell2int 25
spell3int 26
splashint 19
suspendedTownint 17
terrainint 16
waterWakeint 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
quantityof a specified item or blockidto the player's inventory.Name Type Description idint the item or block ID
quantityint how much to add
damageint the damage value of the item
- use Player.addItemInventory instead
Example
// sticks anyone? addItemInventory(280, 64, 0); -
bl_setMobSkin(
entityId, skin) -
Set the
skinimage for a valid MCPEentityId.Name Type Description entityIdint the entity ID (see: EntityType)
skinstring the skin image path (usually an image found in the
../assets/imagesfolder of the MCPE apk)- use Entity.setMobSkin instead
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
entityIdat the specifiedx,y, andzcoordinates using the specifiedskinimage.Name Type Description xdouble the x coordinate
ydouble the y coordinate
zdouble the z coordinate
entityIdint the entity ID (see: EntityType)
skinstring the skin image path (usually an image found in the
../assets/imagesfolder of the MCPE apk)Returns:
Type Description long - the native entity ID of the spawned mob
- use Level.spawnMob instead
Example
// spawn a skeleton bl_spawnMob(152, 48, 73, EntityType.SKELETON, "mob/skeleton.png"); -
clientMessage(
message) -
Display a
messagein the chat buffer.Name Type Description messagestring 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
radiuswith the center located at the specifiedx,yandzcoordinates.Name Type Description xdouble the x coordinate
ydouble the y coordinate
zdouble the z coordinate
radiusdouble the radius
hasFireboolean if true the explosion produces fire, false otherwise
- use Level.explode instead
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*
- use Level.getAddress instead
- figure out what this does
-
getPitch(
entity){double} -
Return the up/down head rotation of the given
entity(range: -90 to 90).Name Type Default Description entitylong Player optional the entity to query
Returns:
Type Description double - the pitch value
- use Entity.getPitch instead
- getYaw for a more detailed example
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
- use Player.getEntity instead
- getYaw for a more detailed example
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
- use Player.getX instead
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
- use Player.getY instead
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
- use Player.getZ instead
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, andzcoordinatesName Type Description xint the x coordinate
yint the y coordinate
zint the z coordinate
Returns:
Type Description int - the block id
- use Level.getTile instead
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 entitylong Player optional the entity to query
Returns:
Type Description double - the yaw value
- use Entity.getYaw instead
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
textas a pop-up toast message.Name Type Description textstring the message to be displayed
Example
// onoz!! print("The creepers are coming!"); -
rideAnimal(
rider, target) -
Make the specified
riderentity ride thetargetentity.Name Type Description riderlong the rider
targetlong the target
- use Entity.rideAnimal instead
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 isNightboolean night if true, day if false
- use Level.setNightMode instead
Example
// afraid of the dark? if (Level.getTime() >= 18000) { setNightMode(false); } -
setPosition(
entity, x, y, z) -
Set the location of the specified
entityto the specifiedx,y,zcoordinates; If attackHook is not used, Player.getEntity() can be used as the entity parameterName Type Description entitylong the entity to be teleported
xdouble the x coordinate
ydouble the y coordinate
zdouble the z coordinate
- use Entity.setPosition instead
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
entityrelative to the currentx,y,zcoordinates. If attackHook is not used, Player.getEntity() should be used as the entity parameterName Type Description entitylong the entity to be teleported
xdouble the x coordinate
ydouble the y coordinate
zdouble the z coordinate
- use Entity.setPositionRelative instead
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 specifiedyawandpitch. If attackHook is not used, Player.getEntity() should be used as the entity parameter.Name Type Description entitylong the target entity that will have its head rotation modified
yawdouble the desired
yawof the entitypitchdouble the desired
pitchof the entity- use Entity.setRot instead
- getYaw for a more detailed example
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
idanddamagevalue at the specifiedx,y,zcoordinatesName Type Default Description xint the x coordinate for the tile
yint the y coordinate for the tile
zint the z coordinate for the tile
idint the tile id
damageint 0 optional the tile's damage value
- use Level.setTile instead
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'svelocityalong the X axis.Name Type Description entitylong the target entity
velocitydouble the desired velocity
- use Entity.setVelX instead
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'svelocityalong the Y axis.Name Type Description entitylong the target entity
velocitydouble the desired velocity
- use Entity.setVelY instead
- Example at setVelX
-
setVelZ(
entity, velocity) -
Set the specified
entity'svelocityalong the Z axis.Name Type Description entitylong the target entity
velocitydouble the desired velocity
- use Entity.setVelZ instead
- Example at setVelX
-
spawnChicken(
x, y, z, skin){long} -
Spawn a chicken entity at the specified
x,y, andzcoordinates using the specifiedskinimage.Name Type Description xint the x coordinate
yint the y coordinate
zint the z coordinate
skinstring the skin image path (usually an image found in the
../assets/imagesfolder of the MCPE apk)Returns:
Type Description long - the native entity ID of the spawned mob
- use Level.spawnChicken instead
- Entity.spawnMob, Level.spawnMob, bl_spawnMob
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, andzcoordinates using the specifiedskinimage.Name Type Description xint the x coordinate
yint the y coordinate
zint the z coordinate
skinstring the skin image path (usually an image found in the
../assets/imagesfolder of the MCPE apk)Returns:
Type Description long - the native entity ID of the spawned mob
- use Level.spawnCow instead
- Entity.spawnMob, Level.spawnMob, bl_spawnMob
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, andzcoordinates using the specifiedskinimage. TheheldItemIdparameter determines what the zombie pigman will be hold when spawned.Name Type Description xint the x coordinate
yint the y coordinate
zint the z coordinate
heldItemIdint the id for the held item
skinstring the skin image path (usually an image found in the
../assets/imagesfolder 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
-
booleanboolean
-
JavaScriptA logical entity with two values: true, and false. -
bytenumber
-
JavaAn 8-bit integer value -
charstring
-
JavaA single 16-bit Unicode character -
Classjava.lang.Class.<Scriptable>
-
RhinoJavaScript object created by the Rhino Javascript engine. -
doublenumber
-
JavaA double-precision 64-bit floating point -
floatnumber
-
JavaA single precision 32-bit floating point -
HashMapjava.util.HashMap.<K, V>
-
JavaA hash table based implementation of the Map interface. Data is stored as key-value pairs. -
JavaA 32-bit integer value -
longnumber
-
JavaA 64-bit integer value -
NativeApiScriptableObject
-
RhinoJavaScript objects that allow access to the MCPE library via BlockLauncher and the Rhino JavaScript engine.Properties:
Name Type Description NativeBlockApiClass public static class for the Block API
NativeEntityApiClass public static class for the Entity API
NativeItemApiClass public static class for the Item API
NativeLevelApiClass public static class for the Level API
NativeModPEApiClass public static class for the ModPE API
NativePlayerApiClass public static class for the Player API
NativeRendererApiClass public static class for the Renderer API
NativeServerApiClass public static class for the Server API
-
numbernumber
-
JavaScriptAccording 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
-
RhinoJava interface that all objects in JavaScript must implement. -
ScriptableObjectorg.mozilla.javascript.ScriptableObject
-
RhinoThis is the default implementation of the Scriptable interface in Rhino. -
shortnumber
-
JavaA 16-bit integer value -
stringstring
-
JavaA string of characters