diff --git a/lib/plugins/informer.js b/lib/plugins/informer.js index cc1f726..905a46d 100644 --- a/lib/plugins/informer.js +++ b/lib/plugins/informer.js @@ -16,18 +16,38 @@ function block(pos) { } function item( - // hand - loc = bot.quickBarSlot + slot, + entity = bot.entity ) { - const item = bot.inventory.slots[loc + bot.QUICK_BAR_START] + const item = slot ? + bot.inventory.slots[parseInt(slot) + bot.QUICK_BAR_START] : + entity.heldItem console.log(item) if (!item) { cfg.quiet || bot.chat("no item") return item } let info = [item.type, item.name] - if (item.metadata) info.push(item.metadata) - cfg.quiet || bot.chat(info.join(": ")) + 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 } function entity(name) {