feat(informer): ✨ add block info based on player's relative position
Relative position includes simple words like "feet", "standing", "head", etc
This commit is contained in:
parent
665102e19c
commit
3c9d62441f
|
@ -14,6 +14,54 @@ let cfg = {
|
|||
bot: bot
|
||||
}
|
||||
|
||||
var RelativePosEnum
|
||||
(function (RelativePosEnum) {
|
||||
RelativePosEnum[RelativePosEnum["feet"] = 0] = "feet"
|
||||
RelativePosEnum[RelativePosEnum["standing"] = 1] = "standing"
|
||||
RelativePosEnum[RelativePosEnum["head"] = 2] = "head"
|
||||
RelativePosEnum[RelativePosEnum["looking"] = 3] = "looking"
|
||||
RelativePosEnum[RelativePosEnum["infront"] = 4] = "infront"
|
||||
RelativePosEnum[RelativePosEnum["behind"] = 5] = "behind"
|
||||
})(RelativePosEnum || (RelativePosEnum = {}))
|
||||
|
||||
function relPosToBlock(entity, relPos) {
|
||||
let pos
|
||||
if (!(relPos in RelativePosEnum)) return console.warn("info: not a relative position:", relPos)
|
||||
relPos = typeof relPos === "number" ? RelativePosEnum[relPos] : relPos
|
||||
switch (relPos) {
|
||||
case "feet":
|
||||
pos = entity.position;
|
||||
break
|
||||
case "standing":
|
||||
pos = entity.position.offset(0, -1, 0)
|
||||
break
|
||||
// todo use CARDINAL directions api from pathfinder
|
||||
// case "behind":
|
||||
// entity.yaw
|
||||
// pos = entity.position
|
||||
// break
|
||||
// case "front":
|
||||
// case "infront":
|
||||
// pos = entity.position
|
||||
// break
|
||||
case "head":
|
||||
pos = entity.position.offset(0, 1.85, 0)
|
||||
break
|
||||
case "looking":
|
||||
if (entity === bot.entity) {
|
||||
return bot.blockAtCursor()
|
||||
// return bot.blockInSight(128, 128)
|
||||
}
|
||||
default:
|
||||
quiet || bot.chat(`info: pos '${relPos}' not implemented`)
|
||||
break
|
||||
}
|
||||
if (pos) {
|
||||
// nearest block
|
||||
return bot.blockAt(pos)
|
||||
}
|
||||
}
|
||||
|
||||
function isVec3(vec) {
|
||||
return vec?.length === 3 || vec.x && vec.y && vec.z
|
||||
}
|
||||
|
@ -21,7 +69,7 @@ function isVec3(vec) {
|
|||
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
|
||||
: typeof pos === "string" ? relPosToBlock(entity, RelativePosEnum[pos]) : pos
|
||||
console.log(block, block?.getProperties && block.getProperties())
|
||||
if (!block) {
|
||||
quiet || bot.chat("empty block")
|
||||
|
@ -146,8 +194,13 @@ function command(message_parts, player) {
|
|||
block(player)
|
||||
break
|
||||
default:
|
||||
console.log(bot.players[message_parts[1]])
|
||||
quiet || bot.chat("info: not yet implemented")
|
||||
if (message_parts[1] in RelativePosEnum) {
|
||||
block(undefined, message_parts[1])
|
||||
} else {
|
||||
// or entity(message_parts[1]).position
|
||||
console.log(bot.players[message_parts[1]])
|
||||
quiet || bot.chat("info: not yet implemented")
|
||||
}
|
||||
}
|
||||
break
|
||||
case "e":
|
||||
|
|
Loading…
Reference in New Issue
Block a user