2020-12-25 02:17:54 +00:00
|
|
|
let cfg
|
|
|
|
let bot
|
|
|
|
let mcData
|
2021-01-17 08:02:05 +00:00
|
|
|
const v = require('vec3')
|
2020-12-25 02:17:54 +00:00
|
|
|
|
2021-01-17 08:02:05 +00:00
|
|
|
function block(pos) {
|
|
|
|
const block = pos ? bot.blockAt(v(pos)) : bot.blockAtCursor()
|
2021-01-17 10:54:31 +00:00
|
|
|
console.log(block, block && block.getProperties())
|
2021-01-17 07:20:49 +00:00
|
|
|
if (!block) {
|
2021-01-17 11:16:41 +00:00
|
|
|
cfg.quiet || bot.chat("empty block")
|
2021-01-17 07:20:49 +00:00
|
|
|
return block
|
|
|
|
}
|
2021-01-05 04:20:35 +00:00
|
|
|
let info = [block.type, block.name]
|
2021-01-17 10:54:31 +00:00
|
|
|
if (block.metadata) info.push(Object.entries(block.getProperties()))
|
2021-01-05 04:20:35 +00:00
|
|
|
cfg.quiet || bot.chat(info.join(": "))
|
2020-12-25 02:17:54 +00:00
|
|
|
}
|
|
|
|
|
2021-01-16 09:51:49 +00:00
|
|
|
function item(
|
2021-01-17 20:24:47 +00:00
|
|
|
slot,
|
|
|
|
entity = bot.entity
|
2021-01-16 09:51:49 +00:00
|
|
|
) {
|
2021-01-17 20:24:47 +00:00
|
|
|
const item = slot ?
|
|
|
|
bot.inventory.slots[parseInt(slot) + bot.QUICK_BAR_START] :
|
|
|
|
entity.heldItem
|
2021-01-16 09:51:49 +00:00
|
|
|
console.log(item)
|
2021-01-17 11:16:41 +00:00
|
|
|
if (!item) {
|
|
|
|
cfg.quiet || bot.chat("no item")
|
|
|
|
return item
|
|
|
|
}
|
2021-01-16 09:51:49 +00:00
|
|
|
let info = [item.type, item.name]
|
2021-01-17 20:24:47 +00:00
|
|
|
if (item.metadata) info.push("meta: " + item.metadata.length)
|
|
|
|
if (item.nbt) {
|
|
|
|
info.push(compound_value(item.nbt))
|
|
|
|
}
|
|
|
|
cfg.quiet || bot.chat(info.join("; "))
|
|
|
|
function compound_value(obj) {
|
|
|
|
if (typeof obj.value == "object") {
|
|
|
|
return compound_value(obj.value)
|
|
|
|
} else if (obj.value) {
|
|
|
|
return obj.value
|
|
|
|
} else if (typeof obj == "object") {
|
|
|
|
const keys = Object.keys(obj)
|
|
|
|
return keys.map(key => {
|
|
|
|
return `${key}: ${compound_value(obj[key])}`
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return item
|
2021-01-16 09:51:49 +00:00
|
|
|
}
|
|
|
|
|
2021-01-16 11:17:42 +00:00
|
|
|
function entity(name) {
|
|
|
|
const entity = bot.nearestEntity((entity) => {
|
2021-01-17 13:32:05 +00:00
|
|
|
const ename = entity.name || entity.username
|
|
|
|
return name && ename ? ename == name : true
|
2021-01-16 11:17:42 +00:00
|
|
|
})
|
|
|
|
console.log(entity)
|
2021-01-17 11:16:41 +00:00
|
|
|
if (!entity) {
|
|
|
|
cfg.quiet || bot.chat("no entity")
|
|
|
|
return entity
|
|
|
|
}
|
2021-01-17 13:32:05 +00:00
|
|
|
let info = [entity.type, entity.name || entity.username]
|
2021-01-16 11:17:42 +00:00
|
|
|
if (entity.metadata) info.push("len: " + entity.metadata.length)
|
|
|
|
cfg.quiet || bot.chat(info.join("; "))
|
|
|
|
}
|
|
|
|
|
2021-01-05 06:32:33 +00:00
|
|
|
function command(message_parts) {
|
|
|
|
switch (message_parts.length) {
|
|
|
|
case 0:
|
2021-01-17 08:02:05 +00:00
|
|
|
// TODO most recent command?
|
|
|
|
block()
|
|
|
|
break;
|
2021-01-05 06:32:33 +00:00
|
|
|
case 1:
|
|
|
|
switch (message_parts[0]) {
|
2021-01-16 09:51:49 +00:00
|
|
|
case "item":
|
|
|
|
item()
|
|
|
|
break
|
2021-01-16 11:17:42 +00:00
|
|
|
case "entity":
|
|
|
|
entity()
|
|
|
|
break
|
2021-01-05 06:32:33 +00:00
|
|
|
case "block":
|
|
|
|
default:
|
|
|
|
block()
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-01-17 11:20:20 +00:00
|
|
|
case 2:
|
|
|
|
switch (message_parts[0]) {
|
|
|
|
case "item":
|
|
|
|
item(message_parts[1])
|
|
|
|
break
|
|
|
|
case "entity":
|
|
|
|
default:
|
|
|
|
entity(message_parts[1])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break
|
|
|
|
|
2021-01-17 08:02:05 +00:00
|
|
|
case 4:
|
|
|
|
switch (message_parts[0]) {
|
|
|
|
case "block":
|
|
|
|
default:
|
|
|
|
block(message_parts.slice(1))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2021-01-05 06:32:33 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-25 02:17:54 +00:00
|
|
|
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 = () => {}
|
|
|
|
|
2021-01-16 11:17:42 +00:00
|
|
|
module.exports = { load, unload, command, block, item, entity }
|