Get Blocks Coordinates

Discussion in 'Development' started by xXNiceAssassinlo YT, Dec 1, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    643
    GitHub:
    xXNiceYT
    Hey, been a long time not creating a issue for pocketmine plugin but here we go again.

    I am trying to get every block coordinates with a id 2(Grass) in a world.
     
    Last edited: Dec 1, 2018
  2. Diduhless

    Diduhless Spider Jockey

    Messages:
    41
    GitHub:
    Diduhless
    I wouldn't do that, because you'd have to foreach all the blocks of a level and the server could exploit
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    643
    GitHub:
    xXNiceYT
    I used Grass as example, but I am not doing grass and how do I foreach every block :/ I don’t see getBlocks() function lol don’t facepalm me please
     
  4. LewBr

    LewBr Zombie

    Messages:
    385
    GitHub:
    lewbr
    he can select to foreach only in a specific area, not all the world because if he does that it will really be an Allahu Akbar server.. hah
     
    jasonwynn10 likes this.
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    643
    GitHub:
    xXNiceYT
    Lol but I don’t think it’s possible to get every grass block in level
     
  6. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    593
    There are lots of posts like this one. You cannot get every single block in a world, you can only get the nearby blocks of an entity, foreach them and check if there are an instance of a Grass.
     
    jasonwynn10 and Muqsit like this.
  7. Muqsit

    Muqsit Wither Skeleton Verified

    Messages:
    1,419
    GitHub:
    muqsit
    You can get all blocks in a world's generated regions. You can't get what's not generated.

    But if you still want to, you can replace blocks from already existing chunks and run a find-and-replace function on newly generated chunks (this could get laggy on the main thread, perhaps do it inside a custom Generator that extends the normal generator?).

    The master branch has a method to iterate through all generated chunks...
    PHP:
    foreach($level->getProvider()->getAllChunks() as $chunk){
        
    //...
    }
    ...and you can use maybe ChunkPopulateEvent to modify newly generated chunks.

    Make a backup before doing any of that, because it's the master branch and there's a chance to ruin the whole world since you're iterating over the whole world :oops:.
     
    Last edited: Dec 1, 2018
  8. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    643
    GitHub:
    xXNiceYT
    Ik that why I made forum Ik i can get nearest player I was just checking if there is way to get every block with Id 2 and I can’t find any post like "this"
     
  9. padrone

    padrone Witch

    Messages:
    58
    GitHub:
    padrone
    why should you use this word "allahu akbar"?
     
  10. StarvingWolf12PE

    StarvingWolf12PE Creeper

    Messages:
    1
    Idk
     
  11. jasonwynn10

    jasonwynn10 Wither Skeleton Poggit Reviewer Verified

    Messages:
    1,271
    GitHub:
    jasonwynn10
    What you are asking is half of the worldedit replace function. I suggest you take a look at one of those plugins for code examples.
     
    radondev likes this.
  12. Kkora

    Kkora Slime

    Messages:
    91
    GitHub:
    kkora2k3
    use world edit or MagicWE. Use //wand and get it crood! But it just get crood of 1 block per click
     
  13. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    643
    GitHub:
    xXNiceYT
    I’m trying to make farm without saving the coordinate of the crops so I am trying to get all crops and use update event to grow them
     
  14. Kkora

    Kkora Slime

    Messages:
    91
    GitHub:
    kkora2k3
  15. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    643
    GitHub:
    xXNiceYT
    I just staid without saving the coordinate on file...
     
  16. Kkora

    Kkora Slime

    Messages:
    91
    GitHub:
    kkora2k3
    It won't save anything.
     
  17. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    643
    GitHub:
    xXNiceYT
    I checked it lmao
     
    jasonwynn10 and Kkora like this.
  18. jasonwynn10

    jasonwynn10 Wither Skeleton Poggit Reviewer Verified

    Messages:
    1,271
    GitHub:
    jasonwynn10
    What if you override the class and trigger a task to manually trigger a block update every set amount of ticks? All you'd need to do is trigger the update once and pocketmine already does that with random block updates. You could also use randomization so they dont all grow in sync for aesthetic
     
    OnTheVerge likes this.
  19. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    643
    GitHub:
    xXNiceYT
    Oh ya your right I’m stupid xd
     
    Kkora likes this.

Share This Page

  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.