world
you interact with the world using Katton.world()
properties
Katton.world().players //a list of `player` values in the game
Katton.world().entities //every nonplayer entity currently in the world, as a list of entity values. use `world.players` instead if you want the players
methods
Katton.world().spawnEntity(type, location)
Katton.world().setBlock(location, material)
Katton.world().getBlock(location)
Katton.world().fillBlocks(from, to, material)
Katton.world().playSound(sound, location, volume = 1, pitch = 1)
Katton.world().spawnParticle(particle, location, ...)
spawnEntity
spawns a new entity into the world
Katton.world().spawnEntity(type, location)
example
Katton.world().spawnEntity("zombie", player.location)
function spawnWave(count, location) {
for (i in 1..count) {
Katton.world().spawnEntity("zombie", location)
}
}
setBlock
sets a block at a target location to a material
Katton.world().setBlock(location, material)
Note
nonblock materials like "diamond_sword" cause a runtime error
example
Katton.world().setBlock(player.location, "glass")
getBlock
gets the block material name at a target location
Katton.world().getBlock(location)
example
val currentBlock = Katton.world().getBlock(player.location) // "glass"
fillBlocks
fills a 3D rectangular region between two corner locations with a block material
Katton.world().fillBlocks(from, to, material)
example
Katton.world().fillBlocks({ "x": 0, "y": 60, "z": 0 }, { "x": 10, "y": 65, "z": 10 }, "stone")
function fillLargeArea(from, to, material) {
// split into smaller boxes yourself and call fillBlocks per chunk
}
playSound
plays a sound effect at a world location visible/audible to everyone around it
Katton.world().playSound(sound, location, volume = 1, pitch = 1)
Note
plays at a fixed location and everyone is able to hear it, unlike player.playSound which plays specifically to one player
example
Katton.world().playSound("entity_wither_spawn", player.location)
Katton.world().playSound("entity_wither_spawn", player.location, volume = 2.0, pitch = 0.8)
spawnParticle
spawns particles into the world visible to all players
Katton.world().spawnParticle(particle, location, ...)
Note
visible to all players
example
Katton.world().spawnParticle("flame", player.location)
Katton.world().spawnParticle("dust", player.location, count = 20, offset = {"x": 1, "y": 1, "z": 1}, color = "#ff55aa", size = 1.5)
Katton.world().spawnParticle("dust_color_transition", player.location, count = 10, color = "#ff0000", to_color = "#0000ff", size = 2)
Katton.world().spawnParticle("block", player.location, count = 30, material = "diamond_block")
Katton.world().spawnParticle("flame", player.location, direction = {"x": 0, "y": 1, "z": 0}, speed = 0.5)