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
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
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
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
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
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
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
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 entityasVillager
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 appliesdistanceTo
Returns the three-dimensional distance between the entities' positions (not their eyes).
Parameters:
entity: the entity to measure to
Returns: the distance in blocks.
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.
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.
Returns the three-dimensional distance from this entity's position to the given coordinates.
Parameters:
x: the x coordinate to measure toy: the y coordinate to measure toz: the z coordinate to measure to
Returns: the distance in blocks.
getAir
Returns the current air supply, in ticks.
Returns: the amount of air this entity has.
getBiome
getBlockPos
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
Returns the chunk containing this entity's block position.
Returns: the chunk helper for the chunk this entity is in.
getChunkPos
getEyeHeight
getEyePos
getFacingDirection
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
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
Returns the maximum air supply, in ticks.
Returns: the maximum amount of air this entity can have.
getName
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
getPassengers
Returns the entity's passengers, or
null if it has none.Returns: the entity passengers, or
null if there are nonegetPitch
Returns the entity's pitch in degrees, without angle wrapping.
Returns: the
pitch value of the entity.getPos
Returns a copy of the entity's current position in world coordinates.
Returns: the entity's position.
getSpeed
Returns horizontal movement since the previous tick, scaled to blocks per second.
Returns: this entity's current speed in blocks per second.
getType
getUUID
getVehicle
Returns the vehicle carrying this entity, or
null if it has none.Returns: the vehicle of the entity.
getVelocity
getX
Returns the entity's current x coordinate in world coordinates.
Returns: the x coordinate.
getY
Returns the entity's current y coordinate in world coordinates.
Returns: the y coordinate.
getYaw
Returns the entity's yaw in degrees, wrapped to the range
[-180, 180).Returns: the
yaw value of the entity.getZ
Returns the entity's current z coordinate in world coordinates.
Returns: the z coordinate.
is
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
Returns whether the entity is alive.
Returns:
true if the entity has not been killed, false otherwiseisGlowing
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
Returns whether the entity is in lava; this is distinct from isOnFire().
Returns: if the entity is in lava.
isOnFire
Returns whether the entity is on fire.
Returns: if the entity is on fire.
isSneaking
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
Returns whether the entity's sprinting state is set.
Returns:
true if the entity is sprinting, false otherwise.rayTraceBlock
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 blocksfluid: whether fluids should be traced through and against
Returns: the block the entity is looking at, or
null if there is nonerayTraceEntity
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 hitresetGlowing
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
Sets the entity's custom name; passing
null clears it.Parameters:
name: the name to give the entity, ornullto take it off
Returns: self for chaining.
setCustomNameVisible
Sets whether the entity's custom name is always visible.
Parameters:
b: whether the name should always be shown
Returns: self for chaining.
setGlowing
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.