Identifying openings at any depth

  • So I'm mainly curious about ChunkLOD. This is exactly what I was looking for in order to possibly create a map mod. It provides all the info I need for a surface map, however I want to also make the mod for subterranian as well. I need to be able to retrieve the texture id at a given x,y,z position. I assume that a open cave would return a null value instead of a texture.


    Actually this might be more of a problem cause technically if you F2 thorugh a cave ceiling and hit F2 again you can technically stand ontop of the cave ceiling where in reality you would be inside solid rock. So behind the cave wall is the same as inside the cave, from a data perspective. Any other methods or is this technically not possible right now? I guess the block only design of Minecraft makes it much much easier to map out the subterranean.

  • Actually as @Miwarre suspected, the terrainData array in the Chunk class contains all necessary information to get the terrain id from a certain position (air is always 0). You could also use the surface array in the ChunkLOD class, although it's difficult to find out this way if there is really a cave or not. Here is the question: What is a cave? Or how do you find out that there is a cave? What's the difference between a cave or a hole in the ground, or a ravine for example?

  • Here is the question: What is a cave? Or how do you find out that there is a cave? What's the difference between a cave or a hole in the ground, or a ravine for example?

    This is the question indeed! :evil:


    It is going to be subjective. At the very minimum, I would qualify as a cave anything which has air block(s) below solid blocks. At least this matches the usual meaning of the Italian equivalent of cave. In this case it is not relevant if it has an opening toward the 'outside' or not.


    If you want to stick to a more strict definition, which requires no openings, then some 'winding' algorithm is probably needed to detect the closure, which, in 3D is not simple. Definitely not something to do in real time while the player is wandering around the world, though!


    Also, the chunks need to be generated before they can be analysed and I suspect only the visible/nearby chunks are normally generated, not subterranean chunks (until someone digs or flies to them). This is going to require additional server/db work to generate the data for analysis. So, mapping might turn out to be a heavy task... (as in real world, anyway).

  • Actually as @Miwarre suspected, the terrainData array in the Chunk class contains all necessary information to get the terrain id from a certain position (air is always 0). You could also use the surface array in the ChunkLOD class, although it's difficult to find out this way if there is really a cave or not. Here is the question: What is a cave? Or how do you find out that there is a cave? What's the difference between a cave or a hole in the ground, or a ravine for example?

    Ok, I see it now.
    I imagine there is no difference between air on either side of the cave wall. I likely have to write a recursive function to read in all terrain info surrounding the player position until actual terrain (non 0) is encountered to generate the map of the cave. Unless there is an id for solid without a texture (behind the cave wall). As to the definition of a cave, I'd imagine from a programming perspective a cave would be anywhere your position is below the known surface level of that postion and chunk. so if you fall down a deep hole, you can still see the surface but the map would still render surface. However once below the surface value, then the program could switch to the recursive function to generate a cave map, assuming the id values behind the cave wall are actually air.... Just my thought.. Never actually attempted anything like this before.

  • At the very minimum, I would qualify as a cave anything which has air block(s) below solid blocks

    That would work - as long as this definition of a cave is sufficient.


    If you want to stick to a more strict definition, which requires no openings, then some 'winding' algorithm is probably needed to detect the closure, which, in 3D is not simple

    One could calculate the gradient at a certain position. This way one could detect at least steep caves (as long as it's not getting confused with mountain walls).


    I suspect only the visible/nearby chunks are normally generated, not subterranean chunks (until someone digs or flies to them)

    Every chunk that has been modified will be generated, so even if no player is nearby, the world.getChunk(x, y, z) method will return a chunk object (or null if no chunk was generated). Basically the server is able to generate a chunk at any position (independent of the players), we just need a convenient way to do that.
    We can either:

    • change the world.getChunk(x, y, z); method, so it always returns a chunk, even if it's necessary to create a new chunk
    • add a new world.createChunk(x, y, z); method which creates a new chunk and returns the newly created chunk

    a cave would be anywhere your position is below the known surface level of that postion and chunk

    That would also work of course :) The surface is basically what you see in the distance (the LOD chunks). So indeed, an opening in the terrain or a ravine isn't necessarily below the surface.


    assuming the id values behind the cave wall are actually air

    Hmm... what do you mean exactly? Of course the inside of a cave is filled with air, but everything else (below the surface and behind cave walls) is solid rock

  • Every chunk that has been modified will be generated, so even if no player is nearby, the world.getChunk(x, y, z) method will return a chunk object (or null if no chunk was generated).

    Ok, my sentence was too cryptic, meaning: only chunks which -- at some moment -- are been visited by at least one player are generated. Actually, your observation seems to imply that only chunks which have been modified by a player are generated. In either case, there are chunks which would fall in the range of a mapping tool and which are not generated (at least not yet, at the moment the mapping tool needs them), particularly if the mapping tool extends in the depth direction too.

    Quote

    Basically the server is able to generate a chunk at any position (independent of the players), we just need a convenient way to do that.We can either:

    • change the world.getChunk(x, y, z); method, so it always returns a chunk, even if it's necessary to create a new chunk
    • add a new world.createChunk(x, y, z); method which creates a new chunk and returns the newly created chunk

    I assumed the world.getChunk(x, y, z); method already works in the way you describe (option 1.).


    If this is not set in stone yet, I would speculate that option 2. would allow some better optimisation (if the plug-in is well-thought and the author cares, of course), as it would allow the plug-in algorithm to decide if the chunk is really needed or not (either according to some heuristics or to the plug-in settings) and spare the generation of not indispensable chunks (even at the expense of some duplicate call: getChunk() first and then createChunk() if necessary).


    This assuming that chunk generation is a rather expensive procedure.

    a cave would be anywhere your position is below the known surface level of that postion and chunk

    Which seems to me another way of expressing the same definition I was proposing above... :D


    Hmm... what do you mean exactly? Of course the inside of a cave is filled with air, but everything else (below the surface and behind cave walls) is solid rock

    I think @zfoxfire is concerned by the 'airy' appearance of the space between the surface and the cave boundary when you fly in it. But all those in-between block are actually solid, aren't they?

  • If this is not set in stone yet, I would speculate that option 2. would allow some better optimisation

    Yeah I guess that's probably the best approach.


    (even at the expense of some duplicate call: getChunk() first and then createChunk() if necessary)

    That's true, maybe in favor of performance we can add an additional getChunk() method which also takes a boolean parameter which indicates it a new chunk should be created automatically. So in the end, there would be these methods:

    Java
    //returns null if no chunk exists
    getChunk(int x, int y, int z);
    //creates a new chunk if necessary, never returns null
    getChunk(int x, int y, int z, boolean createChunk);
    //creates a new chunk, maybe even overrides an existing chunk?
    createChunk(int x, int y, int z);

    I think @zfoxfire is concerned by the 'airy' appearance of the space between the surface and the cave boundary when you fly in it. But all those in-between block are actually solid, aren't they?

    Oh okay, yeah that may be confusing indeed. The game only renders the "transition" between solid and air blocks, that's why the world appears to be "hollow" ^^ Actually the hollow space still contains block data (solid rock).

  • If this is not set in stone yet


    You receive the pun of the day award! :)


    Oh okay, yeah that may be confusing indeed. The game only renders the "transition" between solid and air blocks, that's why the world appears to be "hollow" ^^ Actually the hollow space still contains block data (solid rock).


    Yes, Red. This is exactly what I was confused about but you clarified it earlier that "solid rock" has a terrain value in the chunk data. I was confused because of how I was seeing it in rendering. I assumed that the terrain data might have been storing the space underground but between caves as being open air. I have yet to spend time reading Chunk data to see what's there.

Participate now!

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