Level.getHighestBlockAt() returns 0
I want to teleport a player to a new location
int x = 5438693;
int z = -261848;
int y = player.getLevel().getHighestBlockAt(x, z);
player.teleport(new Position(x, y + 1, z));
But sometimes y is 0 and the player suffocated in a bedrock block.
Expected Behavior
getHighestBlockAt() returns a valid height value.
An exception should be thrown if the value can't be calculated.
Actual Behavior
getHighestBlockAt() returns sometimes 0.
Steps to Reproduce
I found out that the problem occurred when the chunk needs to be loaded because it is not yet in the cache.
Debug information
https://hastebin.com/robeyuyapa
Crashdump, Backtrace or Other Files
Checklist:
- [X] I included a
/debugpastelink - [X] I made sure there aren't duplicates of this report (Use Search)
- [X] I made sure I am using an up-to-date version of Nukkit
- [X] I Made sure the bug/error is not caused by a plugin
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Can confirm
this is due to the fact that the internal heightmap cache is almost entirely unimplemented. i'd advise simply iterating from y=255 to y=0 to find the highest non-air block.
I just wanted to confirm it. 😉 Anyway thanks for tip!
this is due to the fact that the internal heightmap cache is almost entirely unimplemented. i'd advise simply iterating from y=255 to y=0 to find the highest non-air block.
int x = 5438693;
int z = -261848;
Level level = player.getLevel();
for (int y = 255; y >= 0; y--) {
Block block = level.getBlock(x, y, z);
if (block.getId() != 0) {
return y; // never reached!
}
}
Doesn't work for me.
EDIT
It worked after I used the teleport command
/tp 5438693 70 -261848
It seems that this tp command does some kind of "preparation" which is required for my plugin to work correctly. How can I do this programmatically?