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

Setting blocks with async task

Discussion in 'Development' started by notdrewdev, Apr 23, 2019.

  1. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    39
    GitHub:
    drewsucksatlife
    Howdy! I've been trying to place blocks through an async task and have had no success, I've always had it crash with "setBlockIdAt" on null.

    Code for placing blocks:
    PHP:
    $store $this->getFromThreadStore("generator.level{$this->levelId}.manager");
    for(
    $minX = -$this->border$minX <= $this->border$minX++){
          for(
    $y 50$y <= 100$y++){
              
    $store->setBlockIdAt($minX$y$this->borderBlock::BEDROCK);
          }
    }
    Code for calling the task:

    PHP:
    $level $this->plugin->getServer()->getDefaultLevel();
    $this->plugin->getServer()->getAsyncPool()->submitTask(new PlaceBlockTask($border$level->getId()));
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    you can serialize the chunks you want to change, then deserialize it in the task, then you can loop the chunks to your suit
    PHP:
    /** @var Chunk $chunk */
    $serializedChunk $chunk->fastSerialize();
    /** of course you can make this an array and loop it in the task to change more chunks
    $this->plugin->getServer()->getAsyncPool()->submitTask(new PlaceBlockTask($border, $serializedChunk));
    then in the task you can do
    PHP:
    $chunk Chunk::fastDeserialize($this->serializedChunk);
    /** There are only 16x16x256 blocks in a chunk */
    for($xx 0$xx 16$xx++){
        for(
    $zz 0$zz 16$zz++){
            for(
    $yy 50$y <= 100$yy++){
                
    //$chunk->setBlock(); blah blah..
            
    }
        }
    }
     
  3. notdrewdev

    notdrewdev Spider Jockey

    Messages:
    39
    GitHub:
    drewsucksatlife
    Doesn't appear to be placing anything.
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You need to serialize the chunk again after you are done setting the blocks in onRun, then $this->setResult($serializedChunk);
    Then onCompletion you unserialize the chunk(getResult) and setChunk on your level
     
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Why not unserialize in the async task?
     
  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.