As the title said I would like to know how to set a block in a radius of another blick. I tried $block->x + 1 but i want it to form like a square around the block
PHP: $radius = 1;for ($x = -$radius; $x <= $radius; $x++) { for ($y = -$radius; $y <= $radius; $y++) { for ($z = -$radius; $z <= $radius; $z++) { $block->getLevel()->setBlock($block->add($x, $y, $z), Block::get($id, $meta); } }}
PHP: /** @var Block $block */foreach($block->getAllSides() as $pos){ $block->getLevel()->setBlock($pos, Block::get(int, int));} NOTE: $pos is actually a Block instance whichwhich indir extends Vector3. Also, you may want to set the fourth parameter of Level::setBlock() as false to disallow any block updates from happening. Level::setBlock($pos, $block, false, false);
Oh I see, try: PHP: foreach(array_merge( [ $block->add(1, 0, 1), $block->add(-1, 0, -1), $block->add(1, 0, -1), $block->add(-1, 0, 1) ], $block->getAllSides()) as $pos){] But in that case, its better to use @DaPigGuy's with an exception to not loop through the main (center) block.