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(), $chunk, true); }
Would cloning it work? Or am I not understanding you right? Update: Cloning it worked pretty well. Thanks for the help Dylan!
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.