Skip to content

EntityHelper ​

com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper

Wraps a Minecraft entity for script access. Factories such as World.getEntities() return the most specific supported helper subtype;
helpers wrap the underlying entity rather than copying it.
Use the global EntityHelpers types for inheritance-aware checks such as entity instanceof EntityHelpers.Horse; is(String...) instead checks entity registry IDs.

js
const nearby = World.getEntities(10);  
if (nearby !== null) {
  for (const entity of nearby) {
    Chat.log(`${entity.getType()} at ${entity.getPos()}`);  
  }
}

Available in scripts as EntityHelpers.Entity.

Type Parameters ​

  • T: the Minecraft entity wrapped by this helper

Methods ​

asAnimal ​

asAnimal(): LivingEntityHelper<?>Since1.8.4#
Casts this helper to an animal-entity helper. The entity must be an animal; being a living entity alone is not sufficient. Use instanceof EntityHelpers.Animal to test for one.
Returns: this helper as an animal-entity helper

asClientPlayer ​

asClientPlayer(): ClientPlayerEntityHelper<?>Since1.6.3#
Casts this helper to a local-player helper. This is a Java cast, not a type check; it throws ClassCastException unless this helper wraps the local player. Use instanceof EntityHelpers.ClientPlayer to test for one.
Returns: this helper as a local-player helper

asItem ​

asItem(): ItemEntityHelperSince1.6.3#
Casts this helper to an item-entity helper for a dropped item entity. Use instanceof EntityHelpers.Item to test for one.
Returns: this helper as an item-entity helper

asLiving ​

asLiving(): LivingEntityHelper<?>Since1.6.3#
Casts this helper to a living-entity helper, exposing living-entity state. Use instanceof EntityHelpers.Living to test for one.
Returns: this helper as a living-entity helper

asMerchant ​

asMerchant(): MerchantEntityHelper<?>Since1.6.3#
Casts this helper to a merchant helper. Villagers and other merchant entities, including wandering traders, can be cast; the helper exposes merchant state. Use instanceof EntityHelpers.Merchant to test for one.
Returns: this helper as a merchant helper

asPlayer ​

asPlayer(): PlayerEntityHelper<?>Since1.6.3#
Casts this helper to a player helper. This is a Java cast, not a type check; it throws ClassCastException unless this helper wraps a player. Use instanceof EntityHelpers.Player to test for one.
Returns: this helper as a player helper

asServerEntity ​

asServerEntity(): EntityHelper<?>Since1.8.4#
Looks up the same UUID in the integrated server's level corresponding to this entity's dimension. The lookup runs on the server thread; the returned helper wraps a server-side entity and must only be accessed there. Returns null if there is no integrated server, level, or matching loaded entity.
Returns: the server-side helper, or null if the lookup finds no entity

asVillager ​

asVillager(): VillagerEntityHelperSince1.6.3#
Casts this helper to a villager helper. This cast is valid only for villagers; other merchant entities, such as wandering traders, are not villagers. Use instanceof EntityHelpers.Villager to test for one.
Returns: this helper as a villager helper

create ​

static create(Entity e): EntityHelper<?>#
Wraps a Minecraft entity in the most specific supported helper subtype. Throws NullPointerException if e is null.

Parameters:

  • e: the Minecraft entity to wrap
Returns: the helper subtype matching the entity, or a plain EntityHelper if no more specific helper applies

distanceTo ​

distanceTo(EntityHelper<?> entity): floatSince1.8.4#
Returns the three-dimensional distance between the entities' positions (not their eyes).

Parameters:

  • entity: the entity to measure to
Returns: the distance in blocks.
distanceTo(BlockPosHelper pos): doubleSince1.8.4#
Returns the distance from this entity's position to the center of the block.

Parameters:

  • pos: the position to measure to
Returns: the distance in blocks.
distanceTo(Pos3D pos): doubleSince1.8.4#
Returns the three-dimensional distance from this entity's position to the given position.

Parameters:

  • pos: the position to measure to
Returns: the distance in blocks.
distanceTo(double x, double y, double z): doubleSince1.8.4#
Returns the three-dimensional distance from this entity's position to the given coordinates.

Parameters:

  • x: the x coordinate to measure to
  • y: the y coordinate to measure to
  • z: the z coordinate to measure to
Returns: the distance in blocks.

getAir ​

getAir(): intSince1.8.4#
Returns the current air supply, in ticks.
Returns: the amount of air this entity has.

getBiome ​

getBiome(): StringSince1.8.4#
Returns the registry ID of the biome at this entity's block position in the client's current world.
Returns: the biome registry ID, including its namespace.

getBlockPos ​

getBlockPos(): BlockPosHelperSince1.6.5#
Returns the block position containing the entity's position (coordinates are rounded down, not to the nearest block).
Returns: the entity's block position.

getChunk ​

getChunk(): ChunkHelperSince1.8.4#
Returns the chunk containing this entity's block position.
Returns: the chunk helper for the chunk this entity is in.

getChunkPos ​

getChunkPos(): Pos2DSince1.6.5#
Returns the entity's chunk coordinates as a Pos2D: x is chunk x and y is world chunk z.
Returns: the entity's chunk coordinates.

getEyeHeight ​

getEyeHeight(): doubleSince1.2.8#
Returns the entity's eye-height offset for its current pose. Adding it to getY() gives the eye position's y coordinate.
Returns: the current eye height offset for the entity.

getEyePos ​

getEyePos(): Pos3DSince1.8.4#
Returns the position of the entity's eyes, which depends on its current pose.
Returns: the entity's eye position.

getFacingDirection ​

getFacingDirection(): DirectionHelperSince1.8.4#
Returns the horizontal cardinal direction corresponding to the entity's yaw.
Returns: the direction the entity is facing, rounded to the nearest 90 degrees.

getGlowingColor ​

getGlowingColor(): intSince1.8.2#
Returns the entity's team colour, or 0 if it has no team colour. A colour set by setGlowingColor(int) can override the colour used for drawing without changing this value.
Returns: glow color

getMaxAir ​

getMaxAir(): intSince1.8.4#
Returns the maximum air supply, in ticks.
Returns: the maximum amount of air this entity can have.

getName ​

getName(): TextHelperSince1.0.2#
Returns the entity's displayed name as text, including its styling or custom name. Before 1.6.4, this returned a String.
Returns: the name of the entity.

getNBT ​

Returns a newly serialized NBT compound for the entity, excluding its ID.
Returns: the entity as a piece of NBT

Note: was a String until 1.5.0

getPassengers ​

getPassengers(): List<EntityHelper<?>>Since1.2.5#
Returns the entity's passengers, or null if it has none.
Returns: the entity passengers, or null if there are none

getPitch ​

getPitch(): floatSince1.0.8#
Returns the entity's pitch in degrees, without angle wrapping.
Returns: the pitch value of the entity.

getPos ​

getPos(): Pos3D#
Returns a copy of the entity's current position in world coordinates.
Returns: the entity's position.
getPos(float partialTicks): Pos3D#
Returns the entity's position interpolated between its previous and current positions by the supplied partial-tick fraction.

Parameters:

  • partialTicks: the partial-tick interpolation fraction.
Returns: the interpolated entity position.

getSpeed ​

getSpeed(): doubleSince1.8.4#
Returns horizontal movement since the previous tick, scaled to blocks per second.
Returns: this entity's current speed in blocks per second.

getType ​

getType(): String#
Returns the entity type's registry id, including its namespace; this identifies the type, not an individual entity.
Returns: the type of the entity.

getUUID ​

getUUID(): StringSince1.6.5#
Returns: the entity's UUID as a string.

getVehicle ​

getVehicle(): EntityHelper<?>Since1.2.5#
Returns the vehicle carrying this entity, or null if it has none.
Returns: the vehicle of the entity.

getVelocity ​

getVelocity(): Pos3DSince1.8.4#
Returns a copy of the entity's current movement vector, in blocks per tick. Changing the returned position does not change the entity's movement.
Returns: the velocity vector.

getX ​

getX(): doubleSince1.0.8#
Returns the entity's current x coordinate in world coordinates.
Returns: the x coordinate.

getY ​

getY(): doubleSince1.0.8#
Returns the entity's current y coordinate in world coordinates.
Returns: the y coordinate.

getYaw ​

getYaw(): floatSince1.0.8#
Returns the entity's yaw in degrees, wrapped to the range [-180, 180).
Returns: the yaw value of the entity.

getZ ​

getZ(): doubleSince1.0.8#
Returns the entity's current z coordinate in world coordinates.
Returns: the z coordinate.

is ​

is(String... types): booleanSince1.9.0#
Returns whether this entity's type matches any specified entity id. This is a check on getType(), so what is being matched is the kind of thing rather than anything about this individual. Several types can be given at once, in which case the answer is whether the entity is any of them rather than all of them. Each is an entity id and the namespace may be left off, in which case it is read as minecraft. Giving no ids answers false, since there is nothing to match.

Parameters:

  • types: the entity ids to match against
Returns: true if this entity is any of the given types, false otherwise.

isAlive ​

isAlive(): booleanSince1.2.8#
Returns whether the entity is alive.
Returns: true if the entity has not been killed, false otherwise

isGlowing ​

isGlowing(): booleanSince1.1.9#
Returns whether the entity is currently glowing. This does not identify the cause; the outline color is read separately with getGlowingColor().
Returns: if the entity has the glowing effect.

isInLava ​

isInLava(): booleanSince1.1.9#
Returns whether the entity is in lava; this is distinct from isOnFire().
Returns: if the entity is in lava.

isOnFire ​

isOnFire(): booleanSince1.1.9#
Returns whether the entity is on fire.
Returns: if the entity is on fire.

isSneaking ​

isSneaking(): booleanSince1.8.4#
Returns whether the entity's shift-key-down state is set; this is not a pose check.
Returns: true if the entity is sneaking, false otherwise.

isSprinting ​

isSprinting(): booleanSince1.8.4#
Returns whether the entity's sprinting state is set.
Returns: true if the entity is sprinting, false otherwise.

rayTraceBlock ​

rayTraceBlock(double distance, boolean fluid): BlockDataHelperSince1.9.0#
Traces from the entity to find a block within the given distance, or returns null if the trace misses or hits void air. Distance is in blocks; the fluid argument controls fluid handling.

Parameters:

  • distance: how far to reach in blocks
  • fluid: whether fluids should be traced through and against
Returns: the block the entity is looking at, or null if there is none

rayTraceEntity ​

rayTraceEntity(int distance): EntityHelper<?>Since1.9.0#
Returns the pickable entity hit by the entity's targeting trace, or null if no entity is hit within the given distance. Distance is in blocks.

Parameters:

  • distance: how far to reach in blocks
Returns: the hit entity, or null if there is no hit

resetGlowing ​

resetGlowing(): EntityHelper<T extends Entity>Since1.6.3#
Restores the game's decision about whether the entity glows. This does not reset its glow colour; use resetGlowingColor() for that.
Returns: self for chaining.

resetGlowingColor ​

resetGlowingColor(): EntityHelper<T extends Entity>#
Restores the entity's team-derived glow colour after setGlowingColor(int). This does not change whether the entity glows; use resetGlowing() for that.
Returns: self for chaining.

setCustomName ​

setCustomName(TextHelper name): EntityHelper<T extends Entity>Since1.6.4#
Sets the entity's custom name; passing null clears it.

Parameters:

  • name: the name to give the entity, or null to take it off
Returns: self for chaining.

setCustomNameVisible ​

setCustomNameVisible(boolean b): EntityHelper<T extends Entity>Since1.8.0#
Sets whether the entity's custom name is always visible.

Parameters:

  • b: whether the name should always be shown
Returns: self for chaining.

setGlowing ​

setGlowing(boolean val): EntityHelper<T extends Entity>Since1.1.9#
Forces the entity's client-side glow outline on or off, overriding the game's normal decision. resetGlowing() restores the game's decision.

Parameters:

  • val: whether the entity should be glowing
Returns: self for chaining.

setGlowingColor ​

setGlowingColor(int color): EntityHelper<T extends Entity>#
Sets the entity's client-side glow color using a packed color value. This can override the color used for drawing without changing its team color.

Parameters:

  • color: the packed rgb colour to glow in
Returns: self for chaining.

toString ​

toString(): String#
Returns a diagnostic string containing this helper's runtime class name, the representation of its getName() text helper, and its entity type ID.
Returns: a diagnostic representation of the entity