edit
Extension function for Chunk to edit it using a DSL builder.
This function provides a convenient DSL-based approach to modify chunks in Minecraft worlds. It creates a ChunkEditor instance for the chunk and applies the provided actions.
Usage Examples
Basic Usage - Fill a chunk
val chunk: Chunk = world.getChunkAt(0, 0)
chunk.edit {
fill(Material.STONE)
}Replace blocks in a chunk
chunk.edit {
replace(from = Material.DIRT, to = Material.GRASS_BLOCK)
}Multiple operations
chunk.edit {
fill(Material.STONE)
replace(from = Material.STONE, to = Material.DIAMOND_ORE)
refresh() // Apply changes to clients
}Using with World DSL
world.edit {
chunk(x = 0, z = 0) {
fill(Material.BEDROCK)
refresh()
}
}Available Operations
fill(material: Material)- Fills the entire chunk (all 16x16 columns from minHeight to maxHeight) with the specified materialreplace(from: Material, to: Material)- Replaces all blocks matching the 'from' material with the 'to' materialrefresh()- Forces the chunk to be resent to all players, making changes visible immediately
Performance Considerations
Operations modify blocks synchronously and can be expensive for large-scale changes
Consider using
refresh()only once after all modifications to minimize network trafficThe chunk editor operates on blocks from world minHeight to maxHeight (typically -64 to 320 in 1.18+)
Parameters
The DSL builder action to apply to the chunk. Receives ChunkEditor as the receiver.
See also
Extension function to edit player properties using a DSL.
This function provides a convenient way to modify multiple player attributes in a single, readable block of code.
Example usage:
// Simple property changes
player.edit {
gameMode = GameMode.CREATIVE
health = 20.0
foodLevel = 20
}
// Complex scenario: Setup a player for a minigame
player.edit {
gameMode = GameMode.ADVENTURE
health = 20.0
foodLevel = 20
level = 0
exp = 0.0f
inventory.clear()
inventory.addItem(ItemStack(Material.WOODEN_SWORD))
sendMessage(Component.text("Game starting!", NamedTextColor.GREEN))
teleport(arenaSpawnLocation)
}
// Give rewards after quest completion
player.edit {
level = level + 5
exp = 0.0f
inventory.addItem(ItemStack(Material.DIAMOND, 10))
sendMessage("Quest completed! +5 levels and 10 diamonds!")
}Receiver
The player to edit.
Parameters
The DSL action to perform on the player.
See also
Provides a DSL for editing world properties.
This extension function creates a WorldEditor context for the world, allowing you to modify world settings using a type-safe DSL.
Basic usage:
world.edit {
time = 6000L
weather = WeatherType.CLEAR
difficulty = Difficulty.NORMAL
}Advanced usage with multiple operations:
world.edit {
// Set time and weather
time = 0L
weather = WeatherType.THUNDER
// Configure game rules
doMobSpawning = false
doDaylightCycle = false
keepInventory = true
// Edit players
players({ !it.isOp }) {
gameMode = GameMode.ADVENTURE
health = 20.0
}
// Edit blocks
block(0, 64, 0) {
type = Material.BEDROCK
}
// Edit chunks
chunk(0, 0) {
load()
}
}Parameters
The DSL block to execute