Package net.uku3lig.ukulib.utils
Class Ukutils
java.lang.Object
net.uku3lig.ukulib.utils.Ukutils
Simple class for various utilities.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final net.minecraft.text.TextPlaceholder for button text. -
Method Summary
Modifier and TypeMethodDescriptionstatic doublebound(double n, double min, double max) Returns the value, keeping it between two bounds.static intbound(int n, int min, int max) Returns the value, keeping it between two integer bounds.static net.minecraft.client.option.SimpleOption<Boolean>createButton(String key, Object value, Consumer<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple button.static net.minecraft.client.option.SimpleOption<Boolean>createButton(String key, Consumer<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple button.static net.minecraft.client.option.SimpleOption<Boolean>createButton(String key, net.minecraft.text.Text text, Consumer<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple button.static net.minecraft.client.option.SimpleOption<Boolean>createOpenButton(String key, Object value, UnaryOperator<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple button that opens a screen when clicked.static net.minecraft.client.option.SimpleOption<Boolean>createOpenButton(String key, UnaryOperator<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple that opens a screen when clicked.static net.minecraft.client.option.SimpleOption<Boolean>createOpenButton(String key, net.minecraft.text.Text text, UnaryOperator<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple button that opens a screen when clicked.static net.minecraft.client.gui.widget.ButtonWidgetdoneButton(int width, int height, net.minecraft.client.gui.screen.Screen parent) Creates a done button.static StringgetText(net.minecraft.text.OrderedText text) Retrieves the string text from an ordered text.static Ukutils.Tuple2<Integer,Integer> getTextCoords(net.minecraft.text.Text text, int screenWidth, net.minecraft.client.font.TextRenderer textRenderer, int x, int y) Makes text coordinates based on the position of a standard 16x16 icon.static Ukutils.Tuple2<Integer,Integer> getTextCoords(net.minecraft.text.Text text, int screenWidth, net.minecraft.client.font.TextRenderer textRenderer, int x, int y, int width, int height) Makes text coordinates based on the position of an icon.
-
Field Details
-
BUTTON_PLACEHOLDER
public static final net.minecraft.text.Text BUTTON_PLACEHOLDERPlaceholder for button text.
-
-
Method Details
-
createButton
public static net.minecraft.client.option.SimpleOption<Boolean> createButton(String key, Object value, Consumer<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple button. Equivalent tocreateButton(key, Text.of(String.valueOf(value)), callback).- Parameters:
key- The translation key of the button textvalue- The value to be displayed after the coloncallback- The action to be performed when the button is clicked- Returns:
- The generated option
- See Also:
-
createButton
public static net.minecraft.client.option.SimpleOption<Boolean> createButton(String key, Consumer<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple button.- Parameters:
key- The translation key of the button textcallback- The action to be performed when the button is clicked- Returns:
- The generated option
- See Also:
-
createButton
public static net.minecraft.client.option.SimpleOption<Boolean> createButton(String key, net.minecraft.text.Text text, Consumer<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple button.- Parameters:
key- The translation key of the button texttext- The text to be displayed after the coloncallback- The action to be performed when the button is clicked- Returns:
- The generated option
-
createOpenButton
public static net.minecraft.client.option.SimpleOption<Boolean> createOpenButton(String key, Object value, UnaryOperator<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple button that opens a screen when clicked. Equivalent tocreateOpenButton(key, Text.of(String.valueOf(value)), callback).- Parameters:
key- The translation key of the button textvalue- The value to be displayed after the coloncallback- The getter for the screen to be opened when the button is clicked- Returns:
- The generated option
- See Also:
-
createOpenButton
public static net.minecraft.client.option.SimpleOption<Boolean> createOpenButton(String key, UnaryOperator<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple that opens a screen when clicked.- Parameters:
key- The translation key of the button textcallback- The getter for the screen to be opened when the button is clicked- Returns:
- The generated option
- See Also:
-
createOpenButton
public static net.minecraft.client.option.SimpleOption<Boolean> createOpenButton(String key, net.minecraft.text.Text text, UnaryOperator<net.minecraft.client.gui.screen.Screen> callback) Creates aSimpleOptionwhich acts as a simple button that opens a screen when clicked.- Parameters:
key- The translation key of the button texttext- The text to be displayed after the coloncallback- The getter for the screen to be opened when the button is clicked- Returns:
- The generated option
-
doneButton
public static net.minecraft.client.gui.widget.ButtonWidget doneButton(int width, int height, net.minecraft.client.gui.screen.Screen parent) Creates a done button.- Parameters:
width- The width of the screenheight- The height of the screenparent- The parent screen- Returns:
- The generated button
-
getTextCoords
public static Ukutils.Tuple2<Integer,Integer> getTextCoords(net.minecraft.text.Text text, int screenWidth, net.minecraft.client.font.TextRenderer textRenderer, int x, int y, int width, int height) Makes text coordinates based on the position of an icon.- Parameters:
text- The text to be drawnscreenWidth- The width of the screentextRenderer- The text rendererx- The x coordinate of the icony- The y coordinate of the iconwidth- The width of the iconheight- The height of the icon- Returns:
- The tuple of coordinates
-
getTextCoords
public static Ukutils.Tuple2<Integer,Integer> getTextCoords(net.minecraft.text.Text text, int screenWidth, net.minecraft.client.font.TextRenderer textRenderer, int x, int y) Makes text coordinates based on the position of a standard 16x16 icon.- Parameters:
text- The text to be drawnscreenWidth- The width of the screentextRenderer- The text rendererx- The x coordinate of the icony- The y coordinate of the icon- Returns:
- The tuple of coordinates
- See Also:
-
bound
public static double bound(double n, double min, double max) Returns the value, keeping it between two bounds.- Parameters:
n- The valuemin- The bottom boundmax- The top bound- Returns:
- The bounded value
-
bound
public static int bound(int n, int min, int max) Returns the value, keeping it between two integer bounds.- Parameters:
n- The valuemin- The bottom boundmax- The top bound- Returns:
- The bounded value
-
getText
Retrieves the string text from an ordered text.- Parameters:
text- The ordered text- Returns:
- The value of the text
-