craft fix
This commit is contained in:
@@ -138,16 +138,24 @@ class Craft{
|
||||
|
||||
// Move these into openCrating function
|
||||
let windowOnce = (event)=> new Promise((resolve, reject)=> window.once(event, resolve));
|
||||
let inventory = ()=> window.slots.slice(window.inventoryStart, window.inventoryEnd)
|
||||
let inventory = window.slots.slice(window.inventoryStart, window.inventoryEnd);
|
||||
|
||||
// Move the items into the crafting grid
|
||||
// Keep track of used inventory slots to avoid reusing the same slot
|
||||
let usedInventorySlots = new Set();
|
||||
let slotCount = 1;
|
||||
for(let shapeRow of recipe.inShape){
|
||||
for(let shape of shapeRow){
|
||||
this.bot.bot.moveSlotItem(
|
||||
inventory().find((element)=> element && element.type === shape.id).slot,
|
||||
slotCount
|
||||
let inventorySlot = inventory.findIndex((element, index) =>
|
||||
element && element.type === shape.id && !usedInventorySlots.has(index)
|
||||
);
|
||||
if (inventorySlot === -1) {
|
||||
throw new Error(`Not enough items of type ${shape.id} in inventory`);
|
||||
}
|
||||
let actualSlot = window.inventoryStart + inventorySlot;
|
||||
usedInventorySlots.add(inventorySlot);
|
||||
|
||||
this.bot.bot.moveSlotItem(actualSlot, slotCount);
|
||||
await windowOnce(`updateSlot:${slotCount}`);
|
||||
slotCount++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user