Class ScreenVector

java.lang.Object
com.pixelmonmod.api.client.screen.util.ScreenVector
All Implemented Interfaces:
net.minecraft.core.Position
Direct Known Subclasses:
ScreenVector.Immutable

public class ScreenVector extends Object implements net.minecraft.core.Position
Vector of doubles implementing Position, with methods and utilities designed specifically for screen use cases, in particular that of StatefulScreen and StatefulWidget. By default, this class is mutable. Has a subclass, ScreenVector.Immutable, for immutable vectors. Immutability can be switched by calling immutable() and mutable().
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Immutable version of ScreenVector.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ScreenVector(double x, double y)
    Constructs a new mutable vector with the given values, and the z value set to 0.
    ScreenVector(double x, double y, double z)
    Constructs a new mutable vector with the given values.
    ScreenVector(net.minecraft.core.Position position)
    Constructs a new mutable vector with values copied from an existing Position.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(double x, double y)
    Adds to the x and y values of this vector.
    add(double x, double y, double z)
    Adds to the values of this vector.
    add(net.minecraft.core.Position position)
    Adds the values of a given vector to this vector's values.
    double[]
    axes(Axis... axes)
    Gets an array of values, of values of the vector for given axes.
    double
    axis(Axis axis)
    Gets the value of this vector for a given axis.
    double
    chebyshev(net.minecraft.core.Position position)
    Calculates the Chebyshev distance (chessboard distance) between this vector and a given vector, on all axes.
    double
    chebyshev(net.minecraft.core.Position position, Axis... axes)
    Calculates the Chebyshev distance (chessboard distance) between this vector and a given vector, on the given axes.
    Copies the values of this vector into a new mutable vector.
    delta(net.minecraft.core.Position position)
    Sets this vector to the delta/difference between it and the given vector.
    boolean
     
    double
    euclidean(net.minecraft.core.Position position)
    Calculates the Euclidean distance (as the crow flies) between this vector and a given vector, on all axes.
    double
    euclidean(net.minecraft.core.Position position, Axis... axes)
    Calculates the Euclidean distance (as the crow flies) between this vector and a given vector, on the given axes.
    int
     
    Creates a new immutable vector with values copied from this vector.
    Maps this vector to a given screen's dimensions, based on that screen's bounds.
    map(Bounds bounds, double width, double height)
    Maps this vector to the given dimensions, based on the given bounds.
    double
    max()
    Gets the largest value of this vector.
    maximize(net.minecraft.core.Position position)
    Sets this vector to the maximum values of this vector and the given vector.
    double
    min()
    Gets the smallest value of this vector.
    minimize(net.minecraft.core.Position position)
    Sets this vector to the minimum values of this vector and the given vector.
    mul(double mx, double my)
    Multiplies the x and y values of this vector by the given values.
    mul(double mx, double my, double mz)
    Multiplies the values of this vector by the given values.
    mul(Axis axis)
    Multiplies the values of this vector by a given axis.
    mul(net.minecraft.core.Position position)
    Multiplies the values of this vector by a given vector.
    Creates a new mutable vector with values copied from this vector.
    normalize(Bounds bounds)
    Normalize this vector between 0 and 1 based on the given Bounds.
    set(double x, double y)
    Sets the x and y values of this vector to the given values.
    set(double x, double y, double z)
    Sets the values of this vector to the given values.
    Squares the values of this vector.
    take(double x, double y)
    Takes from the x and y values of this vector.
    take(double x, double y, double z)
    Takes from the values of this vector.
    take(net.minecraft.core.Position position)
    Takes the values of a given vector from this vector's values.
    double
    taxicab(net.minecraft.core.Position position)
    Calculates the taxicab distance (Manhattan distance) between this vector and a given vector, on all axes.
    double
    taxicab(net.minecraft.core.Position position, Axis... axes)
    Calculates the taxicab distance (Manhattan distance) between this vector and a given vector, on the given axes.
     
    void
    translate(net.minecraft.client.gui.GuiGraphics graphics)
    Applies this vector as a translation on a given matrix stack.
    double
    x()
    Gets the x value of this vector.
    float
    xF()
    Gets the x value of this vector, cast to a float.
    int
    xI()
    Gets the x value of this vector, cast to an integer.
    double
    y()
    Gets the y value of this vector.
    float
    yF()
    Gets the y value of this vector, cast to a float.
    int
    yI()
    Gets the y value of this vector, cast to an integer.
    double
    z()
    Gets the z value of this vector.
    Constructs a new zeroed mutable vector.
    float
    zF()
    Gets the z value of this vector, cast to a float.
    int
    zI()
    Gets the z value of this vector, cast to an integer.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ScreenVector

      public ScreenVector(double x, double y)
      Constructs a new mutable vector with the given values, and the z value set to 0.
      Parameters:
      x - X value of the new vector.
      y - Y value of the new vector.
    • ScreenVector

      public ScreenVector(net.minecraft.core.Position position)
      Constructs a new mutable vector with values copied from an existing Position.
      Parameters:
      position - The Position to copy values from for the new vector.
    • ScreenVector

      public ScreenVector(double x, double y, double z)
      Constructs a new mutable vector with the given values.
      Parameters:
      x - X value of the new vector.
      y - Y value of the new vector.
      z - Z value of the new vector.
  • Method Details

    • zero

      public static ScreenVector zero()
      Constructs a new zeroed mutable vector.
      Returns:
      A new zeroed mutable vector.
    • copy

      public ScreenVector copy()
      Copies the values of this vector into a new mutable vector.
      Returns:
      A copy of this vector.
    • immutable

      public ScreenVector immutable()
      Creates a new immutable vector with values copied from this vector.
      Returns:
      A new immutable vector with values copied from this vector.
    • mutable

      public ScreenVector mutable()
      Creates a new mutable vector with values copied from this vector.
      Returns:
      A new mutable vector with values copied from this vector.
    • translate

      public void translate(net.minecraft.client.gui.GuiGraphics graphics)
      Applies this vector as a translation on a given matrix stack.
      Parameters:
      graphics - The graphics instance to transform.
    • x

      public double x()
      Gets the x value of this vector.
      Specified by:
      x in interface net.minecraft.core.Position
      Returns:
      The x value of this vector.
    • y

      public double y()
      Gets the y value of this vector.
      Specified by:
      y in interface net.minecraft.core.Position
      Returns:
      The y value of this vector.
    • z

      public double z()
      Gets the z value of this vector.
      Specified by:
      z in interface net.minecraft.core.Position
      Returns:
      The z value of this vector.
    • xF

      public float xF()
      Gets the x value of this vector, cast to a float.
      Returns:
      The x value of this vector as a float.
    • yF

      public float yF()
      Gets the y value of this vector, cast to a float.
      Returns:
      The y value of this vector as a float.
    • zF

      public float zF()
      Gets the z value of this vector, cast to a float.
      Returns:
      The z value of this vector as a float.
    • xI

      public int xI()
      Gets the x value of this vector, cast to an integer.
      Returns:
      The x value of this vector as an integer.
    • yI

      public int yI()
      Gets the y value of this vector, cast to an integer.
      Returns:
      The y value of this vector as an integer.
    • zI

      public int zI()
      Gets the z value of this vector, cast to an integer.
      Returns:
      The z value of this vector as an integer.
    • min

      public double min()
      Gets the smallest value of this vector.
      Returns:
      The smallest value of this vector.
    • max

      public double max()
      Gets the largest value of this vector.
      Returns:
      The largest value of this vector.
    • axis

      public double axis(Axis axis)
      Gets the value of this vector for a given axis.
      Parameters:
      axis - The axis to get the value of.
      Returns:
      The value of the given axis of this vector.
    • axes

      public double[] axes(Axis... axes)
      Gets an array of values, of values of the vector for given axes.
      Parameters:
      axes - The axes to get the values of.
      Returns:
      The values of the given axes of this vector.
    • add

      public ScreenVector add(net.minecraft.core.Position position)
      Adds the values of a given vector to this vector's values. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      position - The vector to add to this vector's values.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • add

      public ScreenVector add(double x, double y)
      Adds to the x and y values of this vector. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      x - The amount to add to the x value.
      y - The amount to add to the y value.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • add

      public ScreenVector add(double x, double y, double z)
      Adds to the values of this vector. This will mutate this vector, and then return itself.
      Parameters:
      x - The amount to add to the x value.
      y - The amount to add to the y value.
      z - The amount to add to the z value.
      Returns:
      This vector.
    • take

      public ScreenVector take(net.minecraft.core.Position position)
      Takes the values of a given vector from this vector's values. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      position - The vector to take from this vector's values.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • take

      public ScreenVector take(double x, double y)
      Takes from the x and y values of this vector. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      x - The amount to take from the x value.
      y - The amount to take from the y value.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • take

      public ScreenVector take(double x, double y, double z)
      Takes from the values of this vector. This will mutate this vector, and then return itself.
      Parameters:
      x - The amount to take from the x value.
      y - The amount to take from the y value.
      z - The amount to take from the z value.
      Returns:
      This vector.
    • mul

      public ScreenVector mul(Axis axis)
      Multiplies the values of this vector by a given axis. Effectively, this will always zero two of the values of this vector, leaving one single value. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      axis - The axis to multiply the values by.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • square

      public ScreenVector square()
      Squares the values of this vector. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • mul

      public ScreenVector mul(net.minecraft.core.Position position)
      Multiplies the values of this vector by a given vector. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      position - The vector to multiply the values by.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • mul

      public ScreenVector mul(double mx, double my)
      Multiplies the x and y values of this vector by the given values. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      mx - The x value multiplier.
      my - The y value multiplier.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • mul

      public ScreenVector mul(double mx, double my, double mz)
      Multiplies the values of this vector by the given values. This will mutate this vector, and then return itself.
      Parameters:
      mx - The x value multiplier.
      my - The y value multiplier.
      mz - the z value multiplier.
      Returns:
      This vector.
    • set

      public ScreenVector set(double x, double y)
      Sets the x and y values of this vector to the given values. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      x - The new x value.
      y - The new y value.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • set

      public ScreenVector set(double x, double y, double z)
      Sets the values of this vector to the given values. This will mutate this vector, and then return itself.
      Parameters:
      x - The new x value.
      y - The new y value.
      z - The new z value.
      Returns:
      This vector.
    • normalize

      public ScreenVector normalize(Bounds bounds)
      Normalize this vector between 0 and 1 based on the given Bounds. This will mutate this vector, and then return itself.
      Parameters:
      bounds - The bounds containing the min/max values to normalize on.
      Returns:
      This vector.
    • map

      public ScreenVector map(StatefulScreen screen)
      Maps this vector to a given screen's dimensions, based on that screen's bounds. First, this vector will be normalized, then multiplied by the screen's dimensions. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      screen - The StatefulScreen to map this vector to.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • map

      public ScreenVector map(Bounds bounds, double width, double height)
      Maps this vector to the given dimensions, based on the given bounds. First, this vector will be normalized, then multiplied by the given dimensions. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      bounds - The bounds to use in normalization.
      width - The width to map this vector to.
      height - The height to map this vector to.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • delta

      public ScreenVector delta(net.minecraft.core.Position position)
      Sets this vector to the delta/difference between it and the given vector. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      position - The vector to get delta of between this vector.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • minimize

      public ScreenVector minimize(net.minecraft.core.Position position)
      Sets this vector to the minimum values of this vector and the given vector. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      position - The vector to compare values with.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • maximize

      public ScreenVector maximize(net.minecraft.core.Position position)
      Sets this vector to the maximum values of this vector and the given vector. This will mutate this vector, and then return itself, unless this is a ScreenVector.Immutable, in which case a new vector will be returned instead.
      Parameters:
      position - The vector to compare values with.
      Returns:
      This vector, or the new vector, depending on what class this vector is.
    • euclidean

      public double euclidean(net.minecraft.core.Position position)
      Calculates the Euclidean distance (as the crow flies) between this vector and a given vector, on all axes. See: Euclidean distance
      Parameters:
      position - The position to get the distance to.
      Returns:
      The calculated Euclidean distance.
    • euclidean

      public double euclidean(net.minecraft.core.Position position, Axis... axes)
      Calculates the Euclidean distance (as the crow flies) between this vector and a given vector, on the given axes. See: Euclidean distance
      Parameters:
      position - The position to get the distance to.
      axes - The axes to consider in calculating the distance.
      Returns:
      The calculated Euclidean distance.
    • taxicab

      public double taxicab(net.minecraft.core.Position position)
      Calculates the taxicab distance (Manhattan distance) between this vector and a given vector, on all axes. See: Taxicab geometry
      Parameters:
      position - The position to get the distance to.
      Returns:
      The calculated taxicab distance.
    • taxicab

      public double taxicab(net.minecraft.core.Position position, Axis... axes)
      Calculates the taxicab distance (Manhattan distance) between this vector and a given vector, on the given axes. See: Taxicab geometry
      Parameters:
      position - The position to get the distance to.
      axes - The axes to consider in calculating the distance.
      Returns:
      The calculated taxicab distance.
    • chebyshev

      public double chebyshev(net.minecraft.core.Position position)
      Calculates the Chebyshev distance (chessboard distance) between this vector and a given vector, on all axes. See: Chebyshev distance
      Parameters:
      position - The position to get the distance to.
      Returns:
      The calculated Chebyshev distance.
    • chebyshev

      public double chebyshev(net.minecraft.core.Position position, Axis... axes)
      Calculates the Chebyshev distance (chessboard distance) between this vector and a given vector, on the given axes. See: Chebyshev distance
      Parameters:
      position - The position to get the distance to.
      axes - The axes to consider in calculating the distance.
      Returns:
      The calculated Chebyshev distance.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object