#How do I get the position of the block I'm looking at?

1 messages ยท Page 1 of 1 (latest)

sweet spire
#

I wanted to get the position of the block I'm looking at within a radius of up to 20 blocks

dreamy wasp
timber cave
simple swallow
simple swallow
simple swallow
sweet spire
#

I try with entity but it generates error

timber cave
sweet spire
timber cave
timber cave
dreamy wasp
#

?!

timber cave
#

what the fuck?

sweet spire
#

Just a minute

#

@timber cave

#
world.afterEvents.itemStartUse.subscribe(data => {
  const player = data.source
  const item = data.itemStack
  const entityInView = player.getEntitiesFromViewDirection({ maxDistance: 60 })[0]
  const blockInView = player.getBlockFromViewDirection({ maxDistance: 60 })?.block

  if (item.typeId == "sakuta:test") {
    const px = player.location.x
    const py = player.location.y
    const pz = player.location.z
    
    let newDist = 0

    if (blockInView != undefined) {
      newDist = Math.sqrt(Math.pow(blockInView.x - px, 2) + Math.pow(blockInView.y - py, 2) + Math.pow(blockInView.z - pz, 2))
    }

    if ((currentDist <= 8 && newDist >= 4) || hasTarget == false) {
      if (entityInView == undefined && blockInView == undefined) return

      hasTarget = true

      if (entityInView) {
        player.setDynamicProperty("target_position_x", entityInView.location.x)
        player.setDynamicProperty("target_position_y", entityInView.location.y)
        player.setDynamicProperty("target_position_z", entityInView.location.z)
      } else if (blockInView) {
        player.setDynamicProperty("target_position_x", blockInView.x)
        player.setDynamicProperty("target_position_y", blockInView.y)
        player.setDynamicProperty("target_position_z", blockInView.z)
      }  
    } else {
      useTrigger = true
    }
  }
})
dreamy wasp
#
const entityInView = player.getEntitiesFromViewDirection({ maxDistance: 60 })[0]?.entity
sweet spire
#

Thanks

timber cave
#

serty is the best

dreamy wasp
timber cave
#

lol

marsh oasis
dreamy wasp
timber cave
#

okay

dreamy wasp
#

I can find mistakes in others, but I can't even write myself....

marsh oasis