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

BlockPlaceEvent

Discussion in 'Development' started by abimalek, Oct 23, 2017.

  1. abimalek

    abimalek Witch

    Messages:
    74
    GitHub:
    megagastpvp
    Im makeing a plugin that if you have a specific block and place it it will spawn 10 cobble stone block under the block. How would I do the getBlock()->getLevel()->setBlock($block getX(-1)); then another
    getBlock()->getLevel()->setBlock($block getX(-2)); is their anything wrong with this code
     
  2. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    To do this, use:
    PHP:
    public function onPlace(BlockPlaceEvent $event) {
        
    $block $event->getBlock();
        if(
    $block->getId() === Block::GLASS) { // if placed block is glass
            
    $level $block->getLevel();
            for(
    $i $block->getY() - 1$i >= $block->getY() - 10$i--) { // goes down 10 blocks
                
    $level->setBlock(new Vector3($block->getX(), $i$block->getZ()), Block::get(4)); // places cobblestone
            
    }
        }
    }
    It will place 10 cobblestone below the placed bedrock, for example.
     
  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.