feat(informer): add item info based on player

Change the parameter order of `item` function to accomodate this
This commit is contained in:
jay 2021-05-10 17:52:53 +05:00
parent 25faac2f4c
commit 360eeff02f

View File

@ -35,18 +35,18 @@ function block(entity = bot.entity, pos = entity?.position?.offset(0, -1, 0)) {
} }
function item( function item(
slot, entity = bot.entity,
entity = bot.entity slot = entity.heldItem
) { ) {
const item = slot ? const item = typeof slot === "number" ?
bot.inventory.slots[parseInt(slot) + bot.QUICK_BAR_START] : bot.inventory.slots[slot + bot.QUICK_BAR_START] :
entity.heldItem slot
console.log(item) console.log("info item:", item)
if (!item) { if (!item) {
quiet || bot.chat("no item") quiet || bot.chat("no item")
return item return item
} }
let info = [item.type, item.name] let info = [item.type, item.name, item.count]
if (item.metadata) info.push("meta: " + item.metadata.length) if (item.metadata) info.push("meta: " + item.metadata.length)
if (item.nbt) { if (item.nbt) {
info.push(compound_value(item.nbt)) info.push(compound_value(item.nbt))
@ -130,7 +130,15 @@ function command(message_parts, player) {
switch (message_parts[0]) { switch (message_parts[0]) {
case "i": case "i":
case "item": case "item":
item(message_parts[1]) switch (message_parts[1]) {
case "me":
item(player)
break
default:
const slot = parseInt(message_parts[1])
slot && item(undefined, slot)
break
}
break break
case "b": case "b":
case "block": case "block":