Skip to content

Commit

Permalink
feat: Support shaped crafting recipes
Browse files Browse the repository at this point in the history
Follow-up to #314. This patch implements parsing of recipe files with the
type "minecraft:crafting_shaped", including very complex recipes such as the
barrel (no, really - due to there being 12 types of wood in the game, there
are 12^8 = 429,981,696 ways to craft a barrel!), along with the required
checks when crafting grid slots are changed.

This means we now support 932 out of 978 crafting recipes, with the
remaining ones needing specialized implementations, such as keeping NBT
data when coloring shulker boxes or repairing tools by combining them.

In any case, it's now possible to go from logs to planks to a crafting table, and
also towards sticks and then torches or even a cobblestone pickaxe.
  • Loading branch information
meyfa committed Feb 1, 2025
1 parent 302804e commit f3f7228
Show file tree
Hide file tree
Showing 8 changed files with 849 additions and 292 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The following features are already working:
- [X] breaking and placing blocks
- [X] block interaction (right-clicking, e.g., to open doors)
- [X] player inventory
- [X] crafting, both 2x2 and 3x3 (however, not all recipes are supported, yet)
- [X] crafting, both 2x2 and 3x3
- [X] chat
- [X] commands (in-game and via an interactive console)
- [X] configuration via server.properties
Expand Down
29 changes: 29 additions & 0 deletions src/copybooks/DD-RECIPES.cpy
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
*> --- Copybook: crafting recipes ---

78 RECIPES-SHAPELESS-CAPACITY VALUE 1000.
78 RECIPES-SHAPED-CAPACITY VALUE 1000.
78 RECIPES-COMPLEX-CAPACITY VALUE 100.

01 RECIPES EXTERNAL.

02 RECIPES-SHAPELESS.
03 RECIPES-SHAPELESS-COUNT BINARY-LONG UNSIGNED.
*> For efficient lookup, shapeless recipes store their ingredients sorted by item protocol ID (descending),
Expand All @@ -13,3 +16,29 @@
04 RECIPE-SHAPELESS-OUTPUT.
05 RECIPE-SHAPELESS-OUTPUT-ID BINARY-LONG UNSIGNED.
05 RECIPE-SHAPELESS-OUTPUT-COUNT BINARY-LONG UNSIGNED.

02 RECIPES-SHAPED.
03 RECIPES-SHAPED-COUNT BINARY-LONG UNSIGNED.
*> Shaped recipes store their ingredients in a 3x3 grid, with the top-left corner being the origin. Slots are
*> enumerated from left to right, top to bottom. Recipes smaller than 3x3 (2x2, 1x2, 2x3, etc.) are padded with
*> zeroes to the right and bottom.
03 RECIPE-SHAPED OCCURS RECIPES-SHAPED-CAPACITY TIMES.
04 RECIPE-SHAPED-INPUTS.
05 RECIPE-SHAPED-INPUT OCCURS 9 TIMES BINARY-LONG UNSIGNED.
04 RECIPE-SHAPED-OUTPUT.
05 RECIPE-SHAPED-OUTPUT-ID BINARY-LONG UNSIGNED.
05 RECIPE-SHAPED-OUTPUT-COUNT BINARY-LONG UNSIGNED.

*> Some shaped recipes have too many combinatorial variations to store them all. For these, we cannot use the fast
*> lookup table above (with one entry per recipe), but must instead store the recipe as a list of options per slot.
*> For example, with 12 wood types, there are 20,736 ways to make a crafting table, or 429,981,696 for a barrel.
02 RECIPES-COMPLEX.
03 RECIPES-COMPLEX-COUNT BINARY-LONG UNSIGNED.
03 RECIPE-COMPLEX OCCURS RECIPES-COMPLEX-CAPACITY TIMES.
04 RECIPE-COMPLEX-INPUTS.
05 RECIPE-COMPLEX-INPUT OCCURS 9 TIMES.
06 RECIPE-COMPLEX-INPUT-OPTIONS BINARY-LONG UNSIGNED.
06 RECIPE-COMPLEX-INPUT-ID OCCURS 128 TIMES BINARY-LONG UNSIGNED.
04 RECIPE-COMPLEX-OUTPUT.
05 RECIPE-COMPLEX-OUTPUT-ID BINARY-LONG UNSIGNED.
05 RECIPE-COMPLEX-OUTPUT-COUNT BINARY-LONG UNSIGNED.
Loading

0 comments on commit f3f7228

Please sign in to comment.