Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot can't take item from chest #3400

Closed
nikitapro225 opened this issue Jun 17, 2024 · 2 comments
Closed

Bot can't take item from chest #3400

nikitapro225 opened this issue Jun 17, 2024 · 2 comments
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f

Comments

@nikitapro225
Copy link

nikitapro225 commented Jun 17, 2024

const mineflayer = require('mineflayer');
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder');
const GoalBlock = goals.GoalBlock;
var vec3 = require('vec3');
const webgui = require('mineflayer-web-inventory');
const Inventory = mineflayer.Inventory;
bot = mineflayer.createBot({
    host: 'localhost',
    port: 25565,
    username: 'Bot',
    version: '1.12.2'
})
webgui(bot)
bot.loadPlugin(pathfinder);
bot.on('login', () => {
    console.log('\x1b[42m\x1b[30m[+] Logged in');
})
let java = '';
let isBusy = false;
bot.on('whisper', (username, message, rawMessage) => {
    const args = message.split(' ');
    if (args[0] === 'kit') {
        if (args.length === 4) {
            const x = parseInt(args[1]);
            const y = parseInt(args[2]);
            const z = parseInt(args[3]);
            
            if (isNaN(x) || isNaN(y) || isNaN(z)) {
                bot.whisper(username, 'Invalid coordinates. Please enter valid numbers for x, y, and z.');
            } else {
                if (bot.pathfinder.isMoving()){
                    bot.whisper(username, 'I\'m busy right now. Please try again later.');
                } else {
                    java = username;
                    console.log(`\x1b[42m\x1b[30m[+] Delivery! ${x}, ${y}, ${z}`);
                    //bot.whisper(username, `Kit coordinates: `);
                    isBusy = true;
                    const targetBlock = new vec3(-131, 71, -194);
                    const block = bot.blockAt(targetBlock);
                    if (block && block.type === 54) { // 54 is the block ID for a chest
                        bot.openChest(block);
                    } else {
                        console.error(`Cannot find a chest at ${targetBlock.x}, ${targetBlock.y}, ${targetBlock.z}`);
                        bot.whisper(username, 'Cannot find a chest at the specified coordinates.');
                    }
                    bot.once('chest_open', (chest) => {
                        const shulkerBoxSlot = chest.findInventoryItem('purple_shulker_box');
                        if (shulkerBoxSlot) {
                            const shulkerBox = chest.takeItem(shulkerBoxSlot.index);
                            console.log(shulkerBox);
                            bot.equip(shulkerBox, 'hand', () => {
                                const goal = new GoalBlock(x, y, z);
                                bot.pathfinder.setGoal(goal);
                                bot.once('goal_reached', () => {
                                    bot.placeBlock(x, y+1, z, 'shulker_box');
                                    isBusy = false;
                                    bot.whisper(username, 'Done!');
                                });
                            });
                        }
                    });
                    bot.whisper(username, 'I\'m going to you');
                }
                 // set busy to false after 5 seconds
            }
        } else {
            bot.whisper(username, 'Invalid kit command. Usage: kit <x> <y> <z>');
        }
    }
})
@nikitapro225 nikitapro225 added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Jun 17, 2024
@extremeheat
Copy link
Member

Not enough information

@extremeheat extremeheat closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2024
@nikitapro225
Copy link
Author

Not enough information

I fix my code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f
Projects
None yet
Development

No branches or pull requests

2 participants