Nukkit icon indicating copy to clipboard operation
Nukkit copied to clipboard

Level.getHighestBlockAt() returns 0

Open gfiedler opened this issue 5 years ago • 4 comments

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 /debugpaste link
  • [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.

gfiedler avatar Jan 24 '20 18:01 gfiedler

Can confirm

Alemiz112 avatar Mar 05 '20 15:03 Alemiz112

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.

DaMatrix avatar Mar 05 '20 16:03 DaMatrix

I just wanted to confirm it. 😉 Anyway thanks for tip!

Alemiz112 avatar Mar 05 '20 17:03 Alemiz112

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?

gfiedler avatar Apr 04 '20 16:04 gfiedler