Class Funcs

java.lang.Object
io.github.emcw.utils.Funcs

public class Funcs extends Object
  • Constructor Details

    • Funcs

      public Funcs()
  • Method Details

    • collectAsMap

      public static <T> Map<String,T> collectAsMap(@NotNull @NotNull Stream<Map.Entry<String,T>> stream)
    • calcArea

      public static int calcArea(int[] X, int[] Z)
    • calcArea

      public static int calcArea(int[] X, int[] Z, int numPoints, int @NotNull ... divisor)
    • roundToNearest16

      public static int roundToNearest16(int value)
    • roundToNearest16

      public static int roundToNearest16(double value)
    • midrange

      public static int midrange(int[] ints)
      Applies the Midrange Formula to the input array, the result is then rounded to the nearest full integer.
      Parameters:
      ints - The input array of integers.
      Returns:
      The resulting int (rounded).
    • euclidean

      public static double euclidean(@NotNull @NotNull Point2D loc1, @NotNull @NotNull Point2D loc2)
      Calculates the distance between two instances of Point2D using Euclidean geometry. Note that the order of parameters here does not matter, the distance will be the same.

      See the underlying euclidean method for further info.
      See Also:
    • euclidean

      public static double euclidean(int x1, int x2, int z1, int z2)
      Calculates the straight-line distance between two locations, ignoring any obstacles or other factors. This allows for diagonal paths that may not be viable in reality, the result is best only in theory.

      In Minecraft, this method is preferred in many cases over Manhattan distance. You can visit here to look at examples of when to use one over the other.
      Parameters:
      x1 - The X coordinate (left/right) of the first location.
      x2 - The position on the X axis (left/right) of the second location.
      z1 - The Z coordinate (up/down) of the first location.
      z2 - The position on the Z axis (up/down) of the second location.
      Returns:
      The distance as a highly precise number.
    • manhattan

      public static int manhattan(@NotNull @NotNull Point2D loc1, @NotNull @NotNull Point2D loc2)
      Calculates the distance between two instances of Point2D using Taxi-cab geometry. See the underlying manhattan method for further info.
      See Also:
    • manhattan

      public static int manhattan(int x1, int z1, int x2, int z2)
      Calculates the Manhattan (sometimes referred to as "taxi-cab") distance between two locations, which is the sum of the absolute differences of their X and Z coordinates.

      This method only considers horizontal and vertical movements, not diagonal. This is usually the method to use when we want the result in blocks and precision is not required.
      Parameters:
      x1 - The position on the X axis (left/right) of the first location.
      z1 - The position on the Z axis (up/down) of the first location.
      x2 - The position on the X axis (left/right) of the second location.
      z2 - The position on the Z axis (up/down) of the second location.
      See Also:
    • removeListDuplicates

      public static <T> List<T> removeListDuplicates(@NotNull @NotNull List<T> list)
    • collectList

      public static <T> List<T> collectList(Stream<T> stream, Boolean unique)
    • parallelStreamArr

      @NotNull public static <T> @NotNull Stream<T> parallelStreamArr(@NotNull T[] arr)
    • strArrHas

      public static boolean strArrHas(String[] arr, @NotNull @NotNull String str)
    • withinRadius

      @Contract(pure=true) public static boolean withinRadius(int num, int[] args)
    • withinRadius

      public static boolean withinRadius(Integer sourceCoord, Integer targetCoord, Integer radius)
    • stringToFullUUID

      public static UUID stringToFullUUID(@NotNull @NotNull String uuidStr) throws IllegalArgumentException
      Ensures a UUID is full (with hyphens) by inserting them at known points in the string.

      If the given string is 36 characters (full uuid), it will use that one without inserting.
      Parameters:
      uuidStr - A trimmed or full UUID in string representation.
      Returns:
      A new UUID with hyphens inserted if not already.
      Throws:
      IllegalArgumentException