Setting a World Chunk Problem

Discussion in 'Spigot Plugin Development' started by KnaxelBaby, Jun 14, 2018 at 10:14 PM.

  1. I need a feature in my plugin to essentially copy a chunk from one world to replace a chunk in the other world. The have the same world coordinates and chunk cords. The only problem im having is understanding the nms construct enough to actually copy a chunk and load it into another chunk in a separate world.


    This is what ive come up with thus far. I receive null-pointer errors from the fromChunk variable when referencing any data in getSections().

    Does anyone know if im one the right track or have any suggestions ? Thank youu :p

    (or should i use world edit and home the server cpu doesnt explode?)
    Code (Text):

                org.bukkit.World refWorld = this.referencWorld;
                org.bukkit.Chunk refChunk = refWorld.getChunkAt(chunk.getX(), chunk.getZ());
                refChunk.load();
                CraftChunk from = (CraftChunk) refChunk;
                CraftChunk to = (CraftChunk) chunk;
                Chunk fromChunk = from.getHandle();
                Chunk toChunk = to.getHandle();
                ChunkSection[] tsec = fromChunk.getSections();
                ChunkSection[] afterSec = new ChunkSection[tsec.length];
                for(ChunkSection c : tsec){
                    System.out.println(c.toString());
                }
                for (int n = 0; n < tsec.length; n++) {
                    if(tsec[n] == null){
                        System.out.println("null chunk section");
                        continue;
                    }
                    ChunkSection source = tsec[n];
                    ChunkSection clone = new ChunkSection(source.
                            getYPosition(),false);
    //clone.a(source..clone());
                    clone.b(new NibbleArray(source.getSkyLightArray().asBytes().clone()));
                    clone.a(new NibbleArray(source.getEmittedLightArray().asBytes().clone()));
                    afterSec[n] = clone;
                }
                toChunk.a(afterSec);
                //toChunk.getWorld().refreshChunk(toChunk.bukkitChunk.getX(), toChunk.bukkitChunk.getZ());
                System.out.println("reloaded a fresh chunk from file");
     
    #1 KnaxelBaby, Jun 14, 2018 at 10:14 PM
    Last edited: Jun 14, 2018 at 10:42 PM
  2. I don't think using nms is what you're looking for. You're really going to need to go block by block, any other method isn't really faster (unless you're deleting the chunk and regenerating it from the seed). In which case, I'd recommend looking into AsyncWorldEdit API.
    https://www.spigotmc.org/resources/asyncworldedit.327/
     
    • Winner Winner x 1
  3. This looks very promising thank you !
     
    • Like Like x 1
  4. Nms is Indeed faster than the bukkit API but the obfuscation makes it difficult to figure out.
     
    • Agree Agree x 1
  5. Oh, I did not know that! Thank you for correcting me.
     
    • Like Like x 1

Share This Page