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

How can I get all the blocks connected to one block

Discussion in 'Development' started by rektpixel, Jan 12, 2018.

  1. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    I have this:
    PHP:
        public function onInteract(PlayerInteractEvent $event) {
            
    $player $event->getPlayer();
            if(
    $player->isOp()){
                
    $block $event->getBlock();
                
    $level $player->getLevel();
                
    $X $block->getX();
                
    $Y $block->getY();
                
    $Z $block->getZ();
    // I want to get all the blocks connected to this block and then all the block conntected to those blocks and so on. Or if this can't be done how do I get the blocks in an area? heeellppp!
    // also must get what block it is..

                
    foreach($blocks as $b)
                
    $X $b->getX();
                
    $Y $b->getY();
                
    $Z $b->getZ();
                
    $pos = new Vector3($X-1$Y$Z);
                
    $level->setBlock($pos$bfalsefalse);
            }
        }
    The code says it all. so how can I do this?
    essentially what I'm trying to achieve is to move a floating ship 1 block ahead of itself when I tap any block on the ship.
     
    Last edited: Jan 12, 2018
  2. rektpixel

    rektpixel Baby Zombie

    Messages:
    186
    r people annoyed with me posting so much. cuz I never get a response. lol
     
  3. MC ATECH

    MC ATECH Baby Zombie

    Messages:
    117
    GitHub:
    mcpeatech
    Don't think its possible to connect blocks to each other in that manner, sorta like slime blocks in a sense. I'm guessing instead you would need to move a block ID so make whatever your moving a specific block... such as dirt or something :p hope this helped in some way!
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    So if you click a block on the ground in a normal survival world, would this delete the whole world?
    Not sure about your exact scenario. How big do you expect your chunks of blocks to be? You may want to use an iterator rather than an array if it gets too large to prevent memory exhaustion. Also beware recursion stack overflow.
     
    MC ATECH and rektpixel 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.