Closed barbarbar338 closed 3 years ago
I had the same issue a few days ago. Right now there are a few issues with the chest interactions in collectblock. One is the goal type GoalBlock should be GoalGetToBlock as right now the bot is attempting to move to the position the chest occupies. I've mentioned this in pr 53 and I just made a focused pr for this issue #66 . Additionally there are issues with the way collectblock attempts to place items into the chest. In my opinion the steps forward are
p.s. I appreciate you adding logging. Would you mind showing an example output. I'm assuming that the bot doesn't reach its goal and therefore does not log 'goal_reached'.
it just spams "path_update" and does nothing (does not logs "goal_reached" or anything). When I tell bot to come to me with another "pathfinding" command when it is stuck where it is, im getting "PathfindingInterrupted: Pathfinding interrupted before item could be reached." error as it should be: https://i.imgur.com/dJmiC9b.png
Thanks. If you change the goal in function gotoChest in mineflayer-collectblock/lib/Inventory.js from
pathfinder.setGoal(new mineflayer_pathfinder_1.goals.GoalBlock(location.x, location.y, location.z));
to
pathfinder.setGoal(new mineflayer_pathfinder_1.goals.GoalGetToBlock(location.x, location.y, location.z));
You should find that the bot does emit 'goal_reached' now; however, it fails to empty its inventory.
as you said, it opens chest but says "TypeError: chest.once is not a function" open chest: https://i.imgur.com/Xur7ioW.png error and code: https://i.imgur.com/xndj7YR.png
API says "Returns a promise on a Container instance which represents the container you are opening.". Lemme see whats going on when use async await
i changed this line with (chest.items.length >= chest.inventoryStart)
and it stored one stack of items. but then gave "TypeError: Cannot read property 'type' of null": https://i.imgur.com/HuT5o9y.png - mineflayer/lib/plugins/inventory.js, line 223 (window.selectedItem comes "null")
also changed openChest
as openContainer
and used promises, here is the result:
// Inventory.js, line 87
function placeItems(bot, chestPos, itemFilter, cb) {
const chestBlock = bot.blockAt(chestPos);
if (chestBlock == null) {
cb(Util_1.error('UnloadedChunk', 'Chest is in an unloaded chunk!'), true);
return;
}
try {
let itemsRemain = false;
bot.openContainer(chestBlock).then(chest => {
const tryDepositItem = (item, cb) => {
// @ts-expect-error ; A workaround for checking if the chest is already full
console.log(chest);
if (chest.items().length >= chest.inventoryStart) {
// Mark that we have items that didn't fit.
itemsRemain = true;
cb();
return;
}
chest.deposit(item.type, item.metadata, item.count, cb);
};
const taskQueue = new mineflayer_utils_1.TaskQueue();
for (const item of bot.inventory.items()) {
if (itemFilter(item)) {
taskQueue.add(cb => tryDepositItem(item, cb));
}
}
taskQueue.addSync(() => chest.close());
taskQueue.runAll((err) => {
if (err != null) {
cb(err, true);
return;
}
cb(undefined, itemsRemain);
});
})
}
catch (err) {
// Sometimes open chest will throw a few asserts if block is not a chest
cb(err, true);
}
}
well, I tried putting items into the chest with the command and realized that the error was caused by the Mineflayer. sometimes it puts the items and sometimes gives this error: https://i.imgur.com/9LXOPvk.png
i'll create an issue on mineflayer
Once again I was wrong :D error was caused by the mineflayer-web-inventory
plugin. I found this issue and removed mineflayer-web-inventory
from my code and it worked :^)
i changed pathfinder.setGoal(new mineflayer_pathfinder_1.goals.GoalBlock(location.x, location.y, location.z));
to pathfinder.setGoal(new mineflayer_pathfinder_1.goals.GoalGetToBlock(location.x, location.y, location.z));
and placeItems to:
function placeItems(bot, chestPos, itemFilter, cb) {
const chestBlock = bot.blockAt(chestPos);
if (chestBlock == null) {
cb(Util_1.error('UnloadedChunk', 'Chest is in an unloaded chunk!'), true);
return;
}
try {
let itemsRemain = false;
bot.openChest(chestBlock).then(chest => { // used promise
const tryDepositItem = (item, cb) => {
// @ts-expect-error ; A workaround for checking if the chest is already full
if (chest.items().length >= chest.inventoryStart) { // removed window
// Mark that we have items that didn't fit.
itemsRemain = true;
cb();
return;
}
chest.deposit(item.type, item.metadata, item.count, cb);
};
const taskQueue = new mineflayer_utils_1.TaskQueue();
for (const item of bot.inventory.items()) {
if (itemFilter(item)) {
taskQueue.add(cb => tryDepositItem(item, cb));
}
}
taskQueue.addSync(() => chest.close());
taskQueue.runAll((err) => {
if (err != null) {
cb(err, true);
return;
}
cb(undefined, itemsRemain);
});
});
}
catch (err) {
// Sometimes open chest will throw a few asserts if block is not a chest
cb(err, true);
}
}
in mineflayer-collectblock/lib/Inventory.js
and it works
When i say "collect dirt", bot stays looking at the chests like this: https://i.imgur.com/UkAyi4t.png this is bot's inventory: https://i.imgur.com/hWk1IJt.png and this is my console: https://i.imgur.com/sND3VwT.png
i changed plugin's code to see what's going on and this is the code
my fetch chest code:
and my collect code: