Skip to content
This repository was archived by the owner on Jun 8, 2022. It is now read-only.

Structure Generation

Michael Weatherby edited this page Aug 1, 2019 · 10 revisions

Here is example code for registering a structure. Copy/paste this for each structure you want to generate. These commands should be run from the #du:post_init function tag to ensure it runs after DU has set up the structure registry system

# Tell DU to enable world gen (you only need this command once).
scoreboard players set worldgen du_data 1

## All of these scores need to be set within the specified ranges.

#[0,2]: Size of structure. 0 = small (less than 16x16), 1 = medium (less than 32x32), 2 = large (any other size). This setting affects rarity- small: 1/9 chunks, medium: 1/108 chunks, large: 1/432 chunks.
scoreboard players set in_0 du_data 0
#[1,1000]: Generation weight. When total weight < 1000 for all possible structures, this is the percent chance it will generate. Otherwise it is weight/total weight (Gen chance will always be =< specified weight).
scoreboard players set in_1 du_data 1000
#[0,1]: Ignore placement restrictions. Useful if you want to generate somewhere other than the surface (ie. ocean, under ground, sky, etc.)
scoreboard players set in_2 du_data 0
#[-1,1]: dimension ID
scoreboard players set in_3 du_data 0

#call registry function
function du:world/registry/register_struct
#save returned registry ID
scoreboard players operation <my_struct_id> <obj> = out_0 du_data

#Modify registry entry with Biome list, if needed. Supports up to 24 biome IDs.
#If you do not need to whitelist/blacklist biomes, delete this line.
execute if score <my_struct_id> <obj> matches 1.. run data modify block -29999999 0 1600 RecordItem.tag.du.struct_reg_<dimension>[0] merge value {biomes:[0,1,2,3],isBlacklist:0b}

After registering the structure, add a function to function tag #du:world/struct_gen_<dimension>. Then, when the score in_0 du_data equals the saved reg ID for the custom structure, spawn the structure. Example: execute if score <my_struct_id> <obj> = in_0 du_data run setblock ~ ~ ~ structure_block{<nbt>}.

Clone this wiki locally