Crafting API

The objd_crafting extension for objD gives you a customizable API for a Craftingtable, that works with nbt data. This documentation focuses on the CraftingTable and Recipe Widgets and generating a crafting package with objD. If you want to use template packages or the online generator, take a look at this article: https://stevertus.com/tools/objd_crafting

Installation

To install the crafting module just include objd_crafting in the pubspec.yaml:

dependencies:
  ...
  objd_crafting:
  ...

CraftingTable

The CraftingTable is the core widget to instantiate a custom crafter. It generates a pack(with a custom namespace) itself as well as the needed functions depending on the inputs. The Crafter is a modified chest with an armorstand inside to implement the logic.

Constructor(all optional)
nameyour custom namespace for the pack and all the scores
displayNamea TextComponent for the name that is displayed in the GUI
idthe starting id of your recipes(automatically increases)
recipesa list of your recipes
recipeSourceanother file location for a recipe function
recipeResultSourceanother file location for the result function
placeholderan Item that blocks all the slots that are not used
guiModelan Item that is retextured to display a GUI; replaces a placeholder by specifing the Slot of the Item
blockModelreplaces the head slot of the Armorstand to display a model for the block
invisibleHitboxbool whether to include code to make the chest invisible(default = true)
useBarrelset to true if you want to use a barrel instead
giveCommandFunctionbool whether to include a function to generate recipes in minecraft
maina List of Widgets that are executed every tick
onDestroya Widget that is executed when the crafting table is destroyed

After you specified all your wanted options and visuals, you get a fully working datapack. Ingame run the set function to create a new craftingtable at the current location. Obviously you can also trigger this with other packs as well. In this craftingtable you can then use your specified recipes.

Recipes

The recipes of a craftingtable are instantiated in the recipes field. A basic recipe takes in ingredient Items with the slot and a result Item.

Recipe
Map<slot,Item>The ingredients as a Map with the Slot(1 to 9) on the one side and your Item on the other
Itemyour result Item
idoverrides the automatically generated id(optional)
exactlyPlacedbool that requires to leave all unused slots empty(default = false)
exactResulta number that limits the result count(optional)

Example:

Recipe(
          {
            1: Item(Block.oak_planks),
            2: Item(Block.oak_planks),
            4: Item(Block.oak_planks),
            5: Item(Block.oak_planks),
          },
          Item(Block.crafting_table,Count:2,nbt:{"MyNBT":1})
)

You can also set the Count variable of any of the items to generate a ratio. In this case you craft 2 craftingtables out of 4 oak_planks.

Recipe.shapeless

The API also supports shapeless crafting. That means you can set the ingredients in any shape and it would be the same result.

Recipe.shapeless
ListThe ingredients in any shape(without slots)
...stays the same

Example:

Recipe.shapeless(
    [
       Item(Block.oak_planks),
       Item(ItemType.diamond)
    ],
    Item(ItemType.diamond_sword)
)

Recipe.fromJson

With objD you can also import usual minecraft recipes in json data. objD automatically parses that and converts it to a command.

Recipe.fromJson
MapThe recipe in json form
...stays the same

Example:

Recipe.fromJson(
  {
	"type": "minecraft:crafting_shaped",
    "pattern": [
      "## ",
      "## ",
      "   "
    ],
    "key": {
      "#": {"item": "minecraft:oak_planks"}
    },
    "result": {
	    "item": "minecraft:crafting_table",
	    "Count": 2
	    "nbt": {
				"MyNBT":1
		}
    }
  }
)

Which would result into the same recipe as the beginning. Also note that the json is extended by the Count and nbt properties as well.

Example with shapeless crafting:

Recipe.fromJson(
{
    "type": "minecraft:crafting_shapeless",
    "ingredients": [
        {
            "item": "minecraft:oak_planks"
        },
        {
            "item": "minecraft:diamond"
        }
    ],
    "result": {
        "item": "minecraft:diamond_sword"
    }
}
)

Libraries

checkarea
chestfile
craftingtable
dropitem
getcommand
objd_crafting
Support for doing something awesome. [...]
placeholder_setdetect
recipe
setarmorstand