1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Chunks not resetting

Discussion in 'Development' started by Irish, Jul 17, 2017.

  1. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    So, I'm saving some chunks of a level when I start my server, and I'm trying to make it so that I can reset those chunks.

    Can anyone check out my code and see where I went wrong? Is this a client bug? Will chunks not set with players in them?

    Adding chunks when the server starts(I tried it without the isset method, but the same results happened):
    PHP:
    for($x $posMin->getFloorX(); $x <= $posMax->getFloorX(); $x++){
                for(
    $z $posMin->getFloorZ(); $z <= $posMax->getFloorZ(); $z++){
                    
    $chunk $this->getLevel()->getChunk($x >> 4$z >> 4);
                    if(!isset(
    $this->chunks[$chunk->getX() . $chunk->getZ()])) {
                        
    $this->chunks[$chunk->getX() . $chunk->getZ()] = $chunk//35 chunks in all.
                    
    }
                }
            }

    Resetting chunks:
    PHP:
     foreach ($this->chunks as $chunk) {
                
    $this->getLevel()->setChunk($chunk->getX(), $chunk->getZ(), $chunktrue);
     }
     
    Levi likes this.
  2. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    you're holding a reference to those chunks... not the chunks themselves.
     
    Irish likes this.
  3. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Would cloning it work? Or am I not understanding you right?

    Update: Cloning it worked pretty well. Thanks for the help Dylan!
     
  4. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    You were holding a reference to the current loaded chunk, not a copy/clone; by cloning the original object you've created a separate instance that wasn't loaded in the level thus, works as you expected.
     
    Irish likes this.
  5. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    Yeah, I understood that after I did it :p
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.