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

setBlock()

Discussion in 'Development' started by Ayzrix, Oct 20, 2019.

  1. Ayzrix

    Ayzrix Witch

    Messages:
    66
    GitHub:
    Ayzrix
    Hi , can you explain me why that's work

    PHP:
                        public function onBreak(BlockBreakEvent $event) {

        
    $player $event->getPlayer();
        
    $block $event->getBlock();
        
    $level $player->getLevel();
        
    $x $player->getX();
        
    $y $player->getY();
        
    $z $player->getZ();

        
    $level->setBlock(new Vector3($x$y$z), Block::get(Block::LAVA));
                                                 
       
        }
     
    But that's don't work

    PHP:
                        public function onBreak(BlockBreakEvent $event) {

        
    $player $event->getPlayer();
        
    $block $event->getBlock();
        
    $level $block->getLevel();
        
    $x $block->getX();
        
    $y $block->getY();
        
    $z $block->getZ();

        
    $level->setBlock(new Vector3($x$y$z), Block::get(Block::LAVA));
                                                 
       
        } 
    I don't have any error but that's not make anything :/

    Can you help me ? That's for replace a block.
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    If the first code worked, then should work the second code too when it is exactly same.
     
  3. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    The first one uses $player for the position, the second one uses $block.
     
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Then it could been caused because the coordinates isn't in integer format.

    PHP:
    $x = (int)$player->getX();
     
  5. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You have to either use a delayed task or cancel the event, as the block will be replaced with air at the end of the event
     
  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.