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

Blocks

Discussion in 'Development' started by LucGamesDE, May 28, 2017.

  1. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    How can I get all blocks in a level and replace all stone blocks with dirt blocks?
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    That sounds like the most laggy plugin ever. Can you show proof of a previous attempt at creation?
     
  3. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    I don't have any code at the moment. I only need to know how to get all blocks
    For example:
    PHP:
    Server::getInstance()->getDefaultLevel()->getBlocks()?????
    And 
    than foreach and check the id
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    ALL blocks in a level? That might take days to compute and you will be annoyed by many memory leak problems when using setBlock spammy. The only solution would be to replace the blocks in a selection of chunk, with 1 subchunk in one tick (with a RepeatingTask), so the server would still be responsive and can clear its caches.
    Also don't use Server::getInstance()
    PHP:
    /** @var $level Level */
    //Kill me for this crappy way of finding the max x and max y values for chunks
    //And also this won't really work, there might be a single chunk missing and then you would end up missing chunks behind that.
    /** BEGIN CRAPPY CODE */
    $maxPX 0;
    while(
    $level->getChunk($maxPX0) !== null){
       
    $maxPX++;
    }
    $minPX 0;
    while(
    $level->getChunk($minPX0) !== null){
       
    $minPX--;
    }
    $maxPY 0;
    while(
    $level->getChunk(0$maxPY) !== null){
       
    $maxPY++;
    }
    $minPY 0;
    while(
    $level->getChunk(0$minPY) !== null){
       
    $minPY--;
    }
    //and btw the server will crash on big worlds, here too many chunks loaded
    //now basically you need to store these values in your repeating task and go through the chunks or subchunks. Please note that on big worlds this might take weeks. Have fun, just don't do it.
    //Just for completeness, here is how you replace blocks in a chunk (not subchunk):
    $chunk $level->getChunk($currX$currY);
    //for loop through 0-15 $cbX and 0-15 $cbZ and 0-255 $cbY
    if($chunk->getBlockId($cbX$cbY$cbZ) == /*whatever*/){
    $chunk->setBlockId($cbX$cbY$cbZ/*whatever*/);
    }
    Conclusion: DO NOT DO THIS WITH POCKETMINE. WRITE A SOFTWARE WHICH DIRECTLY EDITS THE LEVEL FILES, OR USE ONE LIKE MCEDIT.
     
  5. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    Why not?
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    I wonder if it's possible to NBT::readCompressed(...every chunk file) and then replace block ids. That'll be a lot quicker.
     
    jasonwynn10 likes this.
  7. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    If you don't know how to program, don't post in the Development section. maybe try facepalm.
     
  8. LucGamesDE

    LucGamesDE Baby Zombie

    Messages:
    170
    But what is wrong with getInstance?
     
  9. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    instead of reinventing the entire wheel, you could fast-serialize the chunk and throw it in an AsyncTask, and then replace all the IDs ;P Remember MineReset already does things a little like this.
     
  10. Reid

    Reid Spider Jockey

    Messages:
    43
    Why do you want to do this? Wouldn't it be much more efficient to just make a very simple world generator maybe I'm missing something
     
  11. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Simple answer: a level is infinite, so you can't.
     
    Qeis2007, jasonwynn10, Muqsit and 2 others like this.
  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.