Class ScreenVector
java.lang.Object
com.pixelmonmod.api.client.screen.util.ScreenVector
- All Implemented Interfaces:
net.minecraft.core.Position
- Direct Known Subclasses:
ScreenVector.Immutable
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
-
Constructor Summary
ConstructorDescriptionScreenVector
(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 existingPosition
. -
Method Summary
Modifier and TypeMethodDescriptionadd
(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[]
Gets an array of values, of values of the vector for given axes.double
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
Calculates the Chebyshev distance (chessboard distance) between this vector and a given vector, on the given axes.copy()
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
Calculates the Euclidean distance (as the crow flies) between this vector and a given vector, on the given axes.int
hashCode()
Creates a new immutable vector with values copied from this vector.map
(StatefulScreen screen) Maps this vector to a given screen's dimensions, based on that screen's bounds.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.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.mutable()
Creates a new mutable vector with values copied from this vector.Normalize this vector between 0 and 1 based on the givenBounds
.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.square()
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
Calculates the taxicab distance (Manhattan distance) between this vector and a given vector, on the given axes.toString()
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.static ScreenVector
zero()
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.
-
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 existingPosition
.- Parameters:
position
- ThePosition
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
Constructs a new zeroed mutable vector.- Returns:
- A new zeroed mutable vector.
-
copy
Copies the values of this vector into a new mutable vector.- Returns:
- A copy of this vector.
-
immutable
Creates a new immutable vector with values copied from this vector.- Returns:
- A new immutable vector with values copied from this vector.
-
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 interfacenet.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 interfacenet.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 interfacenet.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
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
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
Adds the values of a given vector to this vector's values. This will mutate this vector, and then return itself, unless this is aScreenVector.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
Adds to the x and y values of this vector. This will mutate this vector, and then return itself, unless this is aScreenVector.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
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
Takes the values of a given vector from this vector's values. This will mutate this vector, and then return itself, unless this is aScreenVector.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
Takes from the x and y values of this vector. This will mutate this vector, and then return itself, unless this is aScreenVector.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
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
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 aScreenVector.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
Squares the values of this vector. This will mutate this vector, and then return itself, unless this is aScreenVector.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
Multiplies the values of this vector by a given vector. This will mutate this vector, and then return itself, unless this is aScreenVector.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
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 aScreenVector.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
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
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 aScreenVector.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
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
Normalize this vector between 0 and 1 based on the givenBounds
. 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
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 aScreenVector.Immutable
, in which case a new vector will be returned instead.- Parameters:
screen
- TheStatefulScreen
to map this vector to.- Returns:
- This vector, or the new vector, depending on what class this vector is.
-
map
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 aScreenVector.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
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 aScreenVector.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
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 aScreenVector.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
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 aScreenVector.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
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
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
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() -
equals
-
toString
-