A high-level, general purpose and modular minecraft bot using hot re-loadable (without restarting the bot!) plugins. Batteries included, launch to run!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

87 lines
2.0 KiB

let cfg
let bot
let mcData
const v = require('vec3')
function block(pos) {
const block = pos ? bot.blockAt(v(pos)) : bot.blockAtCursor()
console.log(block)
if (!block) {
cfg.quiet || bot.chat("empty")
return block
}
let info = [block.type, block.name]
if (block.metadata) info.push(block.metadata)
cfg.quiet || bot.chat(info.join(": "))
}
function item(
// hand
loc = bot.quickBarSlot
) {
const item = bot.inventory.slots[loc + bot.QUICK_BAR_START]
console.log(item)
let info = [item.type, item.name]
if (item.metadata) info.push(item.metadata)
cfg.quiet || bot.chat(info.join(": "))
}
function entity(name) {
const entity = bot.nearestEntity((entity) => {
return name && entity.name ? entity.name == name : true
})
console.log(entity)
let info = [entity.type, entity.name]
if (entity.metadata) info.push("len: " + entity.metadata.length)
cfg.quiet || bot.chat(info.join("; "))
}
function command(message_parts) {
switch (message_parts.length) {
case 0:
// TODO most recent command?
block()
break;
case 1:
switch (message_parts[0]) {
case "item":
item()
break
case "entity":
entity()
break
case "block":
default:
block()
break;
}
break;
case 4:
switch (message_parts[0]) {
case "block":
default:
block(message_parts.slice(1))
break;
}
break;
default:
break;
}
}
const load = (config) => {
cfg = config
bot = cfg.bot
cfg.info = {
quiet: cfg.quiet,
}
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
}
const unload = () => {}
module.exports = { load, unload, command, block, item, entity }