feat(informer): add block info based on player position or manually provided coords

This paves the way to get block info based on positions relative from the player
This commit is contained in:
jay 2021-05-07 16:27:44 +05:00
parent 050e2b3bd9
commit ccf0c598e8

View File

@ -14,13 +14,21 @@ let cfg = {
quiet: null,
bot: bot
}
function block(pos) {
const block = pos ? bot.blockAt(v(pos)) : bot.blockAtCursor()
console.log(block, block && block.getProperties())
function isVec3(vec) {
return this.x && this.y && this.z
}
function block(entity = bot.entity, pos = entity?.position?.offset(0, -1, 0)) {
console.assert(pos || entity)
const block = isVec3(pos) ? bot.blockAt(v(pos))
: pos
console.log(block, block?.getProperties && block.getProperties())
if (!block) {
quiet || bot.chat("empty block")
return block
}
bot.lookAt(block?.position)
let info = [block.type, block.name]
if (block.metadata) info.push(Object.entries(block.getProperties()))
quiet || bot.chat(info.join(": "))
@ -89,7 +97,7 @@ function command(message_parts, player) {
} else {
// TODO dispatch on instance of entity, block, etc..
// TODO have the logic inside the function or with a utility function
block(player.position || player?.entity.position || null)
block()
}
break;
case 1:
@ -106,6 +114,9 @@ function command(message_parts, player) {
case "entity":
entity()
break
case "me":
block(player)
break
case "b":
case "block":
default:
@ -134,7 +145,7 @@ function command(message_parts, player) {
case "b":
case "block":
default:
block(message_parts.slice(1))
block(undefined, message_parts.slice(1))
break;
}