1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| async function findAllChests(bot: Bot, direction: 'left' | 'right'): Promise<Vec3[]> { const chest_id = bot.getMCData().blocksByName['chest'].id; return bot.getBot().findBlocks({ matching: function (block: Block) { return block.type === chest_id && (block.getProperties().type === 'single' || block.getProperties().type === 'left'); }, useExtraInfo: true, maxDistance: 64, count: 100 }); }
async function openChest(bot: Bot, chestPostionVec3: Vec3) { const chest = bot.getBot().blockAt(chestPostionVec3); await bot.getBot().pathfinder.goto(new GoalNear(chestPostionVec3.x, chestPostionVec3.y, chestPostionVec3.z, 1));
if (chest) { bot.logger.info('open chest:', chestPostionVec3); try { let chestWindow = await bot.getBot().openContainer(chest); let items = chestWindow.containerItems(); bot.logger.info('chest position: ', chestPostionVec3, 'items:', items.map(item => item.customName? item.customName : item.name)); bot.getBot().closeWindow(chestWindow); } catch (error) { bot.logger.error('Failed to open chest\n', error); } } }
async function scanChest(bot: Bot, direction: 'left' | 'right') { let chests = await findAllChests(bot, direction); bot.logger.info('Found chests: ' + chests.length, chests); for (let chest of chests) { await openChest(bot, chest); } }
|