Skip to content

LivingEntityHelper ​

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

Adds living-entity state, such as health, equipment, and status effects, to an entity helper.

Values reflect the client's current entity state; this helper does not modify it.

asLiving() on an entity helper is a cast, not a type check; it throws if the helper does not wrap a living entity. Use instanceof EntityHelpers.Living, or a type-filtered entity query, when narrowing from an unfiltered entity list.

js
// the living things within twenty blocks, and their health
const mobs = World.getEntities(20, "zombie", "skeleton", "creeper", "cow");  
if (mobs !== null) {
  for (const entity of mobs) {
    if (!(entity instanceof EntityHelpers.Living)) continue;  
    Chat.log(`${entity.getType()}: ${entity.getHealth()} of ${entity.getMaxHealth()}`);  
  }
}

Available in scripts as EntityHelpers.Living.

Type Parameters ​

  • T: the living entity wrapped by this helper

Constructors ​

new LivingEntityHelper ​

new LivingEntityHelper(T extends LivingEntity e)#
Wraps the supplied living entity, retaining the same entity reference.

Parameters:

  • e: the living entity to wrap

Methods ​

canBreatheInWater ​

canBreatheInWater(): booleanSince1.8.4#
whether the entity can breathe underwater according to its entity behavior; this does not account for breathing equipment.
Returns: if the entity can breathe in water

canHaveStatusEffect ​

canHaveStatusEffect(StatusEffectHelper effect): booleanSince1.8.4#
Checks whether Minecraft considers this entity eligible for the given effect; this does not check whether the effect is currently active.

Parameters:

  • effect: the status effect
Returns: true if the entity can be affected by the effect

canSeeEntity ​

canSeeEntity(EntityHelper<?> entity): booleanSince1.8.4#
Checks line of sight using only the three-point raycast; it does not perform the extended search available through canSeeEntity(EntityHelper, boolean).

Parameters:

  • entity: the entity to check line of sight to
Returns: true if the player has line of sight to the specified entity, false otherwise.
canSeeEntity(EntityHelper<?> entity, boolean simpleCast): booleanSince1.8.4#
Checks three target points first. If simpleCast is false and those fail, also raycasts to four side positions at 0.1-block vertical intervals, starting at the target's base; the upper remainder may be unsampled. These checks use visual-block raycasts and ignore fluids.

Parameters:

  • entity: the entity to check line of sight to
  • simpleCast: whether to use a simple raycast or a more complex one
Returns: true if a tested ray misses visual-block collisions

canTakeDamage ​

canTakeDamage(): booleanSince1.8.4#
whether the entity passes the game's enemy-visibility check: it must not be invulnerable, must not be a spectator, and must be alive. This is not a guarantee that every damage source can hurt it.
Returns: if the entity can take damage

canTarget ​

canTarget(LivingEntityHelper<?> target): booleanSince1.8.4#
whether the game permits this entity to attack the target. This is an eligibility check, not an indication that the entity wants to attack; players are not attackable in peaceful difficulty.

Parameters:

  • target: the target entity
Returns: if the entity can target a target entity

getAbsorptionHealth ​

getAbsorptionHealth(): floatSince1.8.4#
the entity's absorption amount, which absorbs damage before health.
Returns: the entity's absorption amount.

getArmor ​

getArmor(): intSince1.8.4#
the entity's armor value as used by the game's damage calculation.
Returns: the entity's armor value.

getArmorToughness ​

getArmorToughness(): doubleSince2.0.0#
the entity's armor-toughness attribute value.
Returns: the entity's armor toughness.

getBowPullProgress ​

getBowPullProgress(): doubleSince1.8.4#
Returns the bow draw power for the item in the entity's main hand, or 0 if it is not a bow.
Returns: the bow pull progress of the entity, 0 by default.

getChestArmor ​

getChestArmor(): ItemStackHelperSince1.2.7#
Returns the stack in the chest armor slot; an empty slot is represented by an empty stack.
Returns: the item in the entity's chest armor slot.

getDefaultHealth ​

getDefaultHealth(): floatSince1.8.4#
Returns a version-dependent value under this legacy method name: in Minecraft 1.21.8, the entity's invulnerability duration; from 1.21.11, its maximum health.
Returns: the version-dependent value described above

Note: returns float since 2.0.0

getFootArmor ​

getFootArmor(): ItemStackHelperSince1.2.7#
the item in the entity's boots slot, or an empty stack if the slot is empty.
Returns: the item in the entity's foot armor slot.

getHeadArmor ​

getHeadArmor(): ItemStackHelperSince1.2.7#
Returns the stack in the head armor slot; an empty slot is represented by an empty stack.
Returns: the item in the entity's head armor slot.

getHealth ​

getHealth(): floatSince1.3.1#
the entity's current health, on the same scale as getMaxHealth(). For entities observed by the client, this is the latest value synchronized to it.
Returns: entity's health

getItemUseTimeLeft ​

getItemUseTimeLeft(): intSince1.9.0#
Returns the remaining use duration of the entity's currently used item, in ticks; zero when not using an item.
Returns: the ticks left of using the held item

getLegArmor ​

getLegArmor(): ItemStackHelperSince1.2.7#
the item in the entity's leggings slot, or an empty stack if the slot is empty.
Returns: the item in the entity's leg armor slot.

getMainHand ​

getMainHand(): ItemStackHelperSince1.2.7#
Returns the main-hand stack; an empty hand is represented by an empty stack, not null.
Returns: the item in the entity's main hand.

getMaxHealth ​

getMaxHealth(): floatSince1.6.5#
the entity's maximum health, which sets the upper bound for getHealth().
Returns: entity's max health

getMobTags ​

getMobTags(): List<String>Since1.9.1#
the tags on this kind of entity rather than on this one entity, which is what the game's own entity type registry carries. A tag is a group the entity type is in, such as the one the game uses to find the undead, so two entities of the same type give the same list whatever has happened to them. The entries are tag ids as strings with the namespace on the front. This is the list isUndead() is answered from, rather than a check run here.
Returns: the tags on this entity's type

getOffHand ​

getOffHand(): ItemStackHelperSince1.2.7#
Returns the off-hand stack; an empty slot is represented by an empty stack.
Returns: the item in the entity's off hand.

getStatusEffects ​

getStatusEffects(): List<StatusEffectHelper>Since1.2.7#
Returns a new list of the entity's active status effects.
Returns: the entity's active status effects

hasNoDrag ​

hasNoDrag(): booleanSince1.8.4#
whether the entity is configured to discard friction; this reports a flag, not its current motion.
Returns: if the entity has no drag

hasNoGravity ​

hasNoGravity(): booleanSince1.8.4#
whether the entity is configured to ignore gravity; this reports a flag, not whether it is currently falling.
Returns: if the entity has no gravity

hasStatusEffect ​

hasStatusEffect(String id): booleanSince1.8.4#
Checks the client's active-effect list for the given effect ID. For remote entities, this reflects only effects present in the client-side state.

Parameters:

  • id: the id of the status effect to look for
Returns: true if an active effect has this ID; false otherwise

isBaby ​

isBaby(): booleanSince1.8.4#
Returns the entity's baby state as reported by Minecraft.
Returns: true if the entity is a baby, false otherwise.

isFallFlying ​

isFallFlying(): booleanSince1.5.0#
whether the entity is currently fall-flying; this reports flight state, not merely whether it has an elytra equipped.
Returns: if the entity has elytra deployed

isHolding ​

isHolding(String item): booleanSince1.9.0#
Checks whether either hand holds the item with this ID. The namespace may be omitted and defaults to minecraft; the air ID checks for an empty hand.

Parameters:

  • item: the id of the item to look for
Returns: true if either hand holds the item; false otherwise

isOnGround ​

isOnGround(): booleanSince1.8.4#
whether the entity's on-ground flag is set; this is not a direct check of the block beneath it.
Returns: if the entity is on the ground

isPartOfGame ​

isPartOfGame(): booleanSince1.8.4#
whether the entity is alive and not a spectator. Unlike canTakeDamage(), this does not also check invulnerability.
Returns: if the entity is part of the game (is alive and not spectator)

isSleeping ​

isSleeping(): booleanSince1.2.7#
whether the entity has a sleeping position. This indicates sleeping state, not how long it has been asleep.
Returns: if the entity is in a bed.

isSpectator ​

isSpectator(): booleanSince1.8.4#
whether the entity is in spectator mode.
Returns: if the entity is in spectator

isUndead ​

isUndead(): booleanSince1.8.4#
Returns whether this entity's type belongs to the game's undead entity-type tag.
Returns: if the entity is undead