Skip to content
1924 words 10 min read

LOICollectionAPI

NOTE

The following content is taken from the LOICollectionAPI structure of LOICollectionA 1.15.0; the LOICollectionAPI structure may differ in later versions.

Default Variables

LOICollectionAPIDescriptionType
{version_mc}Current server Minecraft versionstring
{version_ll}Current server LeviLamina versionstring
{version_protocol}Current server protocol versionstring
{player}Current player namestring
{player_language}Gets the language ID used by the playerstring
{player_language_name}Gets the name of the language used by the playerstring
{player_title}Gets the title currently equipped by the playerstring
{player_title_time}Gets the remaining time the player holds the titlestring
{player_mute}Whether the player is mutedboolean
{player_pvp}Whether the player has PVP enabledboolean
{player_statistcs_onlinetime}Player online timestring
{player_statistcs_kills}Number of mobs killed by the playerint
{player_statistcs_deaths}Number of player deathsint
{player_statistcs_place}Number of blocks placed by the playerint
{player_statistcs_destroy}Number of blocks destroyed by the playerint
{player_statistcs_respawn}Number of player respawnsint
{player_statistcs_join}Number of times the player joined the serverint
{player_gamemode}Current game mode of the playerstring
{player_pos}Coordinates of the playerstring
{player_pos_x}X coordinate of the playerint
{player_pos_y}Y coordinate of the playerint
{player_pos_z}Z coordinate of the playerint
{player_pos_respawn}Respawn coordinates of the playerstring
{player_pos_respawn_x}Respawn X coordinate of the playerint / string(None)
{player_pos_respawn_y}Respawn Y coordinate of the playerint / string(None)
{player_pos_respawn_z}Respawn Z coordinate of the playerint / string(None)
{player_pos_block}Block coordinates of the playerstring
{player_pos_lastdeath}Coordinates of the player's last deathstring
{player_realname}Real name of the playerstring
{player_xuid}XUID string of the playerstring
{player_uuid}UUID string of the playerstring
{player_is_op}Whether the player is an OPboolean
{player_can_fly}Whether the player can flyboolean
{player_health}Current health of the playerint
{player_max_health}Maximum health of the playerint
{player_hunger}Current hunger value of the playerint / string(None)
{player_max_hunger}Maximum hunger value of the playerint / string(None)
{player_saturation}Current saturation of the playerint / string(None)
{player_max_saturation}Maximum saturation of the playerint / string(None)
{player_speed}Current speed of the playerfloat
{player_direction}Current facing direction of the playerstring
{player_dimension}Current dimension ID of the playerint
{player_ip}Connection IP of the playerstring
{player_exp_xp}Current experience of the playerint / string(None)
{player_exp_level}Current level of the playerint / string(None)
{player_exp_level_next}Experience required for the player's next levelint
{player_handitem}Name of the item held by the playerstring
{player_offhand}Name of the item in the player's offhandstring
{player_os}Device name of the playerstring
{player_ms}Network latency of the player (ms)int
{player_ms_avg}Average network latency of the player (ms)int
{player_packet}Network packet loss rate of the player (%)int
{player_packet_avg}Average network packet loss rate of the player (%)int
{server_tps}Gets the current server TPSfloat
{server_mspt}Gets the current server MSPTfloat
{server_time}Current timestring
{server_player_max}Maximum number of playersint
{server_player_online}Number of online playersint
{server_entity}Number of entities on the current serverint
{score(ScoreboardName)}Scoreboard score of the playerint
{tr(languageId)}Gets the translation text of the specified ID in the player's current languagestring
{tr(langcode, languageId)}Gets the translation text of the specified ID in the specified languagestring
{entity(typeid)}Gets the number of entities with the specified IDint

TIP

Due to how the parser works, any string passed should be wrapped with " or '.


Blocking Identifier - $

The blocking identifier is used to prevent variable replacement, i.e. the original variable content is kept as-is and is not parsed into other content.

text
${variable}
ParameterDescription
variableVariable name

TIP

The blocking identifier is usually placed before a variable, and the identifier is removed after the replacement is complete.

Concrete Usage Example of the Blocking Identifier

The following shows the real name of the player without parsing other content

text
{player_realname} + '->' + ${team}
  • Returned result: player -> {team}

Conditional Statement - if

The conditional statement is used to check whether a condition holds. If it holds, the content of result_yes replaces the original statement; otherwise, the content of result_no replaces the original statement

text
if (condition)[result_yes : result_no]
ParameterDescription
conditionCondition to check
result_yesContent to replace with when the condition holds
result_noContent to replace with when the condition does not hold

TIP

Nested if statements are supported in conditional statements, but it is recommended not to nest too deeply, otherwise the statement becomes hard to read

Concrete Usage Example of the Conditional Statement

The following shows the average network latency of the player in different colors

WARNING

Note that the original result of the statement cannot parse special characters, so they need to be combined into a string type

text
if({player_ms_avg} <= 50)["§a" : if( {player_ms_avg} > 50 && {player_ms_avg} <= 250)["§e" : "§c"]] + {player_ms_avg} + "§bms"
  • When the condition {player_ms_avg} <= 50 is met, it returns "§a {player_ms_avg}§bms"
  • When the condition {player_ms_avg} > 50 && {player_ms_avg} <= 250 is met, it returns "§e {player_ms_avg}§bms"
  • When none of the above conditions are met, it returns "§c {player_ms_avg}§bms"

Operators - operator

Operators are tools used in raw statements for more convenient and faster processing, including but not limited to +, -, *, /, etc.

Operator 1DescriptionOperator 2Description
+Addition-Subtraction
*Multiplication/Division
%Modulo^Power
!Logical NOT&&Logical AND
||Logical OR==Equal to
!=Not equal to>Greater than
<Less than>=Greater than or equal to
<=Less than or equal to......

Concrete Usage Example of Operators

Most of the above are self-explanatory and can be used directly, so they will not be elaborated further.
Next, some special usages will be shown.

  1. String concatenation

    text
    "Hello" + "World"
    • Returned result: "HelloWorld"
  2. String comparison

    text
    "Hello" <= "World"
    • Returned result: false

    NOTE

    The comparison rules here can roughly refer to the comparison rules of C++


Function - function

Functions are a collection of commonly used features that help us perform certain operations more conveniently.
Some built-in functions are provided below; more functions can be extended by yourself.

text
namespaces::function_name(parameter1, parameter2,...)
ParameterDescription
namespacesNamespace, used to distinguish different features
function_nameFunction name
parameter1Parameter 1
parameter2Parameter 2
......

WARNING

In a function call, the maximum number of parameters is 100; exceeding that will cause parsing to fail. For details, see the Too many args in function call error

Concrete Usage Example of Functions

The following shows calculating the maximum of cos(sqrt(100)) and sin(sqrt(100)), and taking its absolute value.

TIP

Note that function calls need to be separated with ::, and function parameters need to be separated with ,.

text
math::abs(math::max(math::cos(math::sqrt(100)), math::sin(math::sqrt(100))))
  • Returned result: 0.544021

WARNING

Every expression must be followed by the separator ;


Script Language Features (.lcui)

Since 1.15.0, the UI data of Menu and Shop has been changed to .lcui script files (see Data Files), and the built-in UIs of other modules are also written in the same scripting language. The script supports variables, arrays, strings, numbers, booleans, and none, as well as flow control such as if, while, for, break, continue, and return.

Function Definition and Anonymous Functions

Use func to define named functions; parameter and return value types can be specified (dynamic when unspecified):

lcui
func add(a: int, b: int) -> int {
    return a + b;
}

result = add(1, 2);

Anonymous functions (Lambdas) are defined with func (parameters) -> return type { ... }, and can be assigned to variables or passed directly as parameters:

lcui
double = func (x: int) -> int {
    return x * 2;
};
value = double(3);

form.button("Button", func () -> void {
    mc::runCmd("say Hello");
}, new ButtonOptions());

TIP

Did you know: the sky is blue...... although sometimes it isn't ( ̄y▽ ̄)╭

Classes and Inheritance

The scripting language supports classes, inheritance, access control, and static members:

lcui
class Animal {
public:
    name = "unknown";

    Animal(name) {
        this.name = name;
    }

    func speak() -> string {
        return "...";
    }
}

class Dog extends Animal {
    func speak() -> string {
        return "Woof";
    }
}

dog = new Dog("dog");
if (dog instanceof Animal) [
    mc::runCmd("say " + dog.speak());
]

Class-related keywords and operators:

Keyword/OperatorDescription
classDefines a class
extendsInherits a base class
newCreates an object
thisCurrent object
superCalls base class methods; super(...) calls the base class constructor
instanceofChecks whether an object is an instance of the specified class
public: / private:Access control section
staticStatic member or static method
using Alias = Type;Type alias

Built-in Namespaces and Functions

NamespaceFunctionDescription
mathabs, max, min, sqrt, pow, log, sin, cos, randomMath functions
stringlength, upper, lower, substr, trim, replaceString functions
stdformat(formatStr, array)Formats a string using values from an array
mcrunCmd(command)Executes a command as the current player
GUIManagervalue(id)Gets a GUI registered value
GUIManagerrequest(id, args)Requests GUI registered data
GUIManagercallback(id, args)Calls a GUI registered callback
GUIManageropen(id, formId, type[, ctx])Opens a GUI of the specified type
GUIManagerswitchTo(id, type)Switches the current GUI to the specified type

TIP

The type in GUIManager::open and GUIManager::switchTo is an integer: 1 is CustomForm, 2 is MessageBox, 3 is PaginatedForm, and 4 is ScriptForm.

Common Built-in Classes

ClassDescription
MenuDataMenu data, containing id, type, title, content, permission, exitCommand, scoreCommand, permissionCommand, items, controls, confirm, cancel, run, submit
MenuItemDataMenu button data, containing type, title, id, run, permission, scores
MenuFormMenu form, new MenuForm(id, title); methods: header, label, divider, spacer, textField, dropdown, toggle, slider, button, closeButton, show; callback results are closeReason, actionIndex, action
MenuMessageBoxMenu message box, new MenuMessageBox(id, title); methods: body, button1, button2, show; callback results are closeReason, selection, action
ShopDataShop data, containing id, type, title, content, exitCommand, scoreCommand, titleCommand, itemCommand, items
ShopItemDataShop item data, containing type, title, introduce, number, id, nbt, confirmButton, cancelButton, time, scores
ShopFormShop form, new ShopForm(id, data); methods: label, divider, previousButton, nextButton, chooseButton, closeButton, show; callback results are closeReason, resultCode, shop, itemIndex, item, fromId
ScoreRequirementScore requirement, containing objective, value
PaginatedFormPaginated form, new PaginatedForm(guiId, title, elements[, pageSize]); methods: previous, next, choose, previousButton, nextButton, chooseButton, button, closeButton, divider, dropdown, header, label, slider, spacer, textField, toggle, show, close, isShowing; callback results are closeReason, selection, selectionIndex, page
ObservableString / ObservableNumber / ObservableBooleanObservable data, constructor parameters are (initial value, whether the client can write); methods: getData, setData, subscribe, unsubscribe, isClientWritable
TextOptions / ButtonOptions / TextFieldOptions / DropdownOptions / DropdownItem / SliderOptions / ToggleOptions / DividerOptions / SpacingOptionsOption classes for form controls
GlobalValueGlobal value container, containing a value field

For common errors and solutions of the scripting language, see Common Error Meanings. For the complete class and method documentation of the native UI, see Native UI.

LOICollectionA · A ready-to-use multifunctional plugin set for LeviLamina