Programming in Minecraft. Another programming lesson on Python. GetHeight function
Join our group a programming school for children and teenagers https://vk.com/felikmine_programming
As you know, the y-coordinate of the player corresponds to the height on which it is located. Blocks are also tied to coordinates, which allows us to recognize their type using the getBlock () function and set it in a specific place using setBlocks ().
Hence, we can quite know the height of the uppermost block, which is in the coordinates x and z. The getHeight () function will help us in this.
Example 1. Suppose we have buildings of blocks and we know its coordinates x and z. By passing them to the getHeight () function, we can know the height of the entire tower. This function gives us the y-coordinate of the topmost block itself.
pos = mc.player.getTilePos () # player position
x = pos.x
y = pos.y
z = pos.z
elevation = mc.getHeight (x, z) # highest block
mc.postToChat (build height)
This code gets the player's current position, recognizes the y-coordinate of the highest block in its x- and z-coordinates and sends this value to the chat.
Example 2. Change the code so that it checks if the player's y-coordinate is higher than the height variable.
Then add the code to display the result of the test in the chat as a string "Player Above the Ground: True / False".