#how to use getEntitiesFromViewDirection()

1 messages · Page 1 of 1 (latest)

fossil fern
#

It always returns undefined (variable ent/Ent)

import {system,world,ItemStack} from '@minecraft/server';
import {ActionFormData,ModalFormData,MessageFormData} from '@minecraft/server-ui';

system.runInterval(() => {
  let Players = world.getAllPlayers()
  for(let player of Players){
    let b = player.getBlockFromViewDirection().block?.typeId
    let x = player.getBlockFromViewDirection().block?.location.x
    let y = player.getBlockFromViewDirection().block?.location.y
    let z = player.getBlockFromViewDirection().block?.location.z
    let ent = player.getEntitiesFromViewDirection().entity?.typeId
    let Ent = ent == "undefined" ? "§r" : `\n${ent}`
    
    player.onScreenDisplay.setActionBar(`${b}\n${x} ${y} ${z}${Ent}`)
  }
})
mortal otter
#

getEntitiesFromViewDirection returns an array

fossil fern
mortal otter
fossil fern
#

Nvm fixed,thank you