Class Units

java.lang.Object
mindustry.entities.Units

public class Units extends Object
Utility class for unit and team interactions.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    any(float x, float y, float width, float height, Boolf<mindustry.gen.Unit> filter)
     
    static boolean
    anyEntities(float x, float y, float size)
     
    static boolean
    anyEntities(float x, float y, float width, float height)
     
    static boolean
    anyEntities(float x, float y, float width, float height, boolean ground)
     
    static boolean
    anyEntities(float x, float y, float width, float height, Boolf<mindustry.gen.Unit> check)
     
    static boolean
    Returns whether there are any entities on this tile.
    static boolean
    anyEntities(Tile tile, boolean ground)
    Returns whether there are any entities on this tile.
    static mindustry.gen.Unit
    bestEnemy(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> predicate, Units.Sortf sort)
    Returns the closest enemy of this team using a custom comparison function.
    static mindustry.gen.Teamc
    bestTarget(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> unitPred, Boolf<mindustry.gen.Building> tilePred, Units.Sortf sort)
    Returns the closest target enemy.
    static boolean
    canCreate(Team team, UnitType type)
     
    static boolean
    canInteract(mindustry.gen.Player player, mindustry.gen.Building tile)
     
    static mindustry.gen.Unit
    closest(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> predicate)
    Returns the closest ally of this team in a range.
    static mindustry.gen.Unit
    closest(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> predicate, Units.Sortf sort)
    Returns the closest ally of this team in a range.
    static mindustry.gen.Unit
    closest(Team team, float x, float y, Boolf<mindustry.gen.Unit> predicate)
    Returns the closest ally of this team.
    static mindustry.gen.Building
    closestBuilding(Team team, float wx, float wy, float range, Boolf<mindustry.gen.Building> pred)
     
    static mindustry.gen.Unit
    closestEnemy(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> predicate)
    Returns the closest enemy of this team.
    static mindustry.gen.Unit
    closestOverlap(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> predicate)
    Returns the closest ally of this team.
    static mindustry.gen.Teamc
    closestTarget(Team team, float x, float y, float range)
    Returns the closest target enemy.
    static mindustry.gen.Teamc
    closestTarget(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> unitPred)
    Returns the closest target enemy.
    static mindustry.gen.Teamc
    closestTarget(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> unitPred, Boolf<mindustry.gen.Building> tilePred)
    Returns the closest target enemy.
    static int
    count(float x, float y, float width, float height, Boolf<mindustry.gen.Unit> filter)
     
    static int
    count(float x, float y, float size, Boolf<mindustry.gen.Unit> filter)
     
    static mindustry.gen.Building
    findAllyTile(Team team, float x, float y, float range, Boolf<mindustry.gen.Building> pred)
    Returns the nearest ally tile in a range.
    static mindustry.gen.Building
    findDamagedTile(Team team, float x, float y)
    Returns the nearest damaged tile.
    static mindustry.gen.Building
    findEnemyTile(Team team, float x, float y, float range, Boolf<mindustry.gen.Building> pred)
    Returns the nearest enemy tile in a range.
    static int
    getCap(Team team)
     
    static String
     
    static boolean
    invalidateTarget(mindustry.gen.Posc target, Team team, float x, float y)
    static boolean
    invalidateTarget(mindustry.gen.Posc target, Team team, float x, float y, float range)
    Validates a target.
    static boolean
    invalidateTarget(mindustry.gen.Teamc target, mindustry.gen.Unit targeter, float range)
    static void
    nearby(float x, float y, float width, float height, Cons<mindustry.gen.Unit> cons)
    Iterates over all units in a rectangle.
    static void
    nearby(Rect rect, Cons<mindustry.gen.Unit> cons)
    Iterates over all units in a rectangle.
    static void
    nearby(Team team, float x, float y, float width, float height, Cons<mindustry.gen.Unit> cons)
    Iterates over all units in a rectangle.
    static void
    nearby(Team team, float x, float y, float radius, Cons<mindustry.gen.Unit> cons)
    Iterates over all units in a circle around this position.
    static void
    nearbyBuildings(float x, float y, float range, Cons<mindustry.gen.Building> cons)
    Iterates through all buildings in a range.
    static void
    nearbyEnemies(Team team, float x, float y, float width, float height, Cons<mindustry.gen.Unit> cons)
    Iterates over all units that are enemies of this team.
    static void
    nearbyEnemies(Team team, float x, float y, float radius, Cons<mindustry.gen.Unit> cons)
    Iterates over all units that are enemies of this team.
    static void
    nearbyEnemies(Team team, Rect rect, Cons<mindustry.gen.Unit> cons)
    Iterates over all units that are enemies of this team.
    static boolean
    nearEnemy(Team team, float x, float y, float width, float height)
     
    static void
    unitCapDeath(mindustry.gen.Unit unit)
     
    static void
    unitDeath(int uid)
     
    static void
    unitDespawn(mindustry.gen.Unit unit)
     
    static void
    unitDestroy(int uid)
     
    static void
    unitEnvDeath(mindustry.gen.Unit unit)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Units

      public Units()
  • Method Details

    • unitCapDeath

      public static void unitCapDeath(mindustry.gen.Unit unit)
    • unitEnvDeath

      public static void unitEnvDeath(mindustry.gen.Unit unit)
    • unitDeath

      public static void unitDeath(int uid)
    • unitDestroy

      public static void unitDestroy(int uid)
    • unitDespawn

      public static void unitDespawn(mindustry.gen.Unit unit)
    • canCreate

      public static boolean canCreate(Team team, UnitType type)
      Returns:
      whether a new instance of a unit of this team can be created.
    • getCap

      public static int getCap(Team team)
    • getStringCap

      public static String getStringCap(Team team)
      Returns:
      unit cap as a string, substituting the infinity symbol instead of MAX_VALUE
    • canInteract

      public static boolean canInteract(mindustry.gen.Player player, mindustry.gen.Building tile)
      Returns:
      whether this player can interact with a specific tile. if either of these are null, returns true.
    • invalidateTarget

      public static boolean invalidateTarget(mindustry.gen.Posc target, Team team, float x, float y, float range)
      Validates a target.
      Parameters:
      target - The target to validate
      team - The team of the thing doing tha targeting
      x - The X position of the thing doing the targeting
      y - The Y position of the thing doing the targeting
      range - The maximum distance from the target X/Y the targeter can be for it to be valid
      Returns:
      whether the target is invalid
    • invalidateTarget

      public static boolean invalidateTarget(mindustry.gen.Posc target, Team team, float x, float y)
    • invalidateTarget

      public static boolean invalidateTarget(mindustry.gen.Teamc target, mindustry.gen.Unit targeter, float range)
    • anyEntities

      public static boolean anyEntities(Tile tile, boolean ground)
      Returns whether there are any entities on this tile.
    • anyEntities

      public static boolean anyEntities(Tile tile)
      Returns whether there are any entities on this tile.
    • anyEntities

      public static boolean anyEntities(float x, float y, float size)
    • anyEntities

      public static boolean anyEntities(float x, float y, float width, float height)
    • anyEntities

      public static boolean anyEntities(float x, float y, float width, float height, boolean ground)
    • anyEntities

      public static boolean anyEntities(float x, float y, float width, float height, Boolf<mindustry.gen.Unit> check)
    • findDamagedTile

      public static mindustry.gen.Building findDamagedTile(Team team, float x, float y)
      Returns the nearest damaged tile.
    • findAllyTile

      public static mindustry.gen.Building findAllyTile(Team team, float x, float y, float range, Boolf<mindustry.gen.Building> pred)
      Returns the nearest ally tile in a range.
    • findEnemyTile

      public static mindustry.gen.Building findEnemyTile(Team team, float x, float y, float range, Boolf<mindustry.gen.Building> pred)
      Returns the nearest enemy tile in a range.
    • closestBuilding

      @Nullable public static mindustry.gen.Building closestBuilding(Team team, float wx, float wy, float range, Boolf<mindustry.gen.Building> pred)
      Returns:
      the closest building of the provided team that matches the predicate.
    • nearbyBuildings

      public static void nearbyBuildings(float x, float y, float range, Cons<mindustry.gen.Building> cons)
      Iterates through all buildings in a range.
    • closestTarget

      public static mindustry.gen.Teamc closestTarget(Team team, float x, float y, float range)
      Returns the closest target enemy. First, units are checked, then tile entities.
    • closestTarget

      public static mindustry.gen.Teamc closestTarget(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> unitPred)
      Returns the closest target enemy. First, units are checked, then tile entities.
    • closestTarget

      public static mindustry.gen.Teamc closestTarget(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> unitPred, Boolf<mindustry.gen.Building> tilePred)
      Returns the closest target enemy. First, units are checked, then tile entities.
    • bestTarget

      public static mindustry.gen.Teamc bestTarget(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> unitPred, Boolf<mindustry.gen.Building> tilePred, Units.Sortf sort)
      Returns the closest target enemy. First, units are checked, then buildings.
    • closestEnemy

      public static mindustry.gen.Unit closestEnemy(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> predicate)
      Returns the closest enemy of this team. Filter by predicate.
    • bestEnemy

      public static mindustry.gen.Unit bestEnemy(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> predicate, Units.Sortf sort)
      Returns the closest enemy of this team using a custom comparison function. Filter by predicate.
    • closest

      public static mindustry.gen.Unit closest(Team team, float x, float y, Boolf<mindustry.gen.Unit> predicate)
      Returns the closest ally of this team. Filter by predicate. No range.
    • closest

      public static mindustry.gen.Unit closest(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> predicate)
      Returns the closest ally of this team in a range. Filter by predicate.
    • closest

      public static mindustry.gen.Unit closest(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> predicate, Units.Sortf sort)
      Returns the closest ally of this team in a range. Filter by predicate.
    • closestOverlap

      public static mindustry.gen.Unit closestOverlap(Team team, float x, float y, float range, Boolf<mindustry.gen.Unit> predicate)
      Returns the closest ally of this team. Filter by predicate. Unlike the closest() function, this only guarantees that unit hitboxes overlap the range.
    • count

      public static int count(float x, float y, float size, Boolf<mindustry.gen.Unit> filter)
      Returns:
      whether any units exist in this square (centered)
    • count

      public static int count(float x, float y, float width, float height, Boolf<mindustry.gen.Unit> filter)
      Returns:
      whether any units exist in this rectangle
    • any

      public static boolean any(float x, float y, float width, float height, Boolf<mindustry.gen.Unit> filter)
      Returns:
      whether any units exist in this rectangle
    • nearby

      public static void nearby(@Nullable Team team, float x, float y, float width, float height, Cons<mindustry.gen.Unit> cons)
      Iterates over all units in a rectangle.
    • nearby

      public static void nearby(@Nullable Team team, float x, float y, float radius, Cons<mindustry.gen.Unit> cons)
      Iterates over all units in a circle around this position.
    • nearby

      public static void nearby(float x, float y, float width, float height, Cons<mindustry.gen.Unit> cons)
      Iterates over all units in a rectangle.
    • nearby

      public static void nearby(Rect rect, Cons<mindustry.gen.Unit> cons)
      Iterates over all units in a rectangle.
    • nearbyEnemies

      public static void nearbyEnemies(Team team, float x, float y, float width, float height, Cons<mindustry.gen.Unit> cons)
      Iterates over all units that are enemies of this team.
    • nearbyEnemies

      public static void nearbyEnemies(Team team, float x, float y, float radius, Cons<mindustry.gen.Unit> cons)
      Iterates over all units that are enemies of this team.
    • nearbyEnemies

      public static void nearbyEnemies(Team team, Rect rect, Cons<mindustry.gen.Unit> cons)
      Iterates over all units that are enemies of this team.
    • nearEnemy

      public static boolean nearEnemy(Team team, float x, float y, float width, float height)
      Returns:
      whether there is an enemy in this rectangle.