Skip to content

Instantly share code, notes, and snippets.

@misode
Last active June 7, 2019 20:00
Show Gist options
  • Save misode/7cb24ebaeab4ec03017ba713eccd49c9 to your computer and use it in GitHub Desktop.
Save misode/7cb24ebaeab4ec03017ba713eccd49c9 to your computer and use it in GitHub Desktop.

Orbis 1.13 Technical Details

Orbis works by scanning chunks and performing actions based on certain features of that chunk, like its biome, terrain height and specific blocks in the world. All conditions are based on world generation to make sure everything is seed deterministic.

orbis:main

Every 16 ticks, Orbis does a few things.

  • If a player with the gm4_orbis_active tag is in a chunk that has bedrock at y=0, it spawns a marker for that chunk, if there wasn't one already.
  • For every player with the gm4_orbis_active tag, it generates the closest chunk that hasn't been generated yet. This calls the orbis:chunk/generate function.
  • Kill every chunk that has been generated, but only if all four adjacent chunks have also been generated. This is because chunks use the biome of adjacent chunks to determine the final biome decision.

orbis:chunk/scan

This function is responsible for determining the biome type. There are 5 biome types: default, ocean, desert, snow and mesa. Every biome has its own requirements. If the chunk doesn't meet any requirements, it's considered a default biome.

  • ocean: It counts all the water blocks at y=55 and at y=62. If there are at least 384 the chunk is an ocean.
  • desert: It counts all the sandstone blocks between y=56 and y=110. If there are at least 128 the chunk is a desert.
  • snow: It counts all the snow layers between y=60 and y=89. If there are at least 128 the chunk is a snow biome. The choice for y-89 is very important because starting y=90 snow layers can generate in mountains.
  • mesa: It counts both the terracotta blocks and the red sand blocks between y=62 and y=80. If there are at least 64 of either of those the chunk is a mesa.

orbis:chunk/generate

First, it makes sure that the chunk has been scanned. It also copies the original biome id for later. After that, it makes sure that the four adjacent chunks have been scanned. If necessary, it summons a new chunk marker. This causes the chunks to generate outwards.

After these 5 chunks have been scanned, it tries to correct itself for possible mistakes.

  • If a chunk is surrounded by 3 chunks of another biome, it uses the biome of the surrounding chunks instead.
  • If the chunk is surrounded by 2 pairs of different bioms, it uses the default biome instead. Not doing any terrain modifications is better than doing the wrong modifications.

After these checks, the chunk can finally be generated. It runs a generic function tag #orbis:chunk/generate, and a function tag for each biome type (eg. #orbis:biome/ocean).

After the terrain modifications have been done, it restores the original biome type. This is to make sure chunks are generated the same regardless of the order in which they get generated. It also needs to mark the chunk as gm4_generated and fill y=0 with barriers.

orbis:structure/chunk

This function is run from #orbis:chunk/generate and decides whether or not this chunk should have a chance to spawn a tower or a dungeon. It checks a specific block at y=1.

  • If the block at ~10 1 ~10 is granite, it attempts to spawn a dungeon.
  • If the block at ~10 1 ~10 is diorite, it attempts to spawn a tower.

orbis:structure/check

This is a recursive function. For dungeons, this searches for a cave. For towers, this searches for the highest block in the center of the chunk, ignoring some blocks like grass, snow layers, leaves and logs.

orbis:structure/spawn_attempt

Orbis allows other modules to add structures as dungeons or towers. This function fist calls the #orbis:structure/spawn_init function. Functions that are run by this tag should summon a marker entity if they can spawn a structure that meets the criteria like spawn hight, biome type or specific blocks. For example, the orbis towers need to be between y=80 and y=200 and they each check their biome type. After all modules had the chance to summon such a structure marker, the #orbis:structure/spawn function gets called for one random structure marker. It is important that if a module promises to spawn a structure with a structure marker, they also spawn it.

Orbis also allows other modules to add different spawners and loot. Just like like structure variants, modules first need to summon a populate marker, which is run from #orbis:structure/populate_init based on criteria. For example, the orbis ocean dungeon spawns water spawners because the spawner markers in the structure file have the gm4_water_spawner tag. The difference with structure markers is that multiple chests and spawners need to be set.

You can find the source code of this version here.

Orbis 1.14 Technical Details

Orbis works by scanning chunks and performing actions based on certain features of that chunk, like its biome, terrain height and specific blocks in the world. All conditions are based on world generation to make sure everything is seed deterministic.

orbis:main

Every 4 ticks, Orbis does a few things.

  • If a player without the gm4_orbis_disabled tag is in a chunk that has bedrock at y=0, it spawns a marker for that chunk, if there wasn't one already.
  • For every player without the gm4_orbis_disabled tag, it generates the closest chunk that hasn't been generated yet. This calls the orbis:chunk/generate function.

orbis:chunk/scan and orbis:chunk/get_biomes

This function is responsible for determining the biome type. A chunk can have multiple biome feature identifiers. For example "lush", "forest" and "mountains". The biome identifiers are determined by a loot table (this loot table is currently 380 lines long). The biome feature identifiers are stored on fakeplayers so they are easy and inexpensive to check for.

orbis:chunk/generate

This function first scans the chunk like was described above. Then it will run orbis:structure/chunk to try to spawn a structure. After that it calls a function tag #orbis:chunk/generate, which other datapacks can use. It also summons 4 adjacent chunk markers if necessary. This causes the chunks to generate outwards. Finally it fills y=0 with barriers.

orbis:structure/chunk

This function is run from #orbis:chunk/generate and decides whether or not this chunk should have a chance to spawn a tower or a dungeon. It checks a specific block at y=1.

  • If the block at ~10 1 ~10 is granite, it attempts to spawn a dungeon.
  • If the block at ~10 1 ~10 is diorite, it attempts to spawn a tower.

orbis:structure/check

This is a recursive function. For dungeons, this searches for a cave. For towers, this searches for the highest block in the center of the chunk, ignoring some blocks like grass, snow layers, leaves and logs.

orbis:structure/spawn_attempt

Orbis allows other modules to add structures as dungeons or towers. This function fist calls the #orbis:structure/spawn_init function. Functions that are run by this tag should summon a marker entity if they can spawn a structure that meets the criteria like spawn hight, biome features or specific blocks. For example, the orbis towers need to be between y=80 and y=200 and they each check their biome type. After all modules had the chance to summon such a structure marker, the #orbis:structure/spawn function gets called for one random structure marker. It is important that if a module promises to spawn a structure with a structure marker, they also spawn it.

Orbis also allows other modules to add different spawners and loot. Just like like structure variants, modules first need to summon a populate marker, which is run from #orbis:structure/populate_init based on criteria. For example, the orbis ocean dungeon spawns water spawners because the spawner markers in the structure file have the gm4_water_spawner tag. The difference with structure markers is that multiple chests and spawners need to be set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment