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

Counting specified blocks in a world

Discussion in 'Development' started by DanielYTK, Apr 22, 2017.

  1. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Is there any way I can get how many blocks in one world?
    Ex: I want to know how many blocks of glass have in my world, Any way to do that?
     
  2. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    Foreach them then count them
     
    rektpixel likes this.
  3. moska

    moska Baby Zombie

    Messages:
    105
    GitHub:
    supermaxalex
    Do a foreach
    PHP:
    foreach($whereblocksyouwanttocount as $blocks){
    Then, when you are sending a message or anything else, add this :
    PHP:
    count($blocks);
     
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    If you want to scan the whole world and cause the server to freeze for hours, you could foreach the blocks. You might be better of using an async task with the region files.
     
    Last edited: Apr 22, 2017
  5. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    also see: async
    even on an async scale you need to load the blocks into the async class
     
  6. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    What if the async task reads the blocks directly from the world's files?
     
    SOFe and Sandertv like this.
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Mind thinking before answering? One main point is what to foreach, where you get the $blocks array from. Apparently, it is an enormous bulk of data and you won't want to get them all from a single array.
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    It seems that it's quite difficult to do this asynchronous. It is possible, but it's either ineffective (such that it's barely better than or even worse than doing it synchronously), or you have to write your own level parser, both bad ideas.

    I would suggest that you first count the blocks in loaded memory, and then search generated levels in the world (if you want generated but unloaded chunks too), then load and count and then unload them one by one. Don't load everything together, because the server memory may exhaust when all levels are loaded. You may check the time after every operation, and leave the rest to execute in the next tick, but this is quite complicated. See PEMapModder's WorldEditArt plugin for example of separating loops to ticks -- really got him a big head.
    So if you just want to count the blocks for personal use, I recommend not trying to do it in a plugin, or at least, not try to make it a command that you use frequently :D
     
    minijaham and DanielYTK like this.
  9. moska

    moska Baby Zombie

    Messages:
    105
    GitHub:
    supermaxalex
    It was 7 AM, my brain was sleeping
     
  10. Miste

    Miste Baby Zombie

    Messages:
    109
    GitHub:
    Misteboss
    Same x)
     
  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.