Here is a snippet that allows you to place blocks in a cuboid asynchronously (and therefore without lag, great for minigames and many other uses)
Usage:
code_language.skript:
on script load:
import "com.sk89q.worldedit.regions.CuboidRegion"
import "com.sk89q.worldedit.Vector" as {WorldEditVector}
import "com.sk89q.worldedit.EditSession"
import "com.boydti.fawe.FaweAPI"
import "com.boydti.fawe.util.EditSessionBuilder"
import "com.sk89q.worldedit.blocks.BaseBlock"
import "com.sk89q.worldedit.patterns.BlockChance"
import "java.util.Arrays"
import "com.sk89q.worldedit.patterns.RandomFillPattern"
import "java.util.stream.Collectors"
function getRegion(pos1: location, pos2: location) :: object:
loop 1 and 2:
set {_vec::%loop-num%} to new {WorldEditVector}(x-loc of {_pos%loop-num%}, y-loc of {_pos%loop-num%} and z-loc of {_pos%loop-num%})
return new {CuboidRegion}({_vec::*})
function getBaseBlock(block: itemtype) :: object:
return new {BaseBlock}({_block}.getRandom().getTypeId() and {_block}.getRandom().getData().getData())
function getBlockChance(block: itemtype, chance: number) :: object:
return new {BlockChance}(getBaseBlock({_block}) and {_chance})
function getWorld(world: world) :: object:
return {FaweAPI}.getWorld("%{_world}%")
function getEditSession(world: world) :: object:
return new {EditSessionBuilder}(getWorld({_world})).fastmode(true).build()
function setBlocks(pos1: location, pos2: location, block: object) :: boolean:
set {_session} to getEditSession(world of {_pos1})
set {_args::*} to getRegion({_pos1}, {_pos2}) and getBaseBlock({_block})
if {_block} is a text:
loop split {_block} at ",":
set {_it::*} to join (split loop-value at "%%") with " " parsed as "%integer% %item%"
if {_it::*} is set:
add getBlockChance({_it::2}, {_it::1}) to {_c::*}
delete {_it::*}
else:
return false
set {_args::*} to getRegion({_pos1}, {_pos2})
add new {RandomFillPattern}({Arrays}.stream([{_c::*} as (java type "%{BlockChance}%")]).collect({Collectors}.toList())) to {_args::*}
{_session}.setBlocks({_args::*});
{_session}.flushQueue();
return true
Usage:
- Basic:
setBlocks({corner one}, {corner two}, dirt)
- Patterns:
setBlocks({corner one}, {corner two}, "50%%dirt,25%%air,25%%diamond ore")
- skript-mirror
- Fast Async WorldEdit
Last edited: