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

Insert from Schematic problem

Discussion in 'Development' started by Error202, Apr 6, 2019.

  1. Error202

    Error202 Spider Jockey

    Messages:
    39
    I load the area from the file.
    Everything loads correctly.
    After a few minutes some parts disappear ...
    [​IMG]
    A little bit later...
    [​IMG]
    After restarting the server, almost 80% is lost
    [​IMG]
    Why?


    PHP:
    class LoadTask extends AsyncTask
    {
        private 
    $target;
        private 
    $file;

        public function 
    __construct($target$file){

            
    $this->target json_decode($targettrue);
            
    //$this->target = $target;
            
    $this->file $file;
        }

        public function 
    onRun()
        {
        }

        public function 
    onCompletion(Server $server)
        {
            
    $nbt = new BigEndianNBTStream();
            
    $data $nbt->readCompressed(file_get_contents($this->file));

            
    $width = (int)$data->getShort("Width");
            
    $height = (int)$data->getShort("Height");
            
    $length = (int)$data->getShort("Length");

            if(
    $data->offsetExists("Materials")) {
                
    $materials $data->getString("Materials");
            }
            if (
    $data->offsetExists("Blocks") && $data->offsetExists("Data")) {
                
    $blocks $data->getByteArray("Blocks");
                
    $data_damage $data->getByteArray("Data");
                
    $types $data->getByteArray("Type");

                
    $i 0;
                
                
    $world $server->getLevelByName($this->target['world']);

                
    $iterator = new ChunkIterator($world);

                for(
    $y 0$y $height$y++) {
                    for (
    $z 0$z $length$z++) {
                        for(
    $x 0$x $width$x++) {
                            
    $id ord($blocks{$i});
                            
    $damage ord($data_damage{$i});
                            if(
    $damage >= 16) { // prevents bug
                                
    $damage 0;
                            }

                            
    $type ord($types{$i});
                            if(
    $type >= 16) { // prevents bug
                                
    $type 0;
                            }

                            
    $block = new Block($id$damage);
                            
    $pos = new Position($x $this->target['x'], $y $this->target['y'], $z $this->target['z'], $world);

                            
    $block->$pos->getX();
                            
    $block->$pos->getY();
                            
    $block->$pos->getZ();
                            
    $block->level $pos->getLevel();
                            
    SpecialHelper::setBlock($pos$block$iterator$type);
                            
    $i++;
                        }
                    }
                }

                
    $max_x $this->target['x'] + $width;
                
    $max_z $this->target['z'] + $length;
                
    SpecialHelper::updateData($world$this->target['x'] >> 4$max_x >> 4$this->target['z'] >> 4$max_z >> 4);
            }
        }
    }

    PHP:
    $iterator->moveTo($pos->getX(), $pos->getY(), $pos->getZ());
                
    $iterator->currentSubChunk->setBlock($pos->getX() & 0x0f$pos->getY() & 0x0f$pos->getZ() & 0x0f$block->getId(), $block->getDamage());

    PHP:
    class ChunkIterator extends SubChunkIteratorManager {

        public function 
    moveTo(int $xint $yint $z): bool {
            if (
    parent::moveTo($x$y$z)) {
                return 
    true;
            }
            if (
    $this->currentSubChunk === null) {
                
    $this->currentSubChunl $this->level->getChunk($this->currentX$this->currentZ)->getSubChunk($y >> 4$this->allocateEmptySubs);
                return 
    true;
            }
            return 
    false;
        }

    }
     
    Levi likes this.
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Do you have autosave disabled? Use /save-on to enable autosave.
    Also, you have a typo in your ChunkIterator.
     
  3. Error202

    Error202 Spider Jockey

    Messages:
    39
    Problem still exists..
    Blocks gradually disappear.
    After the reboot disappears 100%.

    P.S.
    $world->save(); - no result
     
    Last edited: Apr 6, 2019
    Levi likes this.
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    DId you figure this out
     
  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.