The World API provides Lua scripts with access to manipulate the world in Minecraft, including getting/setting blocks, spawning particles, controlling time and weather, creating explosions, striking lightning, and managing spawn locations.
The API is accessed via the global WorldApi table in Lua scripts.
Gets the block at a specific location.
Syntax:
local block = WorldApi:getBlock(location)Parameters:
location(userdata): The Location to query
Returns:
block(userdata): The Block object at the location
Example:
local blockLoc = location:clone()
blockLoc:setY(blockLoc:getY() - 1)
local block = WorldApi:getBlock(blockLoc)Sets the block type at a specific location.
Syntax:
WorldApi:setBlock(location, blockType)Parameters:
location(userdata): The Location to modifyblockType(string): The block type name (e.g., "STONE", "DIRT", "GRASS_BLOCK")
Example:
WorldApi:setBlock(blockLoc, "STONE")Gets the block data at a specific location.
Syntax:
local blockData = WorldApi:getBlockData(location)Parameters:
location(userdata): The Location to query
Returns:
blockData(userdata): The BlockData object
Example:
local data = WorldApi:getBlockData(blockLoc)Sets the block data at a specific location.
Syntax:
WorldApi:setBlockData(location, blockData)Parameters:
location(userdata): The Location to modifyblockData(userdata): The BlockData object to set
Example:
local data = WorldApi:getBlockData(blockLoc)
WorldApi:setBlockData(blockLoc, data)Spawns particles at a location.
Syntax:
WorldApi:spawnParticle(location, particleType, count, offset, [data])Parameters:
location(userdata): The Location to spawn particles atparticleType(string): The particle type name (e.g., "FLAME", "SMOKE", "BUBBLE")count(number): Number of particles to spawnoffset(number): The offset spread for particlesdata(userdata, optional): Particle-specific data (e.g., dust color, block state)
Example:
WorldApi:spawnParticle(location, "FLAME", 10, 0.5)Gets the world time.
Syntax:
local time = WorldApi:getTime(world)Parameters:
world(userdata): The World to query
Returns:
time(number): The world time in ticks
Example:
local time = WorldApi:getTime(world)
print("Time: " .. time)Sets the world time.
Syntax:
WorldApi:setTime(world, time)Parameters:
world(userdata): The World to modifytime(number): The time to set in ticks
Example:
WorldApi:setTime(world, 1000) -- MorningChecks if it is currently daytime in the world.
Syntax:
local isDay = WorldApi:isDaytime(world)Parameters:
world(userdata): The World to query
Returns:
isDay(boolean): true if it is daytime, false otherwise
Example:
if WorldApi:isDaytime(world) then
print("It is daytime")
endGets the current weather in the world.
Syntax:
local weather = WorldApi:getWeather(world)Parameters:
world(userdata): The World to query
Returns:
weather(string): The weather type ("clear", "rain", "thunder")
Example:
local weather = WorldApi:getWeather(world)
print("Weather: " .. weather)Sets the weather in the world.
Syntax:
WorldApi:setWeather(world, weatherType, duration)Parameters:
world(userdata): The World to modifyweatherType(string): The weather type ("clear", "rain", "thunder")duration(number): Duration in ticks
Example:
WorldApi:setWeather(world, "clear", 6000) -- Clear for 5 minutesCreates an explosion at a location.
Syntax:
WorldApi:createExplosion(location, power, setFire, breakBlocks)Parameters:
location(userdata): The Location to create the explosion atpower(number): The explosion power (typically 1-10)setFire(boolean): Whether the explosion should set blocks on firebreakBlocks(boolean): Whether the explosion should break blocks
Example:
WorldApi:createExplosion(location, 2, false, false)Strikes lightning at a location.
Syntax:
local lightning = WorldApi:strikeLightning(location, isEffect)Parameters:
location(userdata): The Location to strike lightning atisEffect(boolean): If true, only the visual effect is shown (no damage)
Returns:
lightning(userdata): The LightningStrike object
Example:
local lightning = WorldApi:strikeLightning(location, true) -- Visual only
local lightning = WorldApi:strikeLightning(location, false) -- Real damageGets a world by name.
Syntax:
local world = WorldApi:getWorld(worldName)Parameters:
worldName(string): The name of the world (e.g., "world", "world_nether", "world_the_end")
Returns:
world(userdata): The World object, or nil if not found
Example:
local world = WorldApi:getWorld("world")Gets the spawn location of a world.
Syntax:
local spawnLocation = WorldApi:getSpawnLocation(world)Parameters:
world(userdata): The World to query
Returns:
spawnLocation(userdata): The spawn Location
Example:
local spawn = WorldApi:getSpawnLocation(world)Sets the spawn location of a world.
Syntax:
WorldApi:setSpawnLocation(world, location)Parameters:
world(userdata): The World to modifylocation(userdata): The new spawn Location
Example:
local newSpawn = location:clone()
WorldApi:setSpawnLocation(world, newSpawn)- Block type names must be valid Bukkit material names
- Time is measured in ticks (20 ticks = 1 second)
- Weather duration is measured in ticks
- Explosion power of 4 is equivalent to TNT
- Lightning with
isEffect=truewill not damage entities or ignite blocks - The spawn location must belong to the target world, or the operation will fail
- Particle data is optional and only required for certain particle types (e.g., DUST_COLOR, BLOCK)