Static methods for the Entity API
Methods
-
staticEntity.addEffect(
entity, effectId, duration, amplification, ambient, showParticles
) -
Add a potion effect with the specified
effectId
to the specifiedentity
.Name Type Description entity
Object the entity to add the effect to
effectId
int the MobEffect to add
duration
int the duration of the effect in ticks (1 second = 20 ticks)
amplification
int the amplification level of the effect
ambient
boolean ???
showParticles
boolean show particle effects if true, otherwise false
- MobEffect
- get more info on `amplification`
- figure out what `ambient` is
Example
// give that poisonous look var entity = Player.getPointedEntity(), var effect = MobEffect.poison; // to calculate duration, multiply the number of seconds by 20 // (e.g., 30 seconds * 20 ticks/second = 600 ticks) var duration = 600; Entity.addEffect(entity, effect, duration, 0, false, true);
-
staticEntity.getAll(
){Array.<long>}
-
Return a list of all entity objects in the current world.
Returns:
Type Description Array.<long> - all entity objects currently in the game
Example
// triggered via a custom command (/removeall) function procCmd(cmd) { if (cmd === "removeall") { var entitiesList = Entity.getAll(); for (var i = 0; i < entitiesList.length; i++) { //skip players, otherwise Minecraft glitches if (Player.isPlayer(entitiesList[i])) { continue; } Entity.remove(entitiesList[i]); } } else { return; } }
-
staticEntity.getAnimalAge(
entity
){int} -
Return the age of a mob. Only works for animals and zombies/skeletons/pigmen.
Name Type Description entity
long the native entity id of the animal
Returns:
Type Description int - the animal's age
Example
// code here
-
staticEntity.getArmor(
entity, armorSlot
){int} -
Returns the Item ID of the armor in the given ArmorType slot.
Name Type Description entity
long the native entity id of the player/mob to check
armorSlot
int the ArmorType to check
Returns:
Type Description int - the Item ID of the armor in the given slot
Example
// what's that mob wearing? var ent = Player.getPointedEntity(); var eid = Entity.getEntityTypeId(ent); if (eid >= 10 && eid <= 90) { for (var e in EntityType) { if (EntityType[e] === eid) { var armor = []; var msg = ""; // check each armor slot for (var t in ArmorType) { var slot = Item.getName(Entity.getArmor(ent, t)) || ""; if (slot !== "") { armor.push(slot); } if (armor[0]) { msg = "The mob is wearing: " + armor.toString(); } } clientMessage(msg); } } }
-
staticEntity.getArmorDamage(
)
-
desc
Example
// code here
-
staticEntity.getEntityTypeId(
)
-
desc
Example
// code here
-
staticEntity.getHealth(
)
-
desc
Example
// code here
-
staticEntity.getItemEntityCount(
)
-
desc
Example
// code here
-
staticEntity.getItemEntityData(
)
-
desc
Example
// code here
-
staticEntity.getItemEntityId(
)
-
desc
Example
// code here
-
staticEntity.getMaxHealth(
)
-
desc
Example
// code here
-
staticEntity.getMobSkin(
)
-
desc
Example
// code here
-
staticEntity.getNameTag(
)
-
desc
Example
// code here
-
staticEntity.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 native entity id to query
Returns:
Type Description double - the pitch value
- Entity.getYaw for a more detailed example
Example
// no shoe gazing var pitch = Entity.getPitch(); if (pitch < -30) { clientMessage("Keep your head up!!"); }
-
staticEntity.getRenderType(
)
-
desc
Example
// code here
-
staticEntity.getRider(
)
-
desc
Example
// code here
-
staticEntity.getRiding(
)
-
desc
Example
// code here
-
staticEntity.getUniqueId(
)
-
desc
Example
// code here
-
staticEntity.getVelX(
)
-
desc
Example
// code here
-
staticEntity.getVelY(
)
-
desc
Example
// code here
-
staticEntity.getVelZ(
)
-
desc
Example
// code here
-
staticEntity.getX(
)
-
desc
Example
// code here
-
staticEntity.getY(
)
-
desc
Example
// code here
-
staticEntity.getYaw(
entity
){double} -
return the left/right head rotation of the given
entity
(range: -∞ to ∞)Name Type Default Description entity
long Player optional the native entity id to query
Returns:
Type Description double - the yaw value
Example
// determine player's cardinal or intermediate direction function getDirection() { var player = Player.getEntity(); var yaw = Entity.getYaw(player); var pitch = Entity.getPitch(player); var direction; // adjust rotation for yaw < 0 || yaw >= 360 if (yaw < 0) { Entity.setRot(player, yaw + 360, pitch); } else if (yaw >= 360) { Entity.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());
-
staticEntity.getZ(
)
-
desc
Example
// code here
-
staticEntity.isSneaking(
)
-
desc
Example
// code here
-
staticEntity.remove(
)
-
desc
Example
// code here
-
staticEntity.removeAllEffects(
)
-
desc
Example
// code here
-
staticEntity.removeEffect(
)
-
desc
Example
// code here
-
staticEntity.rideAnimal(
)
-
desc
Example
// code here
-
staticEntity.setAnimalAge(
)
-
desc
Example
// code here
-
staticEntity.setArmor(
)
-
desc
Example
// code here
-
staticEntity.setCape(
)
-
desc
Example
// code here
-
staticEntity.setCarriedItem(
)
-
desc
Example
// code here
-
staticEntity.setCollisionSize(
)
-
desc
Example
// code here
-
staticEntity.setFireTicks(
)
-
desc
Example
// code here
-
staticEntity.setHealth(
)
-
desc
Example
// code here
-
staticEntity.setMaxHealth(
)
-
desc
Example
// code here
-
staticEntity.setMobSkin(
id, skin
) -
Set the
skin
image for a valid MCPE entityid
.Name Type Description id
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 Entity.setMobSkin(Player.getEntity(), "mob/creeper.png");
-
staticEntity.setNameTag(
)
-
desc
Example
// code here
-
staticEntity.setPosition(
)
-
desc
Example
// code here
-
staticEntity.setPositionRelative(
)
-
desc
Example
// code here
-
staticEntity.setRenderType(
)
-
desc
Example
// code here
-
staticEntity.setRot(
entity, yaw, pitch
) -
Set the rotation of the specified
entity
's head to the specifiedyaw
andpitch
. 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 entitypitch
double the desired
pitch
of the entity- getYaw for a more detailed example
Example
// the exorcist var y = 0; while (y <= 360) { setRot(Player.getEntity(), y, 0); y++; }
-
staticEntity.setSneaking(
)
-
desc
Example
// code here
-
staticEntity.setVelX(
entity, velocity
) -
Set the specified
entity
'svelocity
along the X axis.Name Type Description entity
long the target entity
velocity
double the desired velocity
Example
// jetpack fun time var playerDir = [0, 0, 0]; var DEG_TO_RAD = Math.PI / 180; var playerFlySpeed = 1; function modTick() { if (Player.getCarriedItem() == 280) { jetpackTick(); } } function jetpackTick() { toDirectionalVector(playerDir, (Player.getYaw() + 90) * DEG_TO_RAD, Player.getPitch() * DEG_TO_RAD * -1); var player = Player.getEntity(); Entity.setVelX(player, playerFlySpeed * playerDir[0]); Entity.setVelY(player, playerFlySpeed * playerDir[1]); Entity.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); }
-
staticEntity.setVelY(
entity, velocity
) -
Set the specified
entity
'svelocity
along the Y axis.Name Type Description entity
long the target entity
velocity
double the desired velocity
- See example at Entity.setVelX
-
staticEntity.setVelZ(
entity, velocity
) -
Set the specified
entity
'svelocity
along the Z axis.Name Type Description entity
long the target entity
velocity
double the desired velocity
- See example at Entity.setVelX
-
staticEntity.spawnMob(
x, y, z, id, skin
) -
Spawn a valid MCPE entity with the specified
id
at the givenx
,y
, andz
coordinates using the specifiedskin
image.Name Type Description x
double the x coordinate
y
double the y coordinate
z
double the z coordinate
id
int the entity ID (see: EntityType)
skin
string the skin image path (an image found in the
../assets/images
folder of the MCPE apk)Example
// spawn a skeleton Entity.spawnMob(152, 48, 73, EntityType.SKELETON, "mob/skeleton.png");