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

Solved breaking a block in a radius of another

Discussion in 'Development' started by iCirgio, Jul 28, 2018.

  1. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
    ok so im trying to make it so when you break a block it breaks block around it
    example

    xxx
    xox
    xxx

    ok lets say o is the block you broke and x is the blocks that are around it.

    how do i make it break the x
     
  2. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
  3. iCirgio

    iCirgio Slime

    Messages:
    92
    GitHub:
    lolnova
  4. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    I never told u to copy paste just look how pig did it
     
  5. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    I know it's solved, but i'll just leave this here for the future:
    PHP:
    /**
     * @param Position $position
     * @param int      $radius
     * @param bool     $includeAir
     *
     * @return array
     */
    public function getBlocksAroundPosition(Position $positionint $radius 1bool $includeAir false): array{
            
    $blocksAround = [];
            for(
    $i = -$radius$i $radius$i++){
                    for(
    $j = -$radius$j $radius$j++){
                            for(
    $k = -$radius$k $radius$k++){
                                    
    $x $position->$i;
                                    
    $y $position->$j;
                                    
    $z $position->$k;
                                    
    $block $position->level->getBlockAt($x$y$z);
                                    if((
    $block instanceof Air) && $includeAir){
                                            
    $blocksAround[] = $block;
                                    }elseif(!(
    $block instanceof Air)){
                                            
    $blocksAround[] = $block;
                                    }
                            }
                    }
            }
            return 
    $blocksAround;
    }
     
    ShushImSam and OnTheVerge 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.