Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Custom Crafting Table

Michael Weatherby edited this page Aug 25, 2020 · 17 revisions

Note: before starting, it is highly recommend you create- or at least know how to create- a simple dropper based custom crafting table. DU's table is essentially an extension of this system, and using the API will be much more straight forward if you are familiar with dropper based crafting.

The Datapack Utils custom crafting table API has a few advantages over others of its kind:

  • Chest/Barrel based, so the input and output are displayed at the same time like a normal crafting table
  • Accepts any item, including NBT data
  • Configurable cost amounts for each item
  • Output quantity is dynamically set proportional to amount of ingredients for fast crafting

How to Set Up a Custom Table

Datapack utils does not add its own table block- mostly because it doesn't have a resourcepack. Instead, you need to create your own. Summon an entity with the tag du_crafter at the location of a chest-like block (chest, barrel, shulkerbox, etc).

You can modify the marker entity however you like, for example having an armor stand wear a custom model. Any slots not used for crafting will be filled with gray stained glass panes. If you want to fill the unused slots with your own items, for example to add a custom UI texture, give the items the tag du_gui:1b (ie. replaceitem block ~ ~ ~ container.0 structure_block{CustomModelData:<some UI texture>,du_gui:1b}).

The next step is to create the function tag du:recipes/crafting and add your recipe function(s) to it. Note: do to this implementation, all custom tables can craft all custom recipes- even from other datapacks.

Creating recipes is roughly the same as dropper based crafting with a one key differences: leave out the Count NBT tag, and instead use provided scoreboard values for checking count when needed. If the check is successful, replaceitem your output in slot 16.

Example recipe:

execute if score $crafting.in_4 du_data matches 0 if block ~ ~ ~ #du:chest-like{Items:[{Slot:2b,id:"minecraft:cobblestone"},{Slot:3b,id:"minecraft:cobblestone"},{Slot:4b,id:"minecraft:cobblestone"},{Slot:11b,id:"minecraft:cobblestone"},{Slot:13b,id:"minecraft:cobblestone"},{Slot:20b,id:"minecraft:cobblestone"},{Slot:21b,id:"minecraft:cobblestone"},{Slot:22b,id:"minecraft:cobblestone"}]} run replaceitem block ~ ~ ~ container.16 furnace 1

Note the check for $crafting.in_4 du_data being 0. This verifies that the center slot is empty.

In order to make a slot consume multiple ingredients, first check that the slot has enough using scoreboards.

For example: execute if score $crafting.in_0 du_data matches 2.. if block...

Then set the $crafting.out_X du_data score to the needed amount, where x is the slot number.

Example of whole recipe:

execute if score $crafting.in_0 du_data matches 0 if score $crafting.in_2 du_data matches 0 if score $crafting.in_3 du_data matches 2.. if score $crafting.in_5 du_data matches 2.. if score $crafting.in_6 du_data matches 0 if score $crafting.in_8 du_data matches 0 if block ~ ~ ~ #du:chest-like{Items:[{Slot:3b,id:"minecraft:stick"},{Slot:11b,id:"minecraft:stick"},{Slot:12b,id:"minecraft:stick"},{Slot:13b,id:"minecraft:stick"},{Slot:21b,id:"minecraft:stone_slab"}]} run function du:custom_crafter/examples/armor_stand 

#in sub fucntion
replaceitem block ~ ~ ~ container.16 minecraft:armor_stand 2
scoreboard players set $crafting.out_3 du_data 2
scoreboard players set $crafting.out_5 du_data 2

Bellow are the [scoreboard operation numbers ($crafting.in_x and $crafting.out_x)]/[item slot numbers (Slot:Xb)]. Scoreboard numbers are for interacting with scoreboard variables, for example the first slot is $crafting.in_0 and $crafting.out_0. The item slot number is for making recipes, for example the fist slot is {Slot:2b,id:"minecraft:stick"}

layout

Relevant Code Locations