Package dev.boze.api.utility
Class EntityHelper
java.lang.Object
dev.boze.api.utility.EntityHelper
EntityHelper provides entity utility methods.
This class offers a comprehensive set of utilities for working with Minecraft entities,
including distance calculations, health checks, entity type validation, and status queries.
All methods handle null entities gracefully and provide safe defaults.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanSee(net.minecraft.entity.Entity from, net.minecraft.entity.Entity to) Checks if one entity can see another entity.static intgetArmorDurability(net.minecraft.entity.Entity entity) Gets the total durability of all armor items worn by an entity.static doublegetDistance(net.minecraft.entity.Entity from, net.minecraft.entity.Entity to) Gets the distance between two entities.static net.minecraft.util.math.Vec3dgetEyePos(net.minecraft.entity.Entity entity) Gets the eye position of an entity.static net.minecraft.world.GameModegetGameMode(net.minecraft.entity.player.PlayerEntity player) Gets the game mode of a player.static floatgetHealth(net.minecraft.entity.Entity entity) Gets the total health of an entity.static net.minecraft.util.math.Vec3dgetInterpolatedPos(net.minecraft.entity.Entity entity, float delta) Gets the interpolated position of an entity for smooth rendering.static floatgetMaxHealth(net.minecraft.entity.Entity entity) Gets the maximum health of an entity.static intgetPing(net.minecraft.entity.player.PlayerEntity player) Gets the ping (latency) of a player in milliseconds.static booleanhasTotem(net.minecraft.entity.Entity entity) Checks if an entity has a Totem of Undying in their offhand.static booleanisAlive(net.minecraft.entity.Entity entity) Checks if an entity is alive.static booleanisBurrowed(net.minecraft.entity.Entity entity) Checks if an entity is burrowed (inside a block).static booleanisFriend(net.minecraft.entity.Entity entity) Checks if an entity is friended.static booleanisHostile(net.minecraft.entity.Entity entity) Checks if an entity is hostile.static booleanisInHole(net.minecraft.entity.Entity entity, boolean doubles) Checks if an entity is in a hole (surrounded by blocks).static booleanisInvisible(net.minecraft.entity.Entity entity) Checks if an entity is invisible.static booleanisMoving(net.minecraft.entity.Entity entity) Checks if an entity is currently moving.static booleanisPassive(net.minecraft.entity.Entity entity) Checks if an entity is passive/animal.static booleanisTarget(net.minecraft.entity.Entity entity) Checks if an entity is currently targeted.static booleanisWithinRange(net.minecraft.entity.Entity entity, double range) Checks if an entity is within range of the player.static booleanisWithinRange(net.minecraft.entity.Entity entity, net.minecraft.entity.Entity from, double range) Checks if an entity is within range of another entity.
-
Constructor Details
-
EntityHelper
public EntityHelper()
-
-
Method Details
-
isWithinRange
public static boolean isWithinRange(net.minecraft.entity.Entity entity, double range) Checks if an entity is within range of the player. This method calculates the distance from the player to the specified entity and returns true if the entity is within the given range.- Parameters:
entity- The entity to check distance forrange- The maximum distance in blocks- Returns:
- true if the entity is within range, false otherwise
-
isWithinRange
public static boolean isWithinRange(net.minecraft.entity.Entity entity, net.minecraft.entity.Entity from, double range) Checks if an entity is within range of another entity. This method calculates the distance between the two entities and returns true if the target entity is within the given range.- Parameters:
entity- The entity to check distance forfrom- The entity to measure distance fromrange- The maximum distance in blocks- Returns:
- true if the entity is within range, false otherwise
-
getDistance
public static double getDistance(net.minecraft.entity.Entity from, net.minecraft.entity.Entity to) Gets the distance between two entities. Calculates the Euclidean distance between the positions of two entities. Returns Double.MAX_VALUE if either entity is null.- Parameters:
from- The first entityto- The second entity- Returns:
- The distance in blocks, or Double.MAX_VALUE if either entity is null
-
getEyePos
public static net.minecraft.util.math.Vec3d getEyePos(net.minecraft.entity.Entity entity) Gets the eye position of an entity. Returns the position of the entity's eyes, which is typically used for line-of-sight calculations and targeting. Returns Vec3d.ZERO if the entity is null.- Parameters:
entity- The entity to get eye position for- Returns:
- The eye position as a Vec3d, or Vec3d.ZERO if entity is null
-
canSee
public static boolean canSee(net.minecraft.entity.Entity from, net.minecraft.entity.Entity to) Checks if one entity can see another entity. Performs a line-of-sight check between two entities by casting a ray from the first entity's eyes to the second entity's eyes. Returns false if either entity is null.- Parameters:
from- The entity doing the seeingto- The entity being seen- Returns:
- true if there's a clear line of sight, false otherwise
-
getInterpolatedPos
public static net.minecraft.util.math.Vec3d getInterpolatedPos(net.minecraft.entity.Entity entity, float delta) Gets the interpolated position of an entity for smooth rendering. Calculates the interpolated position between the entity's previous position and current position using the specified delta value. A delta of 0.0F returns the previous frame position, while 1.0F returns the current position. This is useful for smooth rendering animations that occur between ticks. Returns Vec3d.ZERO if the entity is null.- Parameters:
entity- The entity to get interpolated position fordelta- The interpolation factor between 0.0F and 1.0F- Returns:
- The interpolated position as a Vec3d, or Vec3d.ZERO if entity is null
-
getHealth
public static float getHealth(net.minecraft.entity.Entity entity) Gets the total health of an entity. Returns the entity's current health plus any absorption amount. For non-living entities, returns 0.0F.- Parameters:
entity- The entity to get health for- Returns:
- The total health value, or 0.0F if not a living entity
-
getMaxHealth
public static float getMaxHealth(net.minecraft.entity.Entity entity) Gets the maximum health of an entity. Returns the entity's maximum health capacity. For non-living entities, returns 0.0F.- Parameters:
entity- The entity to get max health for- Returns:
- The maximum health value, or 0.0F if not a living entity
-
getArmorDurability
public static int getArmorDurability(net.minecraft.entity.Entity entity) Gets the total durability of all armor items worn by an entity. Calculates the sum of remaining durability (max damage - current damage) for all armor pieces (helmet, chestplate, leggings, boots). Only counts humanoid armor slots, not horse armor. For non-living entities, returns 0.- Parameters:
entity- The entity to get armor durability for- Returns:
- The total remaining durability of all armor pieces, or 0 if not a living entity
-
hasTotem
public static boolean hasTotem(net.minecraft.entity.Entity entity) Checks if an entity has a Totem of Undying in their offhand. Returns true if the entity is holding a Totem of Undying in their offhand slot. For non-living entities, returns false.- Parameters:
entity- The entity to check- Returns:
- true if the entity has a totem in offhand, false otherwise
-
getPing
public static int getPing(net.minecraft.entity.player.PlayerEntity player) Gets the ping (latency) of a player in milliseconds. Retrieves the player's network latency from the tab list. Returns 0 if the player is not found in the tab list.- Parameters:
player- The player to get ping for- Returns:
- The ping in milliseconds, or 0 if player is not in tab list
-
isHostile
public static boolean isHostile(net.minecraft.entity.Entity entity) Checks if an entity is hostile. Returns true if the entity belongs to the MONSTER spawn group (e.g., zombies, skeletons, creepers, etc.).- Parameters:
entity- The entity to check- Returns:
- true if the entity is hostile, false otherwise
-
isPassive
public static boolean isPassive(net.minecraft.entity.Entity entity) Checks if an entity is passive/animal. Returns true if the entity belongs to passive spawn groups (CREATURE, WATER_AMBIENT, WATER_CREATURE, UNDERGROUND_WATER_CREATURE, AXOLOTLS, AMBIENT) or is a special case like villagers.- Parameters:
entity- The entity to check- Returns:
- true if the entity is passive/animal, false otherwise
-
isFriend
public static boolean isFriend(net.minecraft.entity.Entity entity) Checks if an entity is friended. Returns true if the entity is a player that has been added to the friends list. For non-player entities, always returns false.- Parameters:
entity- The entity to check- Returns:
- true if the entity is friended, false otherwise
-
isTarget
public static boolean isTarget(net.minecraft.entity.Entity entity) Checks if an entity is currently targeted. Returns true if the entity is in the current target list, meaning it has been attacked recently and is being tracked.- Parameters:
entity- The entity to check- Returns:
- true if the entity is currently targeted, false otherwise
-
isInHole
public static boolean isInHole(net.minecraft.entity.Entity entity, boolean doubles) Checks if an entity is in a hole (surrounded by blocks). A hole is defined as being surrounded by solid blocks on all horizontal sides and having a solid block below. When doubles is false, checks for single-layer holes only. When doubles is true, checks for double-layer hole patterns.- Parameters:
entity- The entity to checkdoubles- Whether to check for double-layer holes (allows some air blocks)- Returns:
- true if the entity is in a hole, false otherwise
-
isBurrowed
public static boolean isBurrowed(net.minecraft.entity.Entity entity) Checks if an entity is burrowed (inside a block). Returns true if the entity's position is inside a solid block like obsidian, ender chests, or bedrock.- Parameters:
entity- The entity to check- Returns:
- true if the entity is burrowed, false otherwise
-
isAlive
public static boolean isAlive(net.minecraft.entity.Entity entity) Checks if an entity is alive. Returns true if the entity exists and is not dead. This is a safer check than just calling isAlive() on potentially null entities.- Parameters:
entity- The entity to check- Returns:
- true if the entity exists and is alive, false otherwise
-
isInvisible
public static boolean isInvisible(net.minecraft.entity.Entity entity) Checks if an entity is invisible. Returns true if the entity has the invisibility effect or is otherwise invisible. For null entities, returns false.- Parameters:
entity- The entity to check- Returns:
- true if the entity is invisible, false otherwise
-
isMoving
public static boolean isMoving(net.minecraft.entity.Entity entity) Checks if an entity is currently moving. Determines movement by checking if the entity's position has changed significantly (> 0.001 blocks) from its previous position. For null entities, returns false.- Parameters:
entity- The entity to check- Returns:
- true if the entity is moving, false otherwise
-
getGameMode
public static net.minecraft.world.GameMode getGameMode(net.minecraft.entity.player.PlayerEntity player) Gets the game mode of a player. Retrieves the player's current game mode from the tab list. Returns null if the player is not found in the tab list or if the player list hasn't loaded yet.- Parameters:
player- The player to get game mode for- Returns:
- The player's game mode, or null if not available
-