feat(informer): add reverse mcdata lookup by block or item id

This commit is contained in:
jay 2021-05-11 14:44:22 +05:00
parent 3c9d62441f
commit 69b1ab0b0b

View File

@ -133,6 +133,22 @@ function entity(name) {
return entity return entity
} }
function blockOrItemFromId(num, quiet = cfg.info.quiet) {
const block = mcData?.blocks[num]
const item = mcData?.items[num]
// const entity = mcData?.entities[num]
if (block || item) {
quiet || bot.chat(
(block && `block: ${block.name}, ` || "")
+ (item && `item: ${item.name}, ` || "")
// + (entity && `entity: ${entity.name}, ` || "")
)
} else {
quiet || bot.chat("info: nonexistent block or item")
}
return { block, item }
}
function command(message_parts, player) { function command(message_parts, player) {
if (message_parts.length > 0) { if (message_parts.length > 0) {
cfg.info.recentCommand = message_parts cfg.info.recentCommand = message_parts
@ -166,8 +182,15 @@ function command(message_parts, player) {
break break
case "b": case "b":
case "block": case "block":
default:
block() block()
break
default:
const num = parseInt(message_parts[0])
if (isFinite(num)) {
blockOrItemFromId(num)
} else {
quiet || bot.chat("info usage: `!info [me|i|e|b|<num>|quiet]`")
}
break; break;
} }