Skip to main content
The MinecraftUtils interface provides a collection of commonly-needed Minecraft utility functions, eliminating the need to copy and paste these functions into your mods.

Accessing MinecraftUtils

import gg.essential.api.EssentialAPI

val minecraftUtils = EssentialAPI.getMinecraftUtils()

Chat Messaging

sendMessage

// Simple message with [Essential] prefix
minecraftUtils.sendMessage("Hello, world!")

// Custom prefix message
minecraftUtils.sendMessage("[MyMod]", "Custom message")
Parameters:
  • message: String - The message to display in chat
  • prefix: String - Custom prefix for the message (optional)
Note: The single-parameter version prefixes messages with [Essential] and should only be used for Essential-specific information. For general messages, use UTextComponent or the two-parameter version.

sendChatMessageAndFormat

// Format with I18n
minecraftUtils.sendChatMessageAndFormat("mymod.message.key")

// Format with parameters
minecraftUtils.sendChatMessageAndFormat(
    "mymod.welcome.message",
    "PlayerName",
    42
)
Queues a message to be displayed in chat, translated and formatted using Minecraft’s I18n system. Parameters:
  • message: String - Message key or text to format
  • parameters: vararg Any - Optional formatting parameters

Server Detection

isHypixel

if (minecraftUtils.isHypixel()) {
    println("Currently on Hypixel!")
}
Returns: Boolean - true if the player is currently connected to the Hypixel server

Resource Loading

getResourceImage

import net.minecraft.util.ResourceLocation
import java.awt.image.BufferedImage

val location = ResourceLocation("mymod", "textures/custom.png")
val image: BufferedImage? = minecraftUtils.getResourceImage(location)

if (image != null) {
    // Use the image, potentially in a DynamicTexture
    val width = image.width
    val height = image.height
}
Loads a resource location into memory as a BufferedImage, useful for creating dynamic textures. Parameters:
  • location: ResourceLocation - The resource to load
Returns: BufferedImage? - The loaded image, or null if loading failed

Development Environment Detection

isDevelopment

if (minecraftUtils.isDevelopment()) {
    println("Running in development environment")
    // Enable debug features, logging, etc.
} else {
    println("Running in production")
}
Returns: Boolean - true if the game is running in a development environment rather than production

Method Reference

interface MinecraftUtils {
    fun sendMessage(message: String)
    fun sendMessage(prefix: String, message: String)
    fun sendChatMessageAndFormat(message: String)
    fun sendChatMessageAndFormat(message: String, vararg parameters: Any)
    fun isHypixel(): Boolean
    fun getResourceImage(location: ResourceLocation): BufferedImage?
    fun isDevelopment(): Boolean
}

Common Use Cases

Displaying Formatted Chat Messages

val utils = EssentialAPI.getMinecraftUtils()

// Display a simple notification
utils.sendMessage("[MyMod]", "Feature enabled!")

// Display a formatted, localized message
utils.sendChatMessageAndFormat(
    "mymod.player.joined",
    playerName,
    playerCount
)

Server-Specific Features

fun onJoinServer() {
    val utils = EssentialAPI.getMinecraftUtils()
    
    if (utils.isHypixel()) {
        // Enable Hypixel-specific features
        enableHypixelStats()
        utils.sendMessage("[MyMod]", "Hypixel features enabled!")
    }
}

Loading Custom Textures

import net.minecraft.client.renderer.texture.DynamicTexture

fun loadCustomTexture() {
    val utils = EssentialAPI.getMinecraftUtils()
    val resourceLocation = ResourceLocation("mymod", "textures/overlay.png")
    
    val image = utils.getResourceImage(resourceLocation)
    if (image != null) {
        val dynamicTexture = DynamicTexture(image)
        // Use the dynamic texture in rendering
    } else {
        println("Failed to load texture")
    }
}

Build docs developers (and LLMs) love