Structures in Eldertal

What are Structures?

Structures are predefined, 3D constructs made of blocks that can be placed manually or generated dynamically in the Eldertal world. They allow for the creation of trees, buildings, ruins, rocks, and other complex objects that can appear consistently.

What can Structures be used for?

Structures have various applications within the game:

  • Generating natural elements like trees, rocks, or caves.
  • Creating dynamic level environments with ruins, villages, or fortresses.
  • Procedural decoration of biomes with plants, mushrooms, or crystals.
  • Custom structures for adventure maps or modding projects.

JSON as a Format for Structures

Structures in Eldertal are stored in JSON format. JSON (JavaScript Object Notation) is a simple, human-readable format that makes defining block structures easy.

Structure of a Structure File

Each structure is stored as a JSON file and consists of three main components:

1. mapping (Block Assignment)

"mapping": {
    "0": ["AIR"],
    "1": ["STONE"],
    "2": ["TREE_OAK"],
    "3": ["TREE_OAK_LEAF"]
}
  • The mapping section assigns numbers to specific block types.
  • In the layouts, these numbers are referenced.
  • Example: 1 represents STONE, 2 represents TREE_OAK.

2. condition (Placement Conditions)

"condition": "height > 5;offset;random<-1,100000"
  • Defines the conditions under which the structure appears in the world.
  • height > 5 → The structure only appears if the ground height is greater than 5.
  • random<-1,100000 → A random value within the range -1 to 100000 determines placement probability.

3. layouts (Layered Structure Design)

"layouts": {
    "0": [
        [0, 0, 0, 0, 0],
        [0, 1, 1, 1, 0],
        [0, 1, 2, 1, 0],
        [0, 1, 1, 1, 0],
        [0, 0, 0, 0, 0]
    ],
    "1": [
        [0, 0, 2, 0, 0],
        [0, 2, 3, 2, 0],
        [2, 3, 3, 3, 2],
        [0, 2, 3, 2, 0],
        [0, 0, 2, 0, 0]
    ]
}
  • The layouts section defines the structure’s layers.
  • Each layer is stored as a 2D array.
  • Each number corresponds to a block from the mapping section.
  • Multiple layers are represented by "0", "1", "2" etc. → from bottom to top.

Creating Your Own Structures

1. Prepare a JSON File

  • Create a new file in the user://structures/ directory.
  • Name it, e.g., my_structure.json.

2. Define the Basic Structure

{
  "mapping": {},
  "condition": "",
  "layouts": {}
}
  • Fill in the sections with your definitions.

3. Define Blocks in mapping

"mapping": {
    "0": ["AIR"],
    "1": ["STONE"],
    "2": ["WOOD"],
    "3": ["LEAF"]
}

4. Design the Layers

"layouts": {
    "0": [
        [0, 0, 1, 0, 0],
        [0, 1, 2, 1, 0],
        [1, 2, 2, 2, 1],
        [0, 1, 2, 1, 0],
        [0, 0, 1, 0, 0]
    ],
    "1": [
        [0, 0, 2, 0, 0],
        [0, 2, 3, 2, 0],
        [2, 3, 3, 3, 2],
        [0, 2, 3, 2, 0],
        [0, 0, 2, 0, 0]
    ]
}
  • This example has 2 layers.
  • The second layer ("1") adds leaves (3).

5. Save the JSON File

  • Save the file in user://structures/.

6. Load the Structure into the Game

  • Start Eldertal and reload the world.
  • If the structure does not appear:
    • Validate the JSON with a JSON validator.
    • Check the condition (e.g., height > 10 may be too restrictive).
    • Test with a smaller structure.

Conclusion

Structures in Eldertal allow for procedural generation of buildings, trees, and formations. They are defined using JSON, are highly customizable, and enable exciting modular content for the game! 🚀