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

Block isn't setting

Discussion in 'Development' started by TwistedAsylumMC, Apr 20, 2018.

  1. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    I'm using interact event to set the block to air, but it doesn't work and there's no errors.
    Code:
    PHP:
    public function onInteract(PlayerInteractEvent $event){
        
    $block $event->getBlock();
        if(
    $block->getId() == 46){
            
    $block->getLevel()->setBlock(new Vector3($block->getX(), $block->getY(), $block->getZ()), Block::get(Block::AIR), true);
        }
    }
    Like i said, there's no errors or anything, i'm using all the correct use imports idk how to fix
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Add
    PHP:
    var_dump($block->getId());
    right after declaring the $block variable and check if you get any console output.
     
  3. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
  4. TwistedAsylumMC

    TwistedAsylumMC Slime

    Messages:
    96
    GitHub:
    twistedasylummc
    when i var dump the id it says
    PHP:
    int(46)
     
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    that's weird. try this:
    PHP:
    public function onInteract(PlayerInteractEvent $event){
        
    $block $event->getBlock();
        
    var_dump($block->getId());
        if(
    $block->getId() == 46){
            
    var_dump($block->getLevel()->setBlock($block), Block::get(Block::AIR), true));
        }
    }
     
  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.