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

Structure Generation

Michael Weatherby edited this page Oct 23, 2020 · 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,3]: Placement scheme. 0 = surface, 1 = surface without restriction (ie. on liquids), 2 = cave, 3 = sky
scoreboard players set $world.in_2 du_data 1

# Optional: add this line to adjust dimension and/or biome whitelist/blacklist
# Defaults to overworld and no biome restrictions
# data merge storage du:temp {object:{dimension:"minecraft:overworld",biomes:["biome_1","biome_2",...],isBlacklist:0b}}

# Returns -1 if registering structure 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:generation/structure. 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 + dimension 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.
  • Different dimension types use placement schemes differently. Default dimensions (ie. overworld) are what you would expect. Caverns (ie. nether) spawn surface structures in open areas, and a cave structure if no open area is found (this makes cave structures somewhat rare here)- sky structures are never spawned. Sky Dimensions (ie. the end) spawn surface structures where applicable and sky structures everywhere- cave structures are never spawned.

Relevant Code Locations