See the PDF version here.

Nbt Crafting 3 Proposal

Siphalor

About

Nbt Crafting 3 is meant to revamp Nbt Crafting to be more maintanable, easier to use and better to extend.

Key aspects of this release will contain:


Still missing from this document and especially needed feedback:

Modules

Ingredient types

If this makes the cut, this mod will no longer process ingredients preemptively but will look for a type property in ingredient objects.

It will look up the ingredient type in a registry and then run the specified deserializer.

{
    "ingredients": [
        {
            "type": "nbtcrafting:custom"
        }
    ]
}

Functions

Functions can be defined for recipe outputs and remainders. They iteratively transform the given stack in the given order.

They are extensibly defined in their own registry. For example KubeJS could hook into this and provide JavaScript expressions.

{
    "result": {
        "item": "hey",
        "nbtcrafting:functions": [
            {
                "type": "nbtcrafting:nbt_merge",
                "source": "i0"
            }
        ]
    }
}

nbtcrafting:nbt_set

This is equivalent to the current static data tag. This will always overwrite existing values at the given location.

nbtcrafting:nbt_list_insert

Allows to add elements to lists. Currently only achievable through merges.

nbtcrafting:nbt_remove

Allows to remove element(s) from objects or lists.

nbtcrafting:nbt_merge

Would be the equivalent of the current merge dollars.

nbtcrafting:count_set

Allows to set the count of the current stack. Will probably still be experimental because of how recipes work.

Better Path notation

The main goal of this redesign is to allow to target multiple elements.
This grants the chance to easily remove/change multiple values at once.

Thought: This could also allow to capture multiple values and concatenate them to a list.

Specification

Based on https://goessner.net/articles/JsonPath.

Operator Name Description
. child operator Allows access to child elements
[] array access operator Allows access to array elements
.. recursive descent Matches all children in the current element and recurses further operators
[,] array set Allows to specify a list of indices to capture
[(start):(end)(:step)] array slice Allows to capture a consecutive number of array elements between start (inclusive) and end (exclusive). Optionally each step-th element is captured
$ root element useful to capture all ingredients (e.g. $..Damage)

Note: regions in parenthesis are meant to be optional

Examples

Example Explanation
ingredient.Enchantments[0].id Gets the id of the first enchantment
ingredient.Enchantments[:].id Targets all enchantment ids
ingredient or ingredient.Damage Gets the Damage value
$..Damage Targets the Damage values of all ingredients

Hello, New World!

This section is meant to give an overview over the current state of this proposal and to visualize the suggested changes.

The example shapeless recipe consumes a diamond sword that has less than 40 damage and a diamond. It results in a diamond axe called “Battle Axe” which copies all the nbt data from the sword and additionally adds a sharpness enchantment at level 10.

The old world

{
    "type": "crafting_shapeless",
    "ingredients": [
        {
            "item": "minecraft:diamond_sword",
            "data": {
                "require": {
                    "Damage": "$..40"
                }
            }
        },
        { "item": "minecraft:diamond" }
    ],
    "result": {
        "item": "minecraft:diamond_axe",
        "data": {
            "display": {
                "Name": {
                    "text": "Battle Axe",
                    "nbtcrafting:strigify": true
                }
            },
            "Enchantments": [
                {
                    "id": "minecraft:sharpness",
                    "lvl": 10
                }
            ],
            "$": {
                "value": "i0",
                "paths": {
                    "/Enchantments\\[\\d+\\]/": "append"
                }
            }
        }
    }
}

The new world

{
    "type": "crafting_shapeless",
    "ingredients": [
        {
            "item": "minecraft:diamond_sword",
            "data": {
                "require": {
                    "Damage": "$..40"
                }
            }
        },
        { "item": "minecraft:diamond" }
    ],
    "result": {
        "item": "minecraft:diamond_axe",
        "nbtcrafting:functions": [
            {
                "type": "nbtcrafting:nbt_merge",
                "source": "i0"
            },
            {
                "type": "nbtcrafting:nbt_set",
                "target": "display.Name",
                "value": {
                    "text": "Battle Axe"
                },
                "stringify": true
            },
            {
                "type": "nbtcrafting:nbt_list_insert",
                "target": "Enchantments",
                "value": {
                    "id": "minecraft:sharpness",
                    "lvl": 10
                }
            }
        ]
    }
}