Server plugins
World generation
World generation is the server's: biomes, dimension types and damage types reach clients in vanilla's registry packets, and the rest never leaves the server, so vanilla clients can join. Plugins add and override entries with vanilla's data pack files in their data folder, as the server's data packs do, and add feature, structure and noise types and level generators in code.
Biomes, dimension types and damage types
Like a data pack's, each file is an entry named after its namespace and path:
data/<namespace>/worldgen/biome/<path>.jsonis the biome<namespace>:<path>;data/<namespace>/dimension_type/<path>.jsonis a dimension type;data/<namespace>/damage_type/<path>.jsonis a damage type.
The files are vanilla 26.3's data pack format 121 for these registries. A biome:
{
"has_precipitation": true,
"temperature": 0.7,
"downfall": 0.8,
"attributes": {
"minecraft:visual/sky_color": "#78a7ff",
"minecraft:visual/fog_color": "#c0d8ff",
"minecraft:gameplay/natural_mob_spawns": {
"modifier": "overlay",
"argument": {
"spawns_by_category": {
"creature": [{ "type": "minecraft:sheep", "weight": 12, "count": 4 }]
},
"spawn_costs": {}
}
}
},
"effects": {
"water_color": "#3f76e4",
"grass_color": "#6fbf4a",
"foliage_color": "#59ae30"
},
"carvers": ["minecraft:cave", "minecraft:canyon"],
"features": []
}
Obsidian reads the files at startup, before the worlds load, and whenever a plugin loads or unloads:
- A file for one of vanilla's entries, like
data/minecraft/worldgen/biome/plains.json, overrides it (see Data packs and overriding vanilla). When files define the same entry, the last wins: plugins' in load order, then data packs'. - A plugin's entries stay registered until the server stops, even when it unloads, since chunks refer to them. After a restart without the plugin, its biomes load as plains, as its blocks load as air.
- A dimension type's
min_y,heightandlogical_heightcan't change until a restart: a reload changing them keeps the old values, with a warning. - A file vanilla wouldn't accept is logged and left out, and the plugin loads without it (see below).
Clients are sent the entries as vanilla sends a data pack's, so vanilla clients can join. Players already connected go back through configuration when entries change. Plugin biomes generate in plugins' dimensions (see Dimensions) and in vanilla's through biome regions. The Obsidian client doesn't tint plugin biomes yet.
What's checked
A file is read as vanilla reads a data pack's, so it's accepted where vanilla accepts it. Errors name the field and
what's expected, like effects.water_color: expected a colour: "#rrggbb", an int or a list of 3 floats.
- Optional fields get vanilla's defaults. Unknown fields, JSON comments and trailing commas are ignored.
- Values must be the right kind of JSON value (
"7"isn't a number). A colour is"#rrggbb"("#aarrggbb"where vanilla takes alpha), an int, or a list of 3 (or 4) floats from 0 to 1. - Ranges are vanilla's. For example, a dimension type's
min_yandheightare multiples of 16,min_y + heightis at most 2032, andlogical_heightis at mostheight. - References must exist. Sounds, particles and entity types are vanilla's (entity types may be a loaded plugin's); a
sound vanilla doesn't have is given inline as
{"sound_id": ..., "range": ...}. - A biome's
featuresandcarversname vanilla's or plugins' entries or tags, or define them inline (see World generation features). Where vanilla would drop a feature, carver or spawner it can't read, the whole file is left out. - A dimension type must declare
has_ender_dragon_fight, and may name adefault_clock, such asminecraft:overworld. Itstimelinescan only be a timeline tag, like"#minecraft:in_overworld".
Most of a biome's and dimension type's looks and rules are environment attributes: sky and fog colours, particles,
music and sounds, and rules like gameplay/water_evaporates or gameplay/bed_rule. Plugins can set all of
vanilla's attributes, as a value or as {"modifier": ..., "argument": ...}. Older fields such as effects.sky_color
or a dimension type's ultrawarm are ignored, as vanilla ignores them. A biome can't set gameplay/fast_lava or
gameplay/sky_light_level, which apply to a whole dimension, and particle options can only name vanilla's blocks and
items.
Mob spawns are the gameplay/natural_mob_spawns attribute (spawns_by_category and spawn_costs), as in the
example, and gameplay/creature_world_gen_spawn_probability. The old biome fields spawners, spawn_costs and
creature_spawn_probability are ignored. Natural spawning doesn't yet combine dimension and biome spawn attributes,
or sample the new kinds of count provider.
The server applies the attributes it has the mechanics for. A value starts at the attribute's default, then the dimension type's applies, then the biome's, so a plugin's biome or dimension type can change them:
gameplay/monsters_burn,gameplay/sky_light_levelandgameplay/fast_lava. In the overworld the day timeline applies after the biome, so a biome can't stop monsters burning by day.gameplay/can_start_raidandgameplay/can_pillager_patrol_spawn.gameplay/piglins_zombifyandgameplay/snow_golem_melts.gameplay/bed_ruleandgameplay/respawn_anchor_works: where beds or anchors don't work, using one explodes, as in vanilla's nether and end.gameplay/water_evaporates: water poured from a bucket hisses away.
Players can't sleep or set their spawn with a bed or anchor yet. The other attributes change what clients show and play.
World generation features
Plugins add configured and placed features, and change what biomes place and spawn with biome modifiers:
data/<namespace>/worldgen/configured_feature/<path>.jsonis the configured feature<namespace>:<path>;data/<namespace>/worldgen/placed_feature/<path>.jsonis a placed feature;data/<namespace>/worldgen/configured_carver/<path>.jsonis a configured carver;data/<namespace>/biome_modifier/<path>.jsonis a biome modifier.
Features are vanilla's format: a configured feature is {"type": ..., "config": {...}} and a placed feature
{"feature": ..., "placement": [...]}. Every type vanilla's own features use is available, and so are the types
plugins register (see Feature types). A feature names others by identifier or defines them inline.
An ore that replaces stone with a plugin block, in every overworld biome:
// data/ruby/worldgen/configured_feature/ore_ruby.json
{
"type": "minecraft:ore",
"config": {
"size": 8,
"discard_chance_on_air_exposure": 0,
"targets": [
{
"target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:stone_ore_replaceables" },
"state": { "Name": "ruby:ruby_ore" }
},
{
"target": { "predicate_type": "minecraft:tag_match", "tag": "minecraft:deepslate_ore_replaceables" },
"state": { "Name": "ruby:deepslate_ruby_ore" }
}
]
}
}
// data/ruby/worldgen/placed_feature/ore_ruby.json
{
"feature": "ruby:ore_ruby",
"placement": [
{ "type": "minecraft:count", "count": 6 },
{ "type": "minecraft:in_square" },
{
"type": "minecraft:height_range",
"height": {
"type": "minecraft:trapezoid",
"min_inclusive": { "above_bottom": -32 },
"max_inclusive": { "absolute": 48 }
}
},
{ "type": "minecraft:biome" }
]
}
// data/ruby/biome_modifier/ore_ruby.json
{
"biomes": "#c:is_overworld",
"add": { "features": { "underground_ores": "ruby:ore_ruby" } }
}
Biome modifiers
A biome modifier is Obsidian's own format, close to NeoForge's modifiers but one file for every change to a set of biomes. It has:
biomes, the biomes it changes, and optionallyexclude, biomes it leaves alone even when inbiomes;add, with any of:features, placed features to add to the end of each decoration step named, like{ "underground_ores": [...], "vegetal_decoration": "ruby:bush" }; features added may be defined inline;spawners, one{"type", "weight", "minCount", "maxCount"}or a list of them, each added to its entity type's category. Weights are at least 0 and counts at least 1;carvers, configured carvers to add to the end of the biomes' carvers, which may be defined inline;spawn_costs,{"<entity type>": {"energy_budget", "charge"}}, replacing those types' costs in the biomes;
remove, with any of:features, placed features to remove, from every step, or from the steps named, as inadd;spawners, entity types whose spawners are removed from every category;carvers, configured carvers to remove;spawn_costs, entity types whose spawn costs are removed.
Fields the format doesn't have are errors. biomes, exclude, features, carvers and entity types each take an
identifier, a tag like #c:is_overworld, or a list mixing both, vanilla's, the shared c: ones or plugins'. A
plugin's entity type spawns in its Category. Steps are vanilla's decoration steps: raw_generation, lakes,
local_modifications, underground_structures, surface_structures, strongholds, underground_ores,
underground_decoration, fluid_springs, vegetal_decoration and top_layer_modification.
A spawn cost spreads a type's mobs out, as in vanilla's soul sand valley: a mob only spawns where the charge of the
mobs around it stays within the cost's energy_budget.
A carver and a modifier adding it to a plugin's tag of biomes, and plains spawning the plugin's mob:
// data/ruby/worldgen/configured_carver/crystal_caves.json
{
"type": "minecraft:cave",
"config": {
"probability": 0.1,
"y": { "type": "minecraft:uniform", "min_inclusive": { "above_bottom": 8 }, "max_inclusive": { "absolute": 60 } },
"yScale": 0.5,
"lava_level": { "above_bottom": 8 },
"replaceable": "#minecraft:overworld_carver_replaceables",
"horizontal_radius_multiplier": 1,
"vertical_radius_multiplier": 1,
"floor_level": -0.7
}
}
// data/ruby/tags/worldgen/biome/has_crystals.json
{ "values": ["#minecraft:is_mountain", "ruby:crystal_peaks"] }
// data/ruby/biome_modifier/crystal_caves.json
{ "biomes": "#ruby:has_crystals", "add": { "carvers": "ruby:crystal_caves" } }
// data/ruby/biome_modifier/golems.json
{
"biomes": ["minecraft:plains", "#c:is_savanna"],
"exclude": "minecraft:sunflower_plains",
"add": {
"spawners": { "type": "ruby:golem", "weight": 10, "minCount": 1, "maxCount": 2 },
"spawn_costs": { "ruby:golem": { "energy_budget": 0.12, "charge": 1.0 } }
},
"remove": { "spawners": "minecraft:creeper" }
}
A configured carver is vanilla's format, with the minecraft:cave, minecraft:nether_cave or minecraft:canyon
type.
The rules:
- Files for vanilla's features and carvers override them (see Data packs and overriding vanilla), and when files define the same entry, the last wins. Unknown types, fields, enum names and blocks, and missing required fields, are errors. A file that can't be read is logged and left out, with the features and modifiers that need it.
- Features may refer to each other in any order and across plugins. A feature that refers back to itself is left out.
- Every modifier's
addapplies first, then everyremove, each in load order, so a removal also removes what other plugins added. A modifier whose features or carvers can't be resolved is logged and leaves both out, and likewise its spawners and spawn costs. - If a dimension's modifiers would place features in a cycle (one both before and after another), which vanilla can't generate either, that dimension's biomes keep their own features, without plugins' modifiers, and it's logged.
- Features, carvers and spawns come and go with their plugin: new chunks use the current ones, and chunks already generated keep what was placed. As in vanilla, adding features to a step can change the seeds of the features after them in that step.
- If a plugin's feature throws while it's placed, the error is logged and the level stops generating new chunks until the plugin reloads or unloads (see Noise types).
Feature types
Like a NeoForge mod's Feature and PlacementModifierType, a plugin can add feature and placement modifier types
that its (and other plugins') feature files name in their type. Register them in ConfigureRegistry, with
identifiers in the plugin's namespace:
public override void ConfigureRegistry(IPluginRegistry registry)
{
registry.RegisterFeatureType<PillarFeature>("ruby:pillar");
registry.RegisterPlacementModifierType<AtHeight>("ruby:at_height");
}
A feature type extends ConfiguredFeatureBase, and a placement modifier type PlacementModifierBase (or
SinglePlacementModifierBase, which gives one position or none, or PlacementFilterBase, which keeps or drops it).
Both are classes with a parameterless constructor, public or not, whose Type returns their identifier:
using Obsidian.API.World.Features;
using Obsidian.API.World.Generator;
using Obsidian.API.World.Generator.RandomSources;
// A column of a block up from its origin, through the blocks it may replace.
public sealed class PillarFeature : ConfiguredFeatureBase
{
public override string Type => "ruby:pillar";
public required SimpleBlockState State { get; init; }
public required IIntProvider Height { get; init; }
public required BlockSet Replaceable { get; init; }
public override bool Place(FeatureContext context)
{
var block = this.State.ToBlock();
var height = this.Height.Sample(context.Random);
var placed = false;
for (var y = 0; y < height; y++)
{
var position = context.Origin + new Vector(0, y, 0);
if (this.Replaceable.Contains(context.Level.GetBlock(position)))
placed |= context.Level.SetBlock(position, block);
}
return placed;
}
}
// Moves the position to a height.
public sealed class AtHeight : SinglePlacementModifierBase
{
public override string Type => "ruby:at_height";
public required int Y { get; init; }
public override Vector? GetPosition(PlacementContext context, IRandomSource random, Vector position) =>
new Vector(position.X, this.Y, position.Z);
}
// data/ruby/worldgen/configured_feature/pillar.json
{
"type": "ruby:pillar",
"config": {
"state": { "Name": "ruby:ruby_block" },
"height": { "type": "minecraft:uniform", "min_inclusive": 2, "max_inclusive": 6 },
"replaceable": ["minecraft:stone", "#minecraft:deepslate_ore_replaceables"]
}
}
// data/ruby/worldgen/placed_feature/pillar.json
{
"feature": "ruby:pillar",
"placement": [{ "type": "ruby:at_height", "y": -4 }, { "type": "minecraft:in_square" }]
}
A plugin type's JSON is read like vanilla's types: each snake_case key sets the property of the same name in
PascalCase (max_height sets MaxHeight), unknown keys and missing required properties are errors, enums match
ignoring case and underscores, and a single value given for a list is a list of it. Properties may be:
- numbers, booleans, strings, enums, lists (
ImmutableArray<T>,List<T>,IReadOnlyList<T>, arrays) andVector; SimpleBlockState({"Name": ..., "Properties": {...}}),BlockSet(blocks and#block tags),BiomeSet(biomes and#biome tags) andWeightedEntry<T>({"data": ..., "weight": ...}, picked from withWeightedEntry<T>.Pick);- vanilla's kinds of worldgen values, which take any type of that kind by its
type:IIntProvider(a number is a constant),IFloatProvider,IHeightProvider,VerticalAnchor,IBlockStateProvider,IBlockPredicate,IRuleTest,ConfiguredFeatureBaseandPlacedFeature(by identifier or inline), the tree parts andStructureProcessor(see Structure processors); - the plugin's own classes, read with the same rules.
RegisterWorldgenType<TBase, TValue> registers a type of another of those kinds, like
RegisterWorldgenType<IIntProvider, MyProvider>("ruby:my_provider"), or of an abstract class or interface of the
plugin's own that its features' properties use.
- Identifiers are in the plugin's namespace. Register in
ConfigureRegistry: registering later throws. - The types go when the plugin unloads, and features made of them are left out until it reloads.
- Density function, surface rule and biome source types are registered the same way (see Noise types).
Tree parts
Vanilla's minecraft:tree feature is made of a trunk placer, a foliage placer, an optional root placer, tree
decorators and a feature size (its minimum_size). Their base classes are in Obsidian.API.World.Features.Trees, so
a plugin can add its own types of each, which vanilla's tree feature and the plugin's own features take, and give its
feature types properties of them:
using Obsidian.API.World.Features.Trees;
public override void ConfigureRegistry(IPluginRegistry registry)
{
registry.RegisterWorldgenType<FoliagePlacer, CubeFoliagePlacer>("ruby:cube");
registry.RegisterWorldgenType<TreeDecorator, CapDecorator>("ruby:cap");
}
// Square rows of leaves of the placer's radius, for its height, down from the top of the trunk.
public sealed class CubeFoliagePlacer : FoliagePlacer
{
public required int Height { get; init; }
public override int GetFoliageHeight(IRandomSource random, int treeHeight) => this.Height;
protected override void CreateFoliage(
TreeContext tree,
int freeTreeHeight,
FoliageAttachment attachment,
int foliageHeight,
int foliageRadius,
int offset)
{
for (var y = offset; y > offset - foliageHeight; y--)
this.PlaceLeavesRow(tree, attachment.Position, foliageRadius, y, attachment.DoubleTrunk);
}
protected override bool ShouldSkipLocation(
IRandomSource random,
int dx,
int y,
int dz,
int radius,
bool doubleTrunk) => false;
}
// A block on the tree's highest log.
public sealed class CapDecorator : TreeDecorator
{
public required SimpleBlockState State { get; init; }
public override void Place(TreeDecoratorContext context)
{
if (context.Logs.Count > 0)
context.SetBlock(context.Logs[^1] + Vector.Up, this.State.ToBlock());
}
}
// data/ruby/worldgen/configured_feature/ruby_tree.json, with vanilla's other tree fields
"foliage_placer": { "type": "ruby:cube", "radius": 2, "offset": 0, "height": 3 },
"decorators": [{ "type": "ruby:cap", "state": { "Name": "ruby:ruby_block" } }]
Placers get the tree as a TreeContext. Its setters and the protected helpers (PlaceLog, PlaceLeavesRow,
TryPlaceLeaf, PlaceRoot, ...) record each block as part of the tree, so leaves get their distance from its logs
afterwards. A decorator's TreeDecoratorContext has the tree's logs, leaves and roots, and vanilla's
minecraft:fallen_tree takes the same decorators. A FeatureSize gives the radius that must be free around the trunk
at each height (GetSizeAtHeight).
Structure processors
Vanilla's minecraft:fossil feature runs its templates' blocks through processor lists, fossil_processors and
overlay_processors, as do template pools' elements (see Structures): lists by identifier, or defined
inline as {"processors": [...]} or a bare list. The StructureProcessor base class is in
Obsidian.API.World.Structures, so a plugin can add processor types, which data names by their processor_type:
using Obsidian.API.World.Structures;
public override void ConfigureRegistry(IPluginRegistry registry) =>
registry.RegisterWorldgenType<StructureProcessor, DecayProcessor>("ruby:decay");
// Keeps each template block with a chance of its integrity.
public sealed class DecayProcessor : StructureProcessor
{
public required float Integrity { get; init; }
public override StructureBlockInfo? ProcessBlock(
IWorldGenLevel level,
Vector origin,
Vector pivot,
StructureBlockInfo original,
StructureBlockInfo current,
TemplatePlacement placement) =>
placement.GetRandom(current.Position).NextFloat() < this.Integrity ? current : null;
}
// data/ruby/worldgen/configured_feature/ruby_fossil.json, with vanilla's other fossil fields
"fossil_processors": [{ "processor_type": "ruby:decay", "integrity": 0.8 }],
"overlay_processors": "minecraft:fossil_coal"
ProcessBlock gets each block at its world position and returns the block to place, or null to drop it;
FinalizeProcessing then sees all the kept blocks. Override ProcessesWholeTemplate when a result depends on the
template's other blocks. TemplatePlacement.GetRandom gives vanilla's placement random. Processors are shared between
threads, so keep them stateless.
A data/<namespace>/worldgen/processor_list/<path>.json file is a processor list, {"processors": [...]} or a bare
list, which fossils and template pools name by identifier, like vanilla's (see Structures).
Structures
Plugins add structures like a data pack, in vanilla's formats:
data/<namespace>/worldgen/structure/<path>.jsonis the structure<namespace>:<path>;data/<namespace>/worldgen/structure_set/<path>.jsonis a structure set, the structures that share a placement;data/<namespace>/worldgen/template_pool/<path>.jsonis a jigsaw template pool;data/<namespace>/worldgen/processor_list/<path>.jsonis a processor list (see Structure processors);data/<namespace>/structure/<path>.nbtis the structure template<namespace>:<path>, gzipped NBT as a structure block saves it.
A tower of one piece, in the biomes of a tag of the plugin's:
// data/ruby/worldgen/structure/tower.json
{
"type": "minecraft:jigsaw",
"biomes": "#ruby:has_structure/tower",
"spawn_overrides": {},
"step": "surface_structures",
"terrain_adaptation": "beard_thin",
"start_pool": "ruby:tower/start",
"size": 1,
"start_height": { "absolute": 0 },
"project_start_to_heightmap": "WORLD_SURFACE_WG",
"max_distance_from_center": 80,
"use_expansion_hack": false
}
// data/ruby/worldgen/template_pool/tower/start.json
{
"fallback": "minecraft:empty",
"elements": [
{
"weight": 1,
"element": {
"element_type": "minecraft:single_pool_element",
"location": "ruby:tower/base",
"processors": "minecraft:empty",
"projection": "rigid"
}
}
]
}
// data/ruby/worldgen/structure_set/towers.json
{
"structures": [{ "structure": "ruby:tower", "weight": 1 }],
"placement": { "type": "minecraft:random_spread", "spacing": 32, "separation": 8, "salt": 1748312 }
}
// data/ruby/tags/worldgen/biome/has_structure/tower.json
{ "values": ["#minecraft:is_forest", "ruby:crystal_plains"] }
with the template saved by a structure block in data/ruby/structure/tower/base.nbt. Its jigsaw blocks name the pools
the tower grows from, up to its size.
- Structures are any of vanilla's data-driven types:
minecraft:jigsaw, and the others with the same fields as vanilla's own files (minecraft:desert_pyramid,minecraft:igloo,minecraft:shipwreck,minecraft:ocean_ruin,minecraft:ruined_portal,minecraft:mineshaft, and so on). Plugins add types of their own in code (see Structure and pool element types). - Structure sets take
minecraft:random_spreadandminecraft:concentric_ringsplacements, with vanilla's fields. - Pools take vanilla's element types (
minecraft:single_pool_element,minecraft:legacy_single_pool_element,minecraft:list_pool_element,minecraft:feature_pool_elementandminecraft:empty_pool_element) and plugins', withrigidorterrain_matchingprojection, and afallbackpool. - Values are checked as vanilla checks them (a jigsaw's
sizefrom 0 to 20, aspacinglarger than itsseparation, ...). A file that can't be read is logged and left out, with the entries that need it. - A template may be at most 32 MiB once decompressed. A template a pool names that doesn't exist is empty, as in vanilla.
Structures generate in every dimension whose biomes their biomes hold, placed by their sets as in vanilla.
- Structures come and go with their plugin, like features: chunks not generated yet get the current structures, and chunks generated before stay as they are. A structure partly generated when its plugin unloads isn't finished, but its start stays saved, across a restart too, and the rest is placed once the plugin is back.
- If a plugin's code in a structure throws, the dimension stops generating like a failing feature (see Noise types).
- Structure tags,
data/<namespace>/tags/worldgen/structure/<path>.json, merge with vanilla's. Explorer maps, dolphins and eyes of ender find structures through them, so a plugin's structure in#minecraft:on_treasure_mapsis found by treasure maps, and one in#minecraft:eye_of_ender_locatedby eyes of ender. /locate structure <structure|#tag>(permission level 2) finds the nearest structure of a type or tag in the sender's dimension. There's no/locate biomeor/locate poi.
Structure and pool element types
Like a NeoForge mod's structure types and pool element types, a plugin can add structure logic and jigsaw pieces in
code, which its (and other plugins') files name in their type and element_type. Register them in
ConfigureRegistry, with identifiers in the plugin's namespace:
using Obsidian.API.World.Generator;
using Obsidian.API.World.Structures;
public override void ConfigureRegistry(IPluginRegistry registry)
{
registry.RegisterWorldgenType<CustomStructure, CrystalSpire>("ruby:crystal_spire");
registry.RegisterWorldgenType<CustomPoolElement, CrystalCluster>("ruby:crystal_cluster");
}
// A spire of ruby blocks in the middle of its chunk, as tall as its height provider says.
public sealed class CrystalSpire : CustomStructure
{
public required IIntProvider Height { get; init; }
public override Vector? FindStart(StructureStartContext context)
{
var x = (context.ChunkX << 4) + 8;
var z = (context.ChunkZ << 4) + 8;
return new Vector(x, context.GetBaseHeight(x, z, HeightmapType.WorldSurfaceWG), z);
}
public override void AddPieces(
StructureStartContext context,
Vector start,
ICollection<CustomStructurePiece> pieces)
{
var height = this.Height.Sample(context.Random);
pieces.Add(new SpirePiece(new BlockArea(start, start + new Vector(0, height - 1, 0))));
}
}
public sealed class SpirePiece(BlockArea bounds) : CustomStructurePiece(bounds)
{
public override void Place(CustomPieceContext context)
{
var block = new SimpleBlockState { Name = "ruby:ruby_block" }.ToBlock();
for (var y = 0; y <= this.Bounds.Max.Y - this.Bounds.Min.Y; y++)
context.SetBlock(new Vector(0, y, 0), block);
}
}
// A 3 by 3 crystal cluster, hanging off any jigsaw that targets minecraft:bottom, like vanilla's feature elements.
public sealed class CrystalCluster : CustomPoolElement
{
public override Vector Size => new(3, 2, 3);
public override IReadOnlyList<PoolJigsaw> GetJigsaws() =>
[new(new Vector(1, 0, 1), "down_south", "minecraft:bottom")];
public override bool Place(CustomPieceContext context)
{
var block = new SimpleBlockState { Name = "minecraft:amethyst_block" }.ToBlock();
context.SetBlock(new Vector(1, 0, 1), block);
context.SetBlock(new Vector(1, 1, 1), block);
context.SetBlock(new Vector(0, 0, 1), block);
return true;
}
}
// data/ruby/worldgen/structure/crystal_spire.json
{
"type": "ruby:crystal_spire",
"biomes": "#ruby:has_structure/crystal_spire",
"spawn_overrides": {},
"step": "surface_structures",
"terrain_adaptation": "beard_thin",
"height": { "type": "minecraft:uniform", "min_inclusive": 6, "max_inclusive": 12 }
}
// an element of a template pool
{ "weight": 1, "element": { "element_type": "ruby:crystal_cluster", "projection": "rigid" } }
- Obsidian reads what every structure has (
biomes,spawn_overrides,stepandterrain_adaptation) and every pool element'sprojection(rigidwhen left out). The file's other keys set the type's properties, read like a feature type's. - Obsidian checks
biomesat the startFindStartgives, adapts the terrain, and places the pieces: each chunk a piece'sBoundsreach places its own part, the context'sBox.CustomPieceContext.SetBlockplaces relative to the piece's lowest corner, or to a pool element's origin turned with the element (its block turned too, a plugin's by its properties). - Starts are made again from the seed whenever a chunk needs them, so
FindStart,AddPiecesandPlacemust depend only on their context. Types are shared between threads; keep them stateless. - A pool element's
Sizeis the space it may place blocks in, and its jigsaws (PoolJigsaw: a position, orientation,name,target,pooland joint) connect it. By default it has one, facing down at its origin, namedminecraft:bottom. - A structure or pool element naming a type that isn't registered is logged and left out, with the entries that need it. A start made with a plugin that unloads stays saved, and carries on when the plugin is back.
Noise settings, density functions and noises
Plugins add the data a dimension's terrain is made of, like a data pack:
data/<namespace>/worldgen/noise_settings/<path>.jsonis the noise settings<namespace>:<path>;data/<namespace>/worldgen/density_function/<path>.jsonis a density function;data/<namespace>/worldgen/noise/<path>.jsonis a noise,{"firstOctave": ..., "amplitudes": [...]};data/<namespace>/worldgen/multi_noise_biome_source_parameter_list/<path>.jsonis a multi-noise parameter list, which only names a built-in preset:{"preset": "minecraft:overworld"}orminecraft:nether.
They're vanilla's formats, read into the same objects as vanilla's own. Noise settings have every field vanilla's
have: sea_level, default_block, default_fluid, noise, the functions of the noise_router, spawn_target, the
flags and surface_rule. A density function is a number (a constant), an identifier, or an object with a type.
Plugins' dimensions use plugins' noise settings (see Dimensions). Ground rolling around y 64 with a
plugin's noise:
// data/ruby/worldgen/noise/bumps.json
{ "firstOctave": -4, "amplitudes": [1.0, 0.5] }
// data/ruby/worldgen/density_function/ground.json
{
"type": "minecraft:add",
"argument1": { "type": "minecraft:y_clamped_gradient", "from_y": 0, "to_y": 128, "from_value": 1, "to_value": -1 },
"argument2": { "type": "minecraft:noise", "noise": "ruby:bumps", "xz_scale": 0.25, "y_scale": 0 }
}
The noise settings then name "final_density": "ruby:ground" in their noise_router.
- Files for vanilla's entries override them (see Data packs and overriding vanilla), and when files define the same entry, the last wins. Unknown types, fields and blocks, missing fields and values out of vanilla's ranges are errors; a file with one is logged and left out, with the entries that need it.
- Entries refer to each other by identifier, in any order and across plugins. One that refers back to itself is left out.
- A dimension keeps the noise settings it was created with until the server stops. A reload changing them, or the density functions and noises they use, applies after a restart.
- A noise may be defined inline, like
"noise": { "firstOctave": -4, "amplitudes": [1, 0.5] }, but inline noises with the same parameters are the same noise. Name a noise file to have two different noises with the same parameters.
Noise types
Like a NeoForge mod's density function, surface rule and biome source types, a plugin registers types that its
(and other plugins') files name in their type, with RegisterWorldgenType in ConfigureRegistry:
registry.RegisterWorldgenType<IDensityFunction, Terraces>("ruby:terraces");
registry.RegisterWorldgenType<ISurfaceRule, Crust>("ruby:crust");
registry.RegisterWorldgenType<ISurfaceCondition, BelowY>("ruby:below_y");
registry.RegisterWorldgenType<BiomeSourceBase, Rings>("ruby:rings");
They're read like feature types, with the same rules, and:
- A density function implements
IDensityFunction:GetValue, and the bounds of its values,MinValueandMaxValue. One with density functions, noises or splines in its properties must also implementMapAll, rebuilding itself with each passed through the visitor, as in the example below; that's how its noises are seeded. Plugins' functions are sampled block by block, where vanilla's are filled a cell at a time. - A surface rule implements
ICustomSurfaceRule, whoseApplygives the block, or null to let the next rule of a sequence try. A condition implementsICustomSurfaceCondition, whoseTestsays whether it holds. The context has the block's position, biome, surface and stone depths, water height and steepness. - A biome source extends
BiomeSourceBase:PossibleBiomeslists the biomes it gives, andGetBiomepicks one per quart from the climate sampler's values. - All of them run for many positions of every chunk, on several threads at once: keep them fast and stateless.
// Steps a function's values into terraces.
public sealed class Terraces : IDensityFunction
{
public string Type => "ruby:terraces";
public required IDensityFunction Argument { get; init; }
public required double Step { get; init; }
public double MinValue => Math.Floor(this.Argument.MinValue / this.Step) * this.Step;
public double MaxValue => Math.Floor(this.Argument.MaxValue / this.Step) * this.Step;
public double GetValue(double x, double y, double z) =>
Math.Floor(this.Argument.GetValue(x, y, z) / this.Step) * this.Step;
public IDensityFunction MapAll(IDensityFunctionVisitor visitor) => visitor.Apply(new Terraces
{
Argument = visitor.Map(this.Argument),
Step = this.Step
});
}
// Puts a block on the top block of the default block (usually stone).
public sealed class Crust : ICustomSurfaceRule
{
public string Type => "ruby:crust";
public required SimpleBlockState Block { get; init; }
public IBlock? Apply(ISurfaceContext context) => context.StoneDepthAbove <= 1 ? this.Block.ToBlock() : null;
}
{ "type": "ruby:terraces", "argument": "ruby:ground", "step": 0.25 }
{ "type": "ruby:crust", "block": { "Name": "ruby:ruby_block" } }
Unloading a plugin waits for the chunks being generated with its types. While it's unloaded, the dimensions using its types stop generating new chunks, with a warning; chunks already generated still load and save. They generate again when the plugin loads, unless the dimension's level stem, or the plugin data it reads, changed meanwhile, which needs a restart.
If a plugin's code throws while a dimension generates (a density function, surface rule or biome source), the error is logged naming the plugins, and the level stops generating new chunks rather than the server stopping. It generates again once those plugins reload, or after a restart. A chunk whose generation failed starts again from scratch, except when decoration failed: then it keeps the features placed before the failure, with a warning.
Dimensions
A plugin adds a dimension with a level stem file, like a data pack: data/<namespace>/dimension/<path>.json is the
dimension <namespace>:<path>. The server's default world gets a level of that name, generated by the generator the
stem names: vanilla's noise, flat or debug generator, or a plugin's level generator. A dimension with one plugin
biome everywhere:
// data/ruby/dimension/crystal_world.json
{
"type": "minecraft:overworld",
"generator": {
"type": "minecraft:noise",
"settings": "minecraft:overworld",
"biome_source": { "type": "minecraft:fixed", "biome": "ruby:crystal_caves" }
}
}
The file is vanilla 26.3's level stem, read with vanilla's rules (see What's checked):
typenames a dimension type, vanilla's or a plugin's, or defines one inline. It decides the level's build range, sky light and everything else a dimension type does.generatorisminecraft:noise,minecraft:flat,minecraft:debugor a plugin's level generator.minecraft:noisehassettings, naming vanilla's noise settings (minecraft:overworld,amplified,large_biomes,caves,floating_islands,netherorend) or a plugin's (see Noise settings), or defining them inline. Itsbiome_sourceis one of vanilla's or a plugin's (see Noise types):minecraft:multi_noise, with an inlinebiomeslist of{"biome": ..., "parameters": {...}}, or apresetnaming a parameter list (minecraft:overworld,minecraft:netheror a parameter list file's). Each parameter (temperature,humidity,continentalness,erosion,depth,weirdness) is a number from -2 to 2 or a range,[min, max]or{"min": ..., "max": ...}, andoffsetis from 0 to 1;minecraft:fixed, with onebiome;minecraft:checkerboard, withbiomes(a biome, a list of them or a biome tag) and ascalefrom 0 to 62;minecraft:the_end, the end's islands and biomes.
minecraft:flathas vanilla's flatsettings:layers, a list of{"block": ..., "height": ...}from the bottom up, and abiomeeverywhere. Lakes, features and structures aren't generated in flat dimensions yet, so"lakes": true,"features": trueand anystructure_overridesbut[]are rejected.minecraft:debugis vanilla's debug world, every block state laid out on a grid at y 70.- Any other
typenames a loaded plugin's level generator (see Level generators); the generator object's other fields are its settings. - A dimension type or biome defined inline becomes an entry named after the stem: the stem
ruby:crystal_world's type isruby:crystal_world/type, and its biomesruby:crystal_world/biome_0,ruby:crystal_world/biome_1and so on. - Noise settings that generate outside the dimension type's build range aren't supported yet, and are rejected.
Generation fills whole cells of
size_vertical * 4blocks from the cell holdingmin_y, so amin_ythat isn't a multiple of that fills from below it.
A noise dimension generates like a vanilla dimension with those settings: terrain, caves, features (see World generation features) and structures. Players spawn on the ground near the climate's spawn, like the overworld's.
The rules:
- A file for one of vanilla's dimensions overrides how it generates (see Data packs and overriding vanilla). When files define the same dimension, the last wins. A file that can't be read is logged and left out; the plugin loads without it.
- A dimension's level is created when its plugin loads, saved in the world's folder under
dimensions/<namespace>/<path>, and loaded from there after a restart. Data-defined dimensions belong to the default world. - Gameplay follows the dimension type, as in vanilla: monster spawning uses its light limits, undead mobs burn by day
with the overworld's timelines (
#minecraft:in_overworld) orminecraft:gameplay/monsters_burn, and raids start whereminecraft:gameplay/can_start_raidallows. Patrols, wandering traders and phantoms stay in the overworld, and a plugin's dimension has no ender dragon fight. Players reach it through a plugin's portals (see Travel and portals). - The level stays until the server stops, even when its plugin unloads. A reload changing its stem, or the plugin data it reads, applies after a restart, since changing a live level's generator would mix two generators' chunks.
- A dimension generating with a plugin's types or level generator stops generating new chunks while that plugin is unloaded (see Noise types and Level generators).
- After a restart without the plugin, its dimension isn't loaded, and its folder is left alone. Players who were in it join at the world's spawn.
Players get there with /dimension <id>, like /dimension ruby:crystal_world, and plugins send them with
IPlayer.TeleportToDimensionAsync("ruby:crystal_world"), to the dimension's spawn. Vanilla clients see a plugin's
dimension as a level of that name with its dimension type.
Data packs and overriding vanilla
Like vanilla's data packs, data can replace vanilla's entries, so a pack can change vanilla's world generation: a Terralith-style pack overriding the overworld's level stem, noise settings, parameter list and biomes generates its overworld instead of vanilla's. The data comes from two places:
- The server's
datapacksfolder, next toplugins(Paths:DataPackssets another, likePaths:Plugins). Each folder or zip file in it with apack.mcmetais a vanilla data pack, read at startup in name order, after the plugins, so the operator's packs win. Data packs are read once: a change applies after a restart. - Plugins' own
data/minecraft/...files, which override vanilla's entries like a data pack's.
A pack is read for the same files as a plugin's data/ folder: world generation, tags and loot tables. Other files,
like recipes, are skipped, and how many is logged.
- A pack needs a
packsection with a valid textdescription, or it isn't loaded. Formats that fail vanilla's checks are only logged. overlaysandfilterwork as in vanilla.- A pack may hold at most 65,536 files, 32 MiB per file and 512 MiB in all, decompressed. A pack over the limits is logged and left out.
- Data packs apply to every world on the server, since Obsidian's registries are shared by all its worlds.
The order is vanilla's entries, then plugins' files in load order, then data packs' in name order. As in vanilla, the
last file for an entry replaces it whole, and tag files merge ("replace": true starts over). You can override:
- biomes, dimension types and damage types, which clients are sent with their new data. Biome modifiers still apply on top of an overridden biome.
- configured and placed features and configured carvers. An override applies everywhere vanilla uses the entry, growing saplings and bone meal included.
- processor lists, structures, structure sets, template pools and structure templates, which vanilla's structures use too. A structure set override moves where vanilla's structures start, in chunks not generated yet.
- noise settings, density functions and noises, including the noises the surface builder reads.
- parameter lists:
data/minecraft/worldgen/multi_noise_biome_source_parameter_list/overworld.jsonwith{"preset": "minecraft:nether"}makes the overworld pick nether biomes from its climate. - level stems:
data/minecraft/dimension/overworld.json(orthe_nether,the_end) replaces how that dimension generates, read like any dimension. It must keep vanilla's dimension type (override the type's file to change it) and theminecraft:noisegenerator; a flat world is a world type of its own, inworlds.json. - tags, merged as above.
A dimension type's build range must hold the noise settings its dimension generates with. An override that doesn't,
like the overworld's type at min_y 0 with vanilla's overworld noise settings from -64, is logged and left out, so
override the noise settings to match.
Vanilla's entries nothing overrides keep their compiled code, so without overrides worlds generate exactly as before. As in vanilla, a pack added to an existing world changes only the chunks generated from then on, with borders between old and new chunks.
- Data packs, and plugins loaded at startup, apply to every world as it loads.
- A plugin loaded, reloaded or unloaded later changes biomes, features, carvers, spawns, tags and damage types at once (players are sent through configuration when synced entries change). A change to how a running vanilla dimension generates (its stem, the noise it reads, its parameter list) applies after a restart.
- A vanilla dimension built with a plugin's types stops generating while the plugin is unloaded, like a plugin's dimension (see Noise types).
A world made in vanilla with a data pack changing its overworld, like Terralith, saves the pack's overworld stem in
its level.dat. Opened as an integrated server, it loads only when a loaded data pack or plugin overrides
minecraft:overworld's level stem with the same stem; otherwise it's refused with an error saying to add the data
pack, or where the stems differ.
Biome regions
A biome region adds a plugin's biomes to a dimension that already exists, like the overworld or the nether, without
replacing its layout, so that several plugins' biomes generate side by side. It's Obsidian's own format, for what
TerraBlender does for NeoForge and Fabric mods: data/<namespace>/biome_region/<path>.json is the region
<namespace>:<path>. A region is an alternative layout for parts of the dimension: either the dimension's own with
some biomes swapped,
// data/ruby/biome_region/crystal_plains.json
{
"dimension": "minecraft:overworld",
"weight": 2,
"replace": {
"minecraft:plains": "ruby:crystal_plains",
"minecraft:sunflower_plains": "ruby:crystal_plains"
}
}
or a parameter list of its own, picked from the climate like a multi_noise biome source's biomes (see
Dimensions):
// data/ruby/biome_region/crystal_lands.json
{
"dimension": "minecraft:overworld",
"weight": 1,
"biomes": [
{
"biome": "ruby:crystal_plains",
"parameters": {
"temperature": [-1, 1], "humidity": [-1, 1], "continentalness": [-0.11, 1],
"erosion": [-1, 1], "depth": 0, "weirdness": [-1, 1], "offset": 0
}
},
{
"biome": "minecraft:ocean",
"parameters": {
"temperature": [-1, 1], "humidity": [-1, 1], "continentalness": [-1.2, -0.11],
"erosion": [-1, 1], "depth": 0, "weirdness": [-1, 1], "offset": 0
}
}
]
}
dimensionnames the dimension by its level stem:minecraft:overworld,minecraft:the_netheror a plugin's dimension. Regions suit dimensions whose biomes follow the climate (multi_noise), but apply to any dimension of vanilla's noise generator. A region naming a dimension that doesn't exist does nothing.weight, from 1 to 1000, is how often the region is picked, against the dimension's other regions and its own layout, which weighs 10.replacemaps the dimension's biomes to the biomes generated instead. A key may be a biome tag, like"#c:is_plains": "ruby:crystal_plains", which replaces each of the tag's biomes.biomesis a parameter list, the dimension's whole layout where the region is, so every climate should find a biome, oceans and caves included. A region hasreplaceorbiomes, not both.- Biomes are vanilla's or plugins'. Fields the format doesn't have are errors, and a file that can't be read is logged and left out. When two plugins define the same region, the last in load order wins.
Regions can be defined in code too, in ConfigureRegistry, with IPluginRegistry.RegisterBiomeRegion: the
identifier, the dimension, the weight, and either the replace map or the biomes as ClimateBiome entries. They
follow the same rules as files.
public override void ConfigureRegistry(IPluginRegistry registry)
{
registry.RegisterBiomeRegion(
"ruby:crystal_plains",
"minecraft:overworld",
2,
new Dictionary<string, string> { ["#c:is_plains"] = "ruby:crystal_plains" });
}
Each column's region is picked from the world seed: the dimension is split into irregular cells about 1024 blocks across, each of which picks a region, or the dimension's own layout, by weight. Terrain doesn't change, only biomes and what follows them: surface rules, features, carvers, spawns and structures. A dimension with no regions generates exactly as without them.
Region biomes are plain biomes, so add them to the tags that biome modifiers and other plugins name, like
#c:is_overworld and #minecraft:is_overworld (or #c:is_nether and #minecraft:is_nether), and to vanilla's
structure tags for the structures they should have, like #minecraft:has_structure/village_plains:
// data/c/tags/worldgen/biome/is_overworld.json, and the same in data/minecraft/tags/worldgen/biome/
{ "values": ["ruby:crystal_plains"] }
- A dimension takes the loaded plugins' regions when it starts generating (at startup for vanilla's, when it's added for a plugin's) and keeps them until the server stops. A plugin change later applies after a restart.
- A region whose plugin unloads keeps generating with its biomes, which stay registered (see Biomes), but without the plugin's features.
- Changing a dimension's regions moves where they fall in chunks not generated yet; chunks already generated stay as they are. After a restart without the plugin, its biomes in saved chunks load as plains.
Level generators
A plugin can generate a whole level in code, like the host's own generators: a class implementing ILevelGenerator,
registered by identifier in ConfigureRegistry.
public sealed class SkyIslandsGenerator : ILevelGenerator
{
public string Id => "ruby:sky_islands";
public void Init(ILevel level)
{
}
public ValueTask<IChunk> GenerateChunkAsync(int x, int z, IChunk? chunk = null,
ChunkGenStage stage = ChunkGenStage.full)
{
// Fill the chunk's blocks and biomes, then mark it generated (full).
}
}
public override void ConfigureRegistry(IPluginRegistry registry) =>
registry.RegisterGenerator<SkyIslandsGenerator>("ruby:sky_islands");
A world uses it by naming it as its Generator in worlds.json, and a world's child dimension by its name there. A
level stem names it as its generator, with settings, like {"type": "ruby:sky_islands", "island_size": 12} (see
Dimensions). To read them, implement IConfigurableLevelGenerator, whose Configure gets the stem's
generator object on each new instance, before Init:
public sealed class SkyIslandsGenerator : IConfigurableLevelGenerator
{
private int islandSize = 8;
public void Configure(JsonElement settings)
{
if (settings.TryGetProperty("island_size", out var size))
this.islandSize = size.GetInt32();
}
// Id, Init and GenerateChunkAsync as above.
}
Settings it can't use should throw: the level then stops, logged, as when Init throws.
- The identifier is in the plugin's namespace, and is registered in
ConfigureRegistry. A generator registered with the plugin'sILevelFactoryinstead is the plugin's too, under itsId. - Each level gets its own instance, created in a service scope of its own (constructor injection works), and then its
Init. When the level stops using it, the instance is disposed if it'sIDisposableorIAsyncDisposable: release there whatInitsubscribed to, or the plugin's code can't unload. - A save takes the generator's
LockChunkAsynclock. Lock with it any chunk the generator writes into besides the one it generates. - While the plugin is unloaded, the level stops generating new chunks, with a warning; chunks already generated still load and save. When the plugin loads again, the level gets a new instance and carries on from its next chunk.
- When the generator throws, the error is logged naming the plugin, the chunk is left ungenerated, and the level stops generating until the plugin reloads.
- After a restart without the plugin, a world saved with its generator loads stopped, rather than generating with another generator. A new world or dimension can't be created without its generator: the server refuses to start it, saying which generator is missing.