Minecraft Lua Scripts API - 0.3-ALPHA

Introduction

Welcome to the Minecraft Lua Scripts Framework! This mod provides a Lua-based scripting environment that enables players to automate tasks and create custom systems in Minecraft. Whether you're working on a new map, managing a server, or designing your own minigames, this framework gives you the flexibility to create dynamic, interactive experiences without the limitations of vanilla gameplay.

Key Features:

Why Lua?

Lua is lightweight, flexible, and user-friendly, making it ideal for adding custom automation without bogging down performance. It offers a perfect balance for both beginners and experienced users—whether you're just starting out or designing sophisticated systems, Lua gives you the power to shape your Minecraft experience.

What this Mod is NOT:

This framework is not designed to replace or cheat the Minecraft experience. Instead, it enhances the gameplay by adding new layers of interaction and automation, perfect for players who want to customize and streamline their in-game tasks.

Who Is This For?

Explore, experiment, and see how the Minecraft Lua Scripts Framework can transform your world!

Commands

Your scripts are located in the luascripts folder within your game directory.

The Minecraft command used to launch your scripts is: /script

/script Command Usage:

Lua Scripting

Environment Variables

Each script executed via command is provided with the following built-in variables:

MLS-Specific Rules

Function Calls

IMPORTANT: When calling methods on objects in the MLS framework, always use the dot (.) notation, not the colon (:) notation.

-- CORRECT way to call methods
world.executeCommand("time set day")
local pos = entity.getPosition()

-- INCORRECT way (will cause errors)
-- world:executeCommand("time set day")
-- local pos = entity:getPosition()

Timing and Delays

To create delays in your scripts, use os.time() to measure elapsed time:

-- Basic timer script for a 10 second countdown
local endTime = os.time() + 10
local lastSecond = 10

while os.time() < endTime do
    local remainingSeconds = endTime - os.time()
    
    if remainingSeconds < lastSecond then
        lastSecond = remainingSeconds
        world.executeCommand("title @a actionbar {\"text\":\"" .. lastSecond .. "\"}")
    end
end
world.executeCommand("title @a title {\"text\":\"Go!\"}")

Best Practices for MLS:

Limitations:

Classes

Classes are regular Lua tables with a defined structure.

Below are all the classes and their fields.

Server

Represents the server in Minecraft.

Functions:

World

Represents the Minecraft dimension world.

Functions:

Example:

BlockPos

Represents the position of a block in the world.

Fields:

Entity

Represents an entity in the game.

Functions:

Player extends Entity

Represents a player in the game.

Examples

Weather Control System

-- weather_cycle.lua
-- Cycles through different weather conditions

while true do
    world.executeCommand("weather clear")
    print("Weather set to clear")
    
    local endTime = os.time() + 30
    while os.time() < endTime do end
    
    world.executeCommand("weather rain")
    print("Weather set to rain")
    
    endTime = os.time() + 30
    while os.time() < endTime do end
    
    world.executeCommand("weather thunder")
    print("Weather set to thunder")
    
    endTime = os.time() + 30
    while os.time() < endTime do end
end

Player Detection System

-- player_detector.lua
-- Detects players in a specific area and triggers actions

local corner1 = {x = 100, y = 64, z = 100}
local corner2 = {x = 120, y = 70, z = 120}

while true do
    local players = world.getPlayersInSquare(corner1, corner2)
    
    if #players > 0 then
        world.executeCommand("setblock 110 65 110 redstone_block")
        print("Players detected: " .. #players)
    else
        world.executeCommand("setblock 110 65 110 air")
        print("No players detected")
    end
    
    -- Check every second
    local endTime = os.time() + 1
    while os.time() < endTime do end
end

Advanced Redstone Logic

-- redstone_monitor.lua
-- Monitors redstone power at a specific position and responds

local monitorPos = {x = 100, y = 64, z = 100}
local outputPos = {x = 102, y = 64, z = 100}

while true do
    local power = world.getRedstonePower(monitorPos)
    
    if power > 0 then
        local command = "say Redstone level: " .. power
        world.executeCommand(command)
        
        -- Create different strength signals based on input
        if power > 10 then
            world.executeCommand("setblock " .. outputPos.x .. " " .. outputPos.y .. " " .. outputPos.z .. " redstone_block")
        else
            world.executeCommand("setblock " .. outputPos.x .. " " .. outputPos.y .. " " .. outputPos.z .. " redstone_torch")
        end
    else
        world.executeCommand("setblock " .. outputPos.x .. " " .. outputPos.y .. " " .. outputPos.z .. " air")
    end
    
    -- Check every half second
    local endTime = os.time() + 0.5
    while os.time() < endTime do end
end