Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

set blocks in an Async task

Comments in 'Plugin Development' started by Creeperface, Jan 22, 2016.

  1. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    im using this code (inspirated from MineReset ) but it doesn't work :/ where is the problem?

    PHP:
    public function onRun(){
            
    $chunkClass $this->chunkClass;
            
    /** @var  Chunk[] $chunks */
            
    $chunks unserialize($this->chunks);
            foreach(
    $chunks as $hash => $binary){
                
    $chunks[$hash] = $chunkClass::fromBinary($binary);
            }

            for(
    $x $this->pos1->x$x <= $this->pos2->x$x++){
                for(
    $z $this->pos1->z$z <= $this->pos2->z$z++){
                    
    $hash Level::chunkHash($x >> 4$z >> 4);
                    
    $chunk null;

                    if(isset(
    $chunks[$hash])){
                        
    $chunk $chunks[$hash];
                    }

                    if(
    $chunk !== null && $this->color){
                        
    $chunk->setBiomeColor($x$z10815147);
                    }

                    for(
    $y $this->pos1->y$y <= $this->pos2->y$y++){
                        if(
    $chunk !== null){
                            
    $id $chunk->getBlockId($x$y$z);
                            
    $meta $chunk->getBlockData($x$y$z);

                            switch(
    $id){
                                case 
    126:
                                    
    $chunk->setBlock($x$y$z158$meta);
                                    break;
                                case 
    95:
                                    
    $chunk->setBlock($x$y$z20);
                                    break;
                                case 
    188:
                                    
    $chunk->setBlock($x$y$zItem::FENCE1);
                                    break;
                                case 
    189:
                                    
    $chunk->setBlock($x$y$zItem::FENCE2);
                                    break;
                                case 
    190:
                                    
    $chunk->setBlock($x$y$zItem::FENCE3);
                                    break;
                                case 
    191:
                                    
    $chunk->setBlock($x$y$zItem::FENCE4);
                                    break;
                                case 
    192:
                                    
    $chunk->setBlock($x$y$zItem::FENCE5);
                                    break;
                            }
                        }
                    }
                }
            }

            
    $this->setResult($chunks);
        }

        public function 
    onCompletion(Server $server)
        {
            
    $chunks $this->getResult();
            
    $level $server->getLevel($this->levelId);
            if (
    $level != null) {
                foreach (
    $chunks as $hash => $chunk) {
                    
    Level::getXZ($hash$x$z);
                    
    $level->setChunk($x$z$chunk);
                }
            }
        }
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Explain how it doesn't work!
  3. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    It doesn't change any block
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Even if you rejoin?
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    Ok thx, i try it again xD

Share This Page

Advertisement