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 Dec 30, 2019 · 10 revisions

Here is example code for registering an structure. Copy/paste this for each structureyou want to generate. These commands need to be run from the #load:post_load function tag to ensure it runs after DU has set up the structure registry system.

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

# [0,3]: Size of structure. 0 = tiny (definitely less than 8x8, 4x4 prefered), 1 = small (less than 16x16), 2 = medium (less than 48x48), 3 = large (more than 48x48). This setting guarantees larger structures are more spread out.
scoreboard players set $world.in_0 du_data 1
# [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 $world.in_1 du_data 1
# [0,1]: 1 = Ignore placement restrictions (prevents generation on water, sky, void, side of cliffs, etc). Useful if you want to generate somewhere other than the surface (ie. ocean, under ground, sky, etc.)
scoreboard players set $world.in_2 du_data 1
# [-1,1]: dimension ID
scoreboard players set $world.in_3 du_data 1

# Optional: add this line to adjust biome whitelist/blacklist
data merge storage du:temp {object:{biomes:[#,#,#,...],isBlacklist:0b}}

# Returns -1 if registering ore failed. Otherwise, returns generated structure registry ID.
function du:world/registry/register_struct
# Keep track of this number in a scoreboard value. 
scoreboard players operation <my_struct_id> <obj> = $world.out_0 du_data

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

Notes on structure generation:

  • It is recommend to have the total combined weight of all your structures for a size category equal 1000 (or less if you want them to be rarer).
  • NBT manipulation is expensive, so if you plan on adding a large number of structures you may want to register categories and pick a structure from that category manually. For example, if you add 20 different types of custom trees, register a single structure "tree" and when "tree" is passed as input pick from one of the 20 variations manually.

Relevant Code Locations

Clone this wiki locally