Won't recognise item id and deposit into chest #2746
Unanswered
Wierdwizard2587
asked this question in
Q&A
Replies: 1 comment
-
Use mcData or search by name instead of hardcoding IDs |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hey all, am making a mining bot and on command the bot will return to a predesignated spot, open the nearest chest and deposit the diamonds it mined into the chest.
only the Chest opens but it doesn't recognize the diamond id number and won't deposit them.
I've started learning Javascript specifically for minelayer and don't have much experience but can't figure it out.
been stuck on this one for a long time so any help would be much appreciated
`const mineflayer = require('mineflayer')
const { pathfinder, Movements } = require('mineflayer-pathfinder')
const { GoalGetToBlock } = require('mineflayer-pathfinder').goals
const toolPlugin = require('mineflayer-tool').plugin
var vec3 = require('vec3');
botOptions = {
host: 'localhost',
port: 25565,
username: "Dmd_MinerBot_1"
}
const bot = mineflayer.createBot(botOptions)
bot.loadPlugin(pathfinder)
bot.loadPlugin(toolPlugin)
async function findAndMine(id){
const block = bot.findBlock({ matching: id, maxDistance: 50000 })
if (block){
const promiseHack = new Promise((res,rej)=>{
bot.once('goal_reached', (goal) => {
if (!bot.canDigBlock(block)){
throw new Error("unable to reack block")
}
bot.tool.equipForBlock(block)
bot.dig(block,false)
bot.once("diggingCompleted",(block)=>{
res()
})
})
bot.pathfinder.setGoal(new GoalGetToBlock(block.position.x, block.position.y, block.position.z))
})
await promiseHack
console.log("promise")
return
} else {
throw new Error("no block found")
}
}
bot.on("diggingAborted",(block)=>{
console.log("diggingAborted")
})
bot.on("diggingCompleted",(block)=>{
console.log("diggingCompleted")
})
function putaway() {
}
bot.on('whisper', (username, message, rawMessage) => {
console.log("i got the whisper")
if (message === 'mine d') {
const mcData = require('minecraft-data')(bot.version)
const moves = new Movements(bot, mcData)
bot.pathfinder.setMovements(moves)
})
bot.on('whisper', (username, message, rawMessage) => {
if (message === 'deposit') {
const mcData = require('minecraft-data')(bot.version);
const movements = new Movements(bot, mcData);
movements.scafoldingBlocks = [];
bot.pathfinder.setMovements(movements);
})
async function depositItem () {
let diamond = bot.inventory.findInventoryItem(264);
let amount = bot.inventory.count('diamond')
bot.chat(amount)
if (diamond) {
try {
await chest.deposit(264, null, amount)
bot.chat(
deposited
)} catch (err) {
bot.chat(
unable to deposit
)}
} else {
bot.chat(
unknown item
)}
}
`
Thanks for any Help!
Beta Was this translation helpful? Give feedback.
All reactions