MCPcopy
hub / github.com/PrismarineJS/mineflayer / craftOnce

Function craftOnce

lib/plugins/craft.js:36–201  ·  view source on GitHub ↗
(recipe, craftingTable)

Source from the content-addressed store, hash-verified

34 }
35
36 async function craftOnce (recipe, craftingTable) {
37 if (craftingTable) {
38 if (!windowCraftingTable) {
39 bot.activateBlock(craftingTable)
40 const [window] = await once(bot, 'windowOpen')
41 windowCraftingTable = window
42 }
43 if (!windowCraftingTable.type.startsWith('minecraft:crafting')) {
44 throw new Error('crafting: non craftingTable used as craftingTable: ' + windowCraftingTable.type)
45 }
46 await startClicking(windowCraftingTable, 3, 3)
47 } else {
48 await startClicking(bot.inventory, 2, 2)
49 }
50
51 async function startClicking (window, w, h) {
52 const extraSlots = unusedRecipeSlots()
53 let ingredientIndex = 0
54 let originalSourceSlot = null
55 let it
56 if (recipe.inShape) {
57 it = {
58 x: 0,
59 y: 0,
60 row: recipe.inShape[0]
61 }
62 await clickShape()
63 } else {
64 await nextIngredientsClick()
65 }
66
67 function incrementShapeIterator () {
68 it.x += 1
69 if (it.x >= it.row.length) {
70 it.y += 1
71 if (it.y >= recipe.inShape.length) return null
72 it.x = 0
73 it.row = recipe.inShape[it.y]
74 }
75 return it
76 }
77
78 async function nextShapeClick () {
79 if (incrementShapeIterator()) {
80 await clickShape()
81 } else if (!recipe.ingredients) {
82 await putMaterialsAway()
83 } else {
84 await nextIngredientsClick()
85 }
86 }
87
88 async function clickShape () {
89 const destSlot = slot(it.x, it.y)
90 const ingredient = it.row[it.x]
91 if (ingredient.id === -1) return nextShapeClick()
92 if (!window.selectedItem || window.selectedItem.type !== ingredient.id ||
93 (ingredient.metadata != null &&

Callers 1

craftFunction · 0.85

Calls 2

onceFunction · 0.85
startClickingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…