# 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...)](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_asAnimal-}

```js
asAnimal(): LivingEntityHelper<?>
```

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

**Since:** 1.8.4

### asClientPlayer {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_asClientPlayer-}

```js
asClientPlayer(): ClientPlayerEntityHelper<?>
```

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

**Since:** 1.6.3

### asItem {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_asItem-}

```js
asItem(): ItemEntityHelper
```

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

**Since:** 1.6.3

### asLiving {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_asLiving-}

```js
asLiving(): LivingEntityHelper<?>
```

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

**Since:** 1.6.3

### asMerchant {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_asMerchant-}

```js
asMerchant(): MerchantEntityHelper<?>
```

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

**Since:** 1.6.3

### asPlayer {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_asPlayer-}

```js
asPlayer(): PlayerEntityHelper<?>
```

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

**Since:** 1.6.3

### asServerEntity {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_asServerEntity-}

```js
asServerEntity(): EntityHelper<?>
```

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

**Since:** 1.8.4

### asVillager {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_asVillager-}

```js
asVillager(): VillagerEntityHelper
```

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

**Since:** 1.6.3

### create {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_create-Entity-}

```js
static create(Entity e): EntityHelper<?>
```

Wraps a Minecraft entity in the most specific supported helper subtype. Throws
[NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html) 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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_distanceTo-EntityHelper-}

```js
distanceTo(EntityHelper<?> entity): float
```

Returns the three-dimensional distance between the entities' positions (not their eyes).

**Parameters:**
- `entity`: the entity to measure to

**Returns:** the distance in blocks.

**Since:** 1.8.4

### distanceTo {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_distanceTo-BlockPosHelper-}

```js
distanceTo(BlockPosHelper pos): double
```

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.

**Since:** 1.8.4

### distanceTo {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_distanceTo-Pos3D-}

```js
distanceTo(Pos3D pos): double
```

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.

**Since:** 1.8.4

### distanceTo {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_distanceTo-double-double-double-}

```js
distanceTo(double x, double y, double z): double
```

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.

**Since:** 1.8.4

### getAir {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getAir-}

```js
getAir(): int
```

Returns the current air supply, in ticks.

**Returns:** the amount of air this entity has.

**Since:** 1.8.4

### getBiome {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getBiome-}

```js
getBiome(): String
```

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.

**Since:** 1.8.4

### getBlockPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getBlockPos-}

```js
getBlockPos(): BlockPosHelper
```

Returns the block position containing the entity's position (coordinates are
rounded down, not to the nearest block).

**Returns:** the entity's block position.

**Since:** 1.6.5

### getChunk {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getChunk-}

```js
getChunk(): ChunkHelper
```

Returns the chunk containing this entity's block position.

**Returns:** the chunk helper for the chunk this entity is in.

**Since:** 1.8.4

### getChunkPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getChunkPos-}

```js
getChunkPos(): Pos2D
```

Returns the entity's chunk coordinates as a [Pos2D](../../../../../api/math/Pos2D.md): x is chunk x and y
is world chunk z.

**Returns:** the entity's chunk coordinates.

**Since:** 1.6.5

### getEyeHeight {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getEyeHeight-}

```js
getEyeHeight(): double
```

Returns the entity's eye-height offset for its current pose. Adding it to
[getY()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getY-) gives the eye position's y coordinate.

**Returns:** the current eye height offset for the entity.

**Since:** 1.2.8

### getEyePos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getEyePos-}

```js
getEyePos(): Pos3D
```

Returns the position of the entity's eyes, which depends on its current pose.

**Returns:** the entity's eye position.

**Since:** 1.8.4

### getFacingDirection {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getFacingDirection-}

```js
getFacingDirection(): DirectionHelper
```

Returns the horizontal cardinal direction corresponding to the entity's yaw.

**Returns:** the direction the entity is facing, rounded to the nearest 90 degrees.

**Since:** 1.8.4

### getGlowingColor {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getGlowingColor-}

```js
getGlowingColor(): int
```

Returns the entity's team color, or `0` if it has no team color.  
A color set by [setGlowingColor(int)](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_setGlowingColor-int-) can override the color used for drawing
without changing this value.

**Returns:** glow color

**Since:** 1.8.2

### getMaxAir {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getMaxAir-}

```js
getMaxAir(): int
```

Returns the maximum air supply, in ticks.

**Returns:** the maximum amount of air this entity can have.

**Since:** 1.8.4

### getName {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getName-}

```js
getName(): TextHelper
```

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.

**Since:** 1.0.2

### getNBT {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getNBT-}

```js
getNBT(): NBTElementHelper.NBTCompoundHelper
```

Returns a newly serialized NBT compound for the entity, excluding its ID.

**Returns:** the entity as a piece of NBT

**Since:** 1.2.8

**Note:** was a [String](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) until 1.5.0

### getPassengers {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getPassengers-}

```js
getPassengers(): List<EntityHelper<?>>
```

Returns the entity's passengers, or `null` if it has none.

**Returns:** the entity passengers, or `null` if there are none

**Since:** 1.2.5

### getPitch {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getPitch-}

```js
getPitch(): float
```

Returns the entity's pitch in degrees, without angle wrapping.

**Returns:** the `pitch` value of the entity.

**Since:** 1.0.8

### getPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getPos-}

```js
getPos(): Pos3D
```

Returns a copy of the entity's current position in world coordinates.

**Returns:** the entity's position.

### getPos {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getPos-float-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getSpeed-}

```js
getSpeed(): double
```

Returns horizontal movement since the previous tick, scaled to blocks per second.

**Returns:** this entity's current speed in blocks per second.

**Since:** 1.8.4

### getType {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getType-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getUUID-}

```js
getUUID(): String
```

**Returns:** the entity's UUID as a string.

**Since:** 1.6.5

### getVehicle {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getVehicle-}

```js
getVehicle(): EntityHelper<?>
```

Returns the vehicle carrying this entity, or `null` if it has none.

**Returns:** the vehicle of the entity.

**Since:** 1.2.5

### getVelocity {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getVelocity-}

```js
getVelocity(): Pos3D
```

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.

**Since:** 1.8.4

### getX {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getX-}

```js
getX(): double
```

Returns the entity's current x coordinate in world coordinates.

**Returns:** the x coordinate.

**Since:** 1.0.8

### getY {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getY-}

```js
getY(): double
```

Returns the entity's current y coordinate in world coordinates.

**Returns:** the y coordinate.

**Since:** 1.0.8

### getYaw {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getYaw-}

```js
getYaw(): float
```

Returns the entity's yaw in degrees, wrapped to the range `[-180, 180)`.

**Returns:** the `yaw` value of the entity.

**Since:** 1.0.8

### getZ {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getZ-}

```js
getZ(): double
```

Returns the entity's current z coordinate in world coordinates.

**Returns:** the z coordinate.

**Since:** 1.0.8

### is {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_is-String[]-}

```js
is(String... types): boolean
```

Returns whether this entity's type matches any specified entity id.  

This is a check on [getType()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_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.

**Since:** 1.9.0

### isAlive {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_isAlive-}

```js
isAlive(): boolean
```

Returns whether the entity is alive.

**Returns:** `true` if the entity has not been killed, `false` otherwise

**Since:** 1.2.8

### isGlowing {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_isGlowing-}

```js
isGlowing(): boolean
```

Returns whether the entity is currently glowing. This does not identify the
cause; the outline color is read separately with [getGlowingColor()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getGlowingColor-).

**Returns:** if the entity has the glowing effect.

**Since:** 1.1.9

### isInLava {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_isInLava-}

```js
isInLava(): boolean
```

Returns whether the entity is in lava; this is distinct from [isOnFire()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_isOnFire-).

**Returns:** if the entity is in lava.

**Since:** 1.1.9

### isOnFire {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_isOnFire-}

```js
isOnFire(): boolean
```

Returns whether the entity is on fire.

**Returns:** if the entity is on fire.

**Since:** 1.1.9

### isSneaking {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_isSneaking-}

```js
isSneaking(): boolean
```

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.

**Since:** 1.8.4

### isSprinting {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_isSprinting-}

```js
isSprinting(): boolean
```

Returns whether the entity's sprinting state is set.

**Returns:** `true` if the entity is sprinting, `false` otherwise.

**Since:** 1.8.4

### rayTraceBlock {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_rayTraceBlock-double-boolean-}

```js
rayTraceBlock(double distance, boolean fluid): BlockDataHelper
```

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

**Since:** 1.9.0

### rayTraceEntity {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_rayTraceEntity-int-}

```js
rayTraceEntity(int distance): EntityHelper<?>
```

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

**Since:** 1.9.0

### resetGlowing {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_resetGlowing-}

```js
resetGlowing(): EntityHelper<T extends Entity>
```

Restores the game's decision about whether the entity glows. This does not reset
its glow color; use [resetGlowingColor()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_resetGlowingColor-) for that.

**Returns:** self for chaining.

**Since:** 1.6.3

### resetGlowingColor {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_resetGlowingColor-}

```js
resetGlowingColor(): EntityHelper<T extends Entity>
```

Restores the entity's team-derived glow color after [setGlowingColor(int)](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_setGlowingColor-int-).  
This does not change whether the entity glows; use [resetGlowing()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_resetGlowing-) for that.

**Returns:** self for chaining.

### setCustomName {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_setCustomName-TextHelper-}

```js
setCustomName(TextHelper name): EntityHelper<T extends Entity>
```

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.

**Since:** 1.6.4

### setCustomNameVisible {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_setCustomNameVisible-boolean-}

```js
setCustomNameVisible(boolean b): EntityHelper<T extends Entity>
```

Sets whether the entity's custom name is always visible.

**Parameters:**
- `b`: whether the name should always be shown

**Returns:** self for chaining.

**Since:** 1.8.0

### setGlowing {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_setGlowing-boolean-}

```js
setGlowing(boolean val): EntityHelper<T extends Entity>
```

Forces the entity's client-side glow outline on or off, overriding the game's
normal decision. [resetGlowing()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_resetGlowing-) restores the game's decision.

**Parameters:**
- `val`: whether the entity should be glowing

**Returns:** self for chaining.

**Since:** 1.1.9

### setGlowingColor {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_setGlowingColor-int-}

```js
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 color to glow in

**Returns:** self for chaining.

### toString {#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_toString-}

```js
toString(): String
```

Returns a diagnostic string containing this helper's runtime class name, the
representation of its [getName()](#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getName-) text helper, and its entity type ID.

**Returns:** a diagnostic representation of the entity
