Appearance
Java API
The java global table allows interacting directly with Java classes and objects from your scripts.
NOTE
When interacting with Minecraft internals, all classes, methods, and fields use Mojang mappings. This means you must use the official, unobfuscated names as they appear in the Minecraft source code.
Core Functions
java.import(class_name)
Loads a Java class by its full package name. Returns a Lua representation of the class.
lua
local Math = java.import("java.lang.Math")
print(Math:abs(-1))java.new(class_obj, ...)
Creates a new instance of a Java class using its class object.
lua
local ArrayList = java.import("java.util.ArrayList")
local list = java.new(ArrayList)
list:add("Hello")java.newInstance(class_name, ...)
Creates a new instance of a Java class using its full class name.
lua
local list = java.newInstance("java.util.ArrayList")
list:add("World")java.proxy(interface_name, table)
Creates a Java proxy for an interface, using a Lua table for method implementations.
lua
local my_runnable = java.proxy("java.lang.Runnable", {
run = function()
print("Running in Java thread!")
end
})Utility Functions
is_instance(obj, class_or_name)
Checks if a Java object is an instance of a specific class or class name.
lua
local Player = java.import("net.minecraft.world.entity.player.Player")
if is_instance(entity, Player) then
print("This is a player!")
end
if is_instance(entity, "java.lang.String") then
print("This is a string!")
end