Skip to content

JSON Fragment

Fragment is a reusable JSON element that can be attached to your Lychee recipes.

Define

All fragments should be defined in the lychee_fragment folder in a data pack, as a JSON file.

{
    "value": "Here can be any type of element"
}

Note

Fragments can be nested.

Use Fragment

First let's assume we have such a fragment:

mymod/lychee_fragment/gems.json
{
    "value": [
        {
            "type": "drop_item",
            "id": "diamond"
        },
        {
            "type": "drop_item",
            "id": "emerald"
        }
    ]
}

Replace the Current Element

{
    "post": {
        "@": "mymod:gems"
    }
}
{
    "post": [
        {
            "type": "drop_item",
            "id": "diamond"
        },
        {
            "type": "drop_item",
            "id": "emerald"
        }
    ]
}

Spread Elements to the Parent

{
    "post": [
        {
            "...@": "mymod:gems"
        },
        {
            "type": "prevent_default"
        }
    ]
}
{
    "post": [
        {
            "type": "drop_item",
            "id": "diamond"
        },
        {
            "type": "drop_item",
            "id": "emerald"
        },
        {
            "type": "prevent_default"
        }
    ]
}

Use Variables

You can define variables together with the fragment path, and reference it in the fragment.

{
    "comment": {
        "@": "mymod:comment",
        "name": "Fragment"
    },
    "post": [
        {
            "...@": "mymod:gems",
            "amount": 3
        },
        {
            "type": "prevent_default"
        }
    ]
}
{
    "value": [
        {
            "type": "drop_item",
            "id": "diamond",
            "count": "$amount"
        },
        {
            "type": "drop_item",
            "id": "emerald",
            "count": "$amount"
        }
    ]
}
{
    "value": "An example of ${name}"
}