#distance between entity and ground

1 messages · Page 1 of 1 (latest)

neat hinge
#

Is there a way to return the distance between the ground and an entity (its height relative to the ground) ?

ruby pilot
ruby pilot
#
import {world, system} from '@minecraft/server'

function entityHeight(dimension) {
    for (let e of world.getDimension(dimension).getEntities()) {
        if (e != undefined) {
            const eloc = e.location
            let currentBlock = world.getDimension(dimension).getBlock(eloc)
            for (let i = 0; i < 320; i++) {
                let nextBlock = currentBlock.below(1)
                if (nextBlock.isAir == false) {
                    world.sendMessage(`${i} ${e.typeId}`)
                    break;
                } else {
                    currentBlock = nextBlock
                }
            }
        }
    }
}

const dimensions = [
    "nether", "overworld", "the_end"
]

system.runInterval(()=> dimensions.forEach(dimension => {entityHeight(dimension); }),10)
ruby pilot
#

this function only gets int numbers for height if you want it to be also for decimals you have to use y instead of block.below(1)

ruby pilot
wheat ravine
wheat ravine
faint inlet