[BUG] world.getTerrainData always returns 0

  • I can't wrap my head around this and trying to understand why I can't make it work is nothing but time consuming.


    This is what I try



    The value printed is always 0.

  • Hmm.. I was wondering about this, since the getTerrainData() function should work properly. But I found the issue in this case, "ChunkUtils:getChunkAndBlockPosition()" does not return the expected block position: The x, y and z values of the blockposition have an offset of two (it has technical reasons, since we use this function internally too). I already changed this (the fix will be available with the next update). In the meantime, you could subtract the value "2" from the blockposition as a workaround, like this:
    [lua]local terrainId = world:getTerrainData(chunkPos.x, chunkPos.y, chunkPos.z, blockPos.x - 2, blockPos.y - 2, blockPos.z - 2);[/lua]

  • Hmm.. I was wondering about this, since the getTerrainData() function should work properly. But I found the issue in this case, "ChunkUtils:getChunkAndBlockPosition()" does not return the expected block position: The x, y and z values of the blockposition have an offset of two (it has technical reasons, since we use this function internally too). I already changed this (the fix will be available with the next update). In the meantime, you could subtract the value "2" from the blockposition as a workaround, like this:
    [lua]local terrainId = world:getTerrainData(chunkPos.x, chunkPos.y, chunkPos.z, blockPos.x - 2, blockPos.y - 2, blockPos.z - 2);[/lua]


    I was wondering why the - 2 as I have seen this at a few places already.


    Cheers!

  • dont forget to also add at lest -0.5 onto the y or the plants will look as if they are floating so y will be - 2.5 in the end

    Yahgiggle Steam Signature, real name Deon Hamilton :thumbsup: Server @ ip 139.99.136.76:4255 Name (The Federation of territory) Unity :thumbsup:

    If at first your code does not work call it version 0.1 with the odd bug :thinking:

    My Own Website




    31245-logo-png
  • I was wondering why the - 2 as I have seen this at a few places already.


    That's because each chunk has room for the edge terraininformation (2 adjacent blocks) of its neighbour chunks (it's necessary for terraingeneration and faceculling). On the one hand it's necessary to generate all chunks at the "end of your view distance" without unnecessary chunk requests from the server, on the other hand it's due to performance reasons (adjacent block lookup is much faster compared to accessing a different chunk, though there is a tiny memory penalty, but the result is worth it^^).

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!