Class TargetUtil

java.lang.Object
com.hypixel.hytale.server.core.util.TargetUtil

public final class TargetUtil extends Object
A utility class that contains a variety of useful target related methods.
  • Constructor Details

    • TargetUtil

      public TargetUtil()
  • Method Details

    • getTargetBlock

      @Nullable public static org.joml.Vector3i getTargetBlock(@Nonnull ChunkStore chunkStore, @Nonnull BiIntPredicate blockIdPredicate, double originX, double originY, double originZ, double directionX, double directionY, double directionZ, double maxDistance)
      Called to fetch the target block position based on a raycast from an origin in a specific direction.
      Parameters:
      chunkStore - The chunk store to perform the raycast in.
      blockIdPredicate - A predicate that tests the block ID and fluid ID at each position. Return true to continue the raycast, false to stop.
      originX - The X coordinate of the origin.
      originY - The Y coordinate of the origin.
      originZ - The Z coordinate of the origin.
      directionX - The X component of the direction.
      directionY - The Y component of the direction.
      directionZ - The Z component of the direction.
      maxDistance - The maximum distance to cast.
      Returns:
      the target Vector3i block position, or null if no block was found within the max distance.
    • getTargetBlock

      @Nullable @Deprecated public static org.joml.Vector3i getTargetBlock(@Nonnull World world, @Nonnull BiIntPredicate blockIdPredicate, double originX, double originY, double originZ, double directionX, double directionY, double directionZ, double maxDistance)
      Deprecated.
    • getTargetBlockOrigin

      @Nullable public static org.joml.Vector3i getTargetBlockOrigin(@Nonnull ChunkStore chunkStore, @Nonnull BiIntPredicate blockIdPredicate, double originX, double originY, double originZ, double directionX, double directionY, double directionZ, double maxDistance)
      Called to fetch the origin (base) block position of a multi-block structure hit by a raycast.

      Functions identically to getTargetBlock(ChunkStore, BiIntPredicate, double, double, double, double, double, double, double), except the returned position is offset by the packed filler value at the hit position so that filler blocks resolve to their origin block.

      Parameters:
      chunkStore - The chunks store to perform the raycast in.
      blockIdPredicate - A predicate that tests the block ID and fluid ID at each position. Return true to continue the raycast, false to stop.
      originX - The X coordinate of the origin.
      originY - The Y coordinate of the origin.
      originZ - The Z coordinate of the origin.
      directionX - The X component of the direction.
      directionY - The Y component of the direction.
      directionZ - The Z component of the direction.
      maxDistance - The maximum distance to cast.
      Returns:
      the origin Vector3i block position, or null if no block was found within the max distance.
    • getTargetBlockOrigin

      @Nullable @Deprecated public static org.joml.Vector3i getTargetBlockOrigin(@Nonnull World world, @Nonnull BiIntPredicate blockIdPredicate, double originX, double originY, double originZ, double directionX, double directionY, double directionZ, double maxDistance)
      Deprecated.
    • getTargetLocation

      @Nullable public static org.joml.Vector3d getTargetLocation(@Nonnull ChunkStore chunkStore, @Nonnull IntPredicate blockIdPredicate, double originX, double originY, double originZ, double directionX, double directionY, double directionZ, double maxDistance)
      Called to fetch the target location based on a raycast from an origin in a specific direction.
      Parameters:
      chunkStore - The chunk store to perform the raycast in.
      blockIdPredicate - A predicate that tests the block ID at each position. Return true to continue the raycast, false to stop.
      originX - The X coordinate of the origin.
      originY - The Y coordinate of the origin.
      originZ - The Z coordinate of the origin.
      directionX - The X component of the direction.
      directionY - The Y component of the direction.
      directionZ - The Z component of the direction.
      maxDistance - The maximum distance to cast.
      Returns:
      the target Vector3d location, or null if no block was found within the max distance.
    • getTargetLocation

      @Nullable public static org.joml.Vector3d getTargetLocation(@Nonnull World world, @Nonnull IntPredicate blockIdPredicate, double originX, double originY, double originZ, double directionX, double directionY, double directionZ, double maxDistance)
    • getTargetBlockAvoidLocations

      @Nullable public static org.joml.Vector3i getTargetBlockAvoidLocations(@Nonnull ChunkStore chunkStore, @Nonnull IntPredicate blockIdPredicate, double originX, double originY, double originZ, double directionX, double directionY, double directionZ, double maxDistance, @Nonnull Collection<Int3OpenHashSet> blocksToIgnore)
      Called to fetch the target block position based on a raycast from an origin in a specific direction,
      Parameters:
      chunkStore - The chunk store to perform the raycast in.
      blockIdPredicate - A predicate that tests the block ID at each position. Return true to continue the raycast, false to stop.
      originX - The X coordinate of the origin.
      originY - The Y coordinate of the origin.
      originZ - The Z coordinate of the origin.
      directionX - The X component of the direction.
      directionY - The Y component of the direction.
      directionZ - The Z component of the direction.
      maxDistance - The maximum distance to cast.
      blocksToIgnore - A list of sets of block positions to ignore during the raycast.
      Returns:
      the target Vector3i block position, or null if no block was found within the max distance.
    • getTargetBlockAvoidLocations

      @Nullable @Deprecated public static org.joml.Vector3i getTargetBlockAvoidLocations(@Nonnull World world, @Nonnull IntPredicate blockIdPredicate, double originX, double originY, double originZ, double directionX, double directionY, double directionZ, double maxDistance, @Nonnull Collection<Int3OpenHashSet> blocksToIgnore)
      Deprecated.
    • getTargetBlockAvoidLocations

      @Nullable public static org.joml.Vector3i getTargetBlockAvoidLocations(@Nonnull ChunkStore chunkStore, @Nonnull IntPredicate blockIdPredicate, double originX, double originY, double originZ, double directionX, double directionY, double directionZ, double maxDistance, @Nonnull Collection<Int3OpenHashSet> blocksToIgnore, @Nonnull org.joml.Vector3d hitPositionOut)
    • getTargetBlockAvoidLocations

      @Nullable @Deprecated public static org.joml.Vector3i getTargetBlockAvoidLocations(@Nonnull World world, @Nonnull IntPredicate blockIdPredicate, double originX, double originY, double originZ, double directionX, double directionY, double directionZ, double maxDistance, @Nonnull Collection<Int3OpenHashSet> blocksToIgnore, @Nonnull org.joml.Vector3d hitPositionOut)
      Deprecated.
    • getTargetBlock

      @Nullable public static org.joml.Vector3i getTargetBlock(@Nonnull Ref<EntityStore> ref, double maxDistance, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch the target block position based on a raycast from an entity.
      Parameters:
      ref - The entity reference of the entity.
      maxDistance - The maximum distance to cast.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      the target Vector3i block position, or null if no block was found within the max distance.
    • getTargetBlock

      @Nullable public static org.joml.Vector3i getTargetBlock(@Nonnull Ref<EntityStore> ref, @Nonnull IntPredicate blockIdPredicate, double maxDistance, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch the target block position based on a raycast from an entity.
      Parameters:
      ref - The entity reference of the entity.
      blockIdPredicate - The predicate to test block IDs.
      maxDistance - The maximum distance to cast.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      the target Vector3i block position, or null if no block was found within the max distance.
    • getTargetBlockOrigin

      @Nullable public static org.joml.Vector3i getTargetBlockOrigin(@Nonnull Ref<EntityStore> ref, double maxDistance, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch the origin (base) block position of a multi-block structure hit by a raycast from an entity.
      Parameters:
      ref - The entity reference of the entity.
      maxDistance - The maximum distance to cast.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      the origin Vector3i block position, or null if no block was found within the max distance.
    • getTargetBlockOrigin

      @Nullable public static org.joml.Vector3i getTargetBlockOrigin(@Nonnull Ref<EntityStore> ref, @Nonnull IntPredicate blockIdPredicate, double maxDistance, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch the origin (base) block position of a multi-block structure hit by a raycast from an entity.
      Parameters:
      ref - The entity reference of the entity.
      blockIdPredicate - The predicate to test block IDs.
      maxDistance - The maximum distance to cast.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      the origin Vector3i block position, or null if no block was found within the max distance.
    • getTargetLocation

      @Nullable public static org.joml.Vector3d getTargetLocation(@Nonnull Ref<EntityStore> ref, double maxDistance, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch the target location based on a raycast from an entity.
      Parameters:
      ref - The entity reference of the entity.
      maxDistance - The maximum distance to cast.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      the target Vector3d location, or null if no block was found within the max distance.
    • getTargetLocation

      @Nullable public static org.joml.Vector3d getTargetLocation(@Nonnull Ref<EntityStore> ref, @Nonnull IntPredicate blockIdPredicate, double maxDistance, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch the target location based on a raycast from an entity.
      Parameters:
      ref - The entity reference of the entity.
      blockIdPredicate - The predicate to test block IDs.
      maxDistance - The maximum distance to cast.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      the target Vector3d location, or null if no block was found within the max distance.
    • getTargetLocation

      @Nullable public static org.joml.Vector3d getTargetLocation(@Nonnull Transform transform, @Nonnull IntPredicate blockIdPredicate, double maxDistance, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch the target location based on a raycast from an entity.
      Parameters:
      transform - The transform to raycast from.
      blockIdPredicate - The predicate to test block IDs.
      maxDistance - The maximum distance to cast.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      the target Vector3d location, or null if no block was found within the max distance.
    • getAllEntitiesInSphere

      @Nonnull public static List<Ref<EntityStore>> getAllEntitiesInSphere(@Nonnull org.joml.Vector3d position, double radius, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch a list of all entities within a spherical area, utilising the spatial resources available.
      Parameters:
      position - The center position of the sphere.
      radius - The radius of the sphere.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      a list of entity references within the sphere.
    • getAllEntitiesInCylinder

      @Nonnull public static List<Ref<EntityStore>> getAllEntitiesInCylinder(@Nonnull org.joml.Vector3d position, double radius, double height, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch a list of all entities within a cylindrical area, utilising the spatial resources available.
      Parameters:
      position - The center position of the cylinder.
      radius - The radius of the cylinder in the XZ plane.
      height - The total height of the cylinder (extends halfHeight above and below center).
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      a list of entity references within the cylinder.
    • getAllEntitiesInBox

      @Nonnull public static List<Ref<EntityStore>> getAllEntitiesInBox(@Nonnull org.joml.Vector3d min, @Nonnull org.joml.Vector3d max, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch a list of all entities within an axis-aligned box, utilising the spatial resources available.
      Parameters:
      min - The minimum corner of the box (inclusive).
      max - The maximum corner of the box (inclusive).
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      a list of entity references within the box.
    • getTargetEntity

      @Nullable public static Ref<EntityStore> getTargetEntity(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch the nearest entity in view of the given entity reference. Uses the default ENTITY_TARGET_RADIUS of 8 blocks.
      Parameters:
      ref - The entity reference of the viewer entity.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      The nearest entity reference in view, or null if none found.
    • getTargetEntity

      @Nullable public static Ref<EntityStore> getTargetEntity(@Nonnull Ref<EntityStore> ref, float radius, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch the nearest entity in view of the given entity reference.
      Parameters:
      ref - The entity reference of the viewer entity.
      radius - The radius, in blocks, in which to search for entities.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      The nearest entity reference in view, or null if none found.
    • getTargetEntity

      @Nullable public static Ref<EntityStore> getTargetEntity(@Nonnull Ref<EntityStore> ref, float radius, boolean includeItemDrops, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to fetch the nearest entity in view of the given entity reference.
      Parameters:
      ref - The entity reference of the viewer entity.
      radius - The radius, in blocks, in which to search for entities.
      includeItemDrops - Whether dropped item entities may be targeted. Item drops are intangible and indexed separately, so the entity search never sees them unless they are requested here.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
      Returns:
      The nearest entity reference in view, or null if none found.
    • getLook

      @Nonnull public static Transform getLook(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Creates a new Transform instance based on the transform and head rotation/height of the provided entity.
      Parameters:
      ref - The entity reference of the entity that we are creating a transform for.
      componentAccessor - The ComponentAccessor for component access.
      Returns:
      the newly created Transform instance.