1.12.2 Best way to manipulate chunk data?

Discussion in 'Spigot Plugin Development' started by DJMAN, Aug 1, 2020 at 11:17 PM.

  1. I've been struggling to get this right for a while now.

    Basically, I want to have an always persistent ocean in the world, where any air "blocks" below a certain Y level get replaced with stationary water (and Y 0 is just a layer of barrier blocks).

    I know that I could just use a world generator to do this, but then the server has to process all of that, and since this project involves having a giant amount of worlds (all of which will have this "ocean"), I don't think it'd be a good idea in terms of storage either.

    I want to achieve this with ProtocolLib, by intercepting every MAP_CHUNK packet sent and populating the water blocks there. But for the life of me, I can't figure out how to even read/write the chunk data. I tried using ChunkPacketProcessor, however that seems outdated and I can't get it to handle the data properly, it always seems to corrupt the chunk.

    Does anyone have a solution for this?
     
  2. joehot200

    Supporter

    I don't think this is a good idea.

    Using ProtocolLib means that the server believes different information than the client. For example, the clients would not drown in ProtocolLib-generated water, or the server may kick players for "flying is not allowed".

    If you truly want to edit chunks with ProtocolLib, I will warn you it is a bit of nightmare to do successfully. The wiki.vg chunk format page should point you in the right direction: https://wiki.vg/Chunk_Format


    A custom world generator does not necessarily pre-generate a world. Therefore, you could simply use a custom generator. There would be no additional storage problems compared to vanilla world generation. Read more here: https://bukkit.gamepedia.com/Developing_a_World_Generator_Plugin#Introduction


    The other, highly cumbersome and lazy method would be to wait for chunk loading and then editing the blocks once the chunk is loaded.
     
  3. I understand that, and it won't be a problem.

    I was hoping that someone had already written some sort of (up-to-date) library to read the chunk data because it does seem like a lot to write my own code for that.
     
    • Like Like x 1
  4. this. other issues:
    monsters will spawn where the water is, as theres no water in the server.
    monsters will desync hard wherever there is water, as to the server, they will be walking, but to the client they will be floating up.
    you cannot simulate flowing water (which you may be fine with since you mentioned stationary water)
    you gonna get some funky stuff when your water interacts with real water and with lava.
    any time a block is mined or placed, the surrounding blocks will get updated, reverting false water back to air.

    you would greatly benefit from simply using a chunk generator, as minecraft will handle everything for you. you dont use anymore disk space, as the block takes space whether its air or not. you wont have any weird side effects, and itll be properly integrated with everything else. it saves you the cpu usage of having to modify every chunk data packet for every player every time (which is definitely much more resources than just generating each chunk with some water instead of air)
     
    • Agree Agree x 1
  5. joehot200

    Supporter

    There isn't really one, and I believe that such a library would break with every update. Some very good ones can be found at the bottom of the wiki.vg page I already linked above.

    I would highly recommend a custom generator, as the server does not have to "process all of that" as you presumed, nor does it increase storage space. Therefore, all of the advantages seem to lie with using a custom generator. It should be easier to maintain as well as more efficient to both client & server.
     
  6. Thank you, I'll look into it and see if I could maybe use it as a starting point.

    Again, none of that will be a problem, nothing will ever get a chance to interact with the water, it's purely visual.
     
  7. Wait, so instead of doing a 1 time generation and storing it to disk, you are going to decode every chunk, modify the necessary chunk data and then re-encode it for every single chunk sent to every player? Surely there is a better way to do this than with ProtocolLib.
     
    • Agree Agree x 1
  8. Yup, that's exactly what I want to do.