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:
- Enhance Map Creation: Add complex, automated systems and behaviors to your maps—perfect for custom adventures, puzzles, and challenges.
- Server Management: Automate server maintenance tasks such as player teleportation, dynamic permissions adjustment, event-triggered actions, and in-game announcements.
- Create Custom Minigames: Build unique minigames that feature automated triggers, events, and actions, all controlled by scripts.
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?
- Map Creators: Add dynamic elements, automate puzzle mechanics, or control events in your maps without the constraints of redstone.
- Server Owners: Automate management tasks, player interactions, and world features to keep your server running smoothly.
- Minigame Designers: Build intricate, automated minigames with custom rules, triggers, and actions.
- Lua Enthusiasts: Whether you're a beginner or experienced, use the power of Lua scripting to build your own automation and systems.
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:
/script run <filepath> <threadName> — Executes the specified script, where <filepath> is the relative path to your script file (with the "luascripts" folder as the root), and <threadName> is the name used to reference the script's running thread.
/script stop <threadName> — Stops the specified thread, where <threadName> is the name of the running thread you want to stop.
/script stop all — Stops all running threads.
/script list — Lists all active threads.
Lua Scripting
Environment Variables
Each script executed via command is provided with the following built-in variables:
- server (Server) - Represents the server instance.
- world (World or nil) - The world instance from which the script is triggered.
- entity (Entity or nil) - The entity that initiated the script.
- position (BlockPos or nil) - The position at which the script is executed.
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:
- Use descriptive thread names when starting scripts via /script run to easily identify and manage running scripts.
- Clean up after yourself - if your script creates entities or blocks, consider removing them when the script stops.
- Avoid high-frequency polling of world state when possible, as this can impact server performance.
- Use error handling to gracefully handle issues in your scripts.
- Plan for Script Termination - since /script stop now immediately stops scripts, ensure your script includes proper cleanup logic to handle unexpected termination.
Limitations:
- Scripts run with operator (OP) permissions regardless of the permissions of the player who executed them.
- Resource-intensive scripts may impact server performance.
- Scripts cannot directly access the Minecraft code or modify the game's core behavior.
- Each script runs in its own thread, which means global variables are not shared between scripts.
- World operations are limited to the API methods provided; not all Minecraft features are accessible.
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:
-
getWorld()
- Retrieves the dimension world by its ID.
Arguments:
- dimensionID (number) - The ID of the dimension.
Returns:
World or nil
World
Represents the Minecraft dimension world.
Functions:
-
executeCommand()
- Executes a command on the server.
Arguments:
- command (string) - The Minecraft command to execute (without the '/').
- blockPos (BlockPos, optional) - The position where the command will be executed (Default: 0, 0, 0).
Returns:
nil -
createExplosion()
- Creates an explosion in the world.
Arguments:
- blockPos (BlockPos) - The world position where the explosion occurs.
- strength (number, optional) - The strength of the explosion (Default: 4.0).
- mode (("break", "destroy", "none"), optional) - Defines the explosion's effect on blocks:
- "break" - Destroys blocks and drops loot.
- "destroy" - Destroys blocks without dropping loot.
- "none" - Only triggers the explosion effect, no block destruction.
Returns:
nil -
canBlockSeeSky()
- Checks if the block has a clear line of sight to the sky.
Arguments:
- blockPos (BlockPos) - The position of the block.
Returns:
boolean -
getSpawnPosition()
- Retrieves the spawn position.
Returns:
BlockPos -
getCurrentTime()
- Gets the current time in the world.
Returns:
number -
getWorldID()
- Retrieves the world ID.
Returns:
number or nil
-
getGameRuleValue()
- Retrieves the value of a specified game rule.
Arguments:
- gameRule (string) - The name of the game rule whose value is being retrieved.
Returns:
number, boolean, string, or nil
-
getMoonPhaseFactor()
- Retrieves the current moon phase factor.
Returns:
number
-
getRedstonePower()
- Retrieves the redstone power level of a given block.
Arguments:
- blockPos (BlockPos) - The position of the block for which the redstone power is being retrieved.
- direction (("up", "down", "north", "south", "east", "west"), optional) - The direction of the redstone signal. If not specified, the maximum power will be returned.
- "up" - The upward side of the block.
- "down" - The downward side of the block.
- "north" - The northern side of the block.
- "south" - The southern side of the block.
- "east" - The eastern side of the block.
- "west" - The western side of the block.
Returns:
number -
getRedstonePowerFromNeighbors()
- Retrieves the redstone power level from neighboring blocks.
Arguments:
- blockPos (BlockPos) - The position of the block from which redstone power will be retrieved.
Returns:
number -
isBlockPowered()
- Checks if the specified block is powered.
Arguments:
- blockPos (BlockPos) - The coordinates of the block to check.
Returns:
boolean -
getLight()
- Retrieves the light level at the specified block position.
Arguments:
- blockPos (BlockPos) - The coordinates of the block to check.
Returns:
number -
isBlockAir()
- Checks if the specified block is air.
Arguments:
- blockPos (BlockPos) - The coordinates of the block to check.
Returns:
boolean -
isDaytime()
- Determines whether it is currently daytime in the world.
Returns:
boolean -
getDifficulty()
- Gets the current difficulty level of the game.
Returns:
string -
isRaining()
- Checks if it is currently raining in the world.
Returns:
boolean -
isThundering()
- Determines whether there is a thunderstorm in the world.
Returns:
boolean -
getPlayersCountOnServer()
- Retrieves the total number of players currently connected to the server.
Returns:
number -
getPlayersCountInWorld()
- Retrieves the number of players currently present in the world.
Returns:
number -
getPlayers()
- Gets a list of all players in the current context.
Returns:
table{<Player>} -
getEntitiesInSquare()
- Retrieves a list of all entities within the specified square area.
-
getPlayersInSquare()
- Retrieves a list of all players within the specified square area.
Example:
BlockPos
Represents the position of a block in the world.
Fields:
- x (number) - The x-coordinate of the block's position.
- y (number) - The y-coordinate of the block's position.
- z (number) - The z-coordinate of the block's position.
Entity
Represents an entity in the game.
Functions:
-
getDisplayName()
- Retrieves the display name of the entity.
Returns:
string -
getId()
- Retrieves the unique UUID of the entity.
Returns:
string -
getPosition()
- Gets the current position of the entity in the world.
Returns:
BlockPos -
getLookingBlockPosition()
- Determines the position of the block the entity is currently looking at.
Arguments:
- distance (number, optional) - The maximum distance to check for the block being looked at. Defaults to 512 if not specified.
Returns:
BlockPos
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