Class Ukutils

java.lang.Object
net.uku3lig.ukulib.utils.Ukutils

public class Ukutils extends Object
Simple class for various utilities.
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.minecraft.client.gui.components.Button
    doneButton(int width, int height, net.minecraft.client.gui.screens.Screen parent)
    Creates a done button.
    static Path
    Creates a config path for a file name.
    static @Nullable net.minecraft.resources.Identifier
    getHeadTex(String username)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Originally meant for internal use, you should look at PlayerFaceRenderer instead which is more robust and actually tested by mojang
    static Map<net.minecraft.client.KeyMapping,Consumer<net.minecraft.client.Minecraft>>
    The map of keybindings and their respective actions.
    static net.minecraft.network.chat.MutableComponent
    getStyledText(net.minecraft.util.FormattedCharSequence text)
    Retrieves the styled text from a formatted char sequence.
    static String
    getText(net.minecraft.util.FormattedCharSequence text)
    Retrieves the string text from a formatted char sequence.
    static org.joml.Vector2ic
    getTextCoords(net.minecraft.network.chat.Component text, int screenWidth, net.minecraft.client.gui.Font textRenderer, int x, int y)
    Makes text coordinates based on the position of a standard 16x16 icon.
    static org.joml.Vector2ic
    getTextCoords(net.minecraft.network.chat.Component text, int screenWidth, net.minecraft.client.gui.Font textRenderer, int x, int y, int width, int height)
    Makes text coordinates based on the position of an icon.
    static void
    registerKeybinding(net.minecraft.client.KeyMapping keyBinding, Consumer<net.minecraft.client.Minecraft> action)
    Register a keybinding.
    static void
    registerToggleBind(net.minecraft.client.KeyMapping keyBinding, BooleanSupplier getter, it.unimi.dsi.fastutil.booleans.BooleanConsumer setter, net.minecraft.network.chat.Component message)
    Register a keybinding for a boolean option that can be toggled.
    static void
    sendToast(net.minecraft.network.chat.Component title, @Nullable net.minecraft.network.chat.Component body)
    Displays a simple toast message.
    static boolean
    textureExists(net.minecraft.resources.Identifier texture)
    Checks if a texture exists and is registered.

    Methods inherited from class java.lang.Object

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

    • doneButton

      public static net.minecraft.client.gui.components.Button doneButton(int width, int height, net.minecraft.client.gui.screens.Screen parent)
      Creates a done button.
      Parameters:
      width - The width of the screen
      height - The height of the screen
      parent - The parent screen
      Returns:
      The generated button
    • getTextCoords

      public static org.joml.Vector2ic getTextCoords(net.minecraft.network.chat.Component text, int screenWidth, net.minecraft.client.gui.Font 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 drawn
      screenWidth - The width of the screen
      textRenderer - The text renderer
      x - The x coordinate of the icon
      y - The y coordinate of the icon
      width - The width of the icon
      height - The height of the icon
      Returns:
      The tuple of coordinates
    • getTextCoords

      public static org.joml.Vector2ic getTextCoords(net.minecraft.network.chat.Component text, int screenWidth, net.minecraft.client.gui.Font textRenderer, int x, int y)
      Makes text coordinates based on the position of a standard 16x16 icon.
      Parameters:
      text - The text to be drawn
      screenWidth - The width of the screen
      textRenderer - The text renderer
      x - The x coordinate of the icon
      y - The y coordinate of the icon
      Returns:
      The tuple of coordinates
      See Also:
    • getText

      public static String getText(net.minecraft.util.FormattedCharSequence text)
      Retrieves the string text from a formatted char sequence.
      Parameters:
      text - The ordered text
      Returns:
      The value of the text
    • getStyledText

      public static net.minecraft.network.chat.MutableComponent getStyledText(net.minecraft.util.FormattedCharSequence text)
      Retrieves the styled text from a formatted char sequence.
      Parameters:
      text - The ordered text
      Returns:
      The styled text
    • getConfigPath

      public static Path getConfigPath(String name)
      Creates a config path for a file name.
      Parameters:
      name - The name of the file
      Returns:
      The path to the file
    • sendToast

      public static void sendToast(net.minecraft.network.chat.Component title, @Nullable @Nullable net.minecraft.network.chat.Component body)
      Displays a simple toast message.
      Parameters:
      title - The title of the message
      body - The body of the message
    • textureExists

      @Contract("null -> false") public static boolean textureExists(net.minecraft.resources.Identifier texture)
      Checks if a texture exists and is registered.
      Parameters:
      texture - The texture to check
      Returns:
      Whether the texture exists
    • getHeadTex

      @Nullable @Deprecated(since="1.10.0", forRemoval=true) public static @Nullable net.minecraft.resources.Identifier getHeadTex(String username)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Originally meant for internal use, you should look at PlayerFaceRenderer instead which is more robust and actually tested by mojang
      Gets the texture of a player's head.
      Parameters:
      username - The username of the player
      Returns:
      The texture of the player's head
    • registerKeybinding

      public static void registerKeybinding(net.minecraft.client.KeyMapping keyBinding, Consumer<net.minecraft.client.Minecraft> action)
      Register a keybinding.
      Parameters:
      keyBinding - The keybinding
      action - The action to be performed when the key is pressed
    • registerToggleBind

      public static void registerToggleBind(net.minecraft.client.KeyMapping keyBinding, BooleanSupplier getter, it.unimi.dsi.fastutil.booleans.BooleanConsumer setter, net.minecraft.network.chat.Component message)
      Register a keybinding for a boolean option that can be toggled. Warning: for the consumer, make sure NOT to use method reference if you're using ukulib's config; do something like b -> manager.getConfig().setValue(b) instead.
      Parameters:
      keyBinding - The keybinding
      getter - The boolean value getter
      setter - The boolean value setter
      message - The message to be displayed to the player when the key is pressed. The new state (ON or OFF) will be appended to this message.
    • getKeybindings

      public static Map<net.minecraft.client.KeyMapping,Consumer<net.minecraft.client.Minecraft>> getKeybindings()
      The map of keybindings and their respective actions.
      Returns:
      The map.