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

Solved Code doesn't seem to work

Discussion in 'Development' started by minijaham, Sep 10, 2020.

  1. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Hey! I am trying to make a plugin where obsidian breaks by TNT

    PHP:
    <?php

    namespace minijaham\BreakableObsidian;

    use 
    pocketmine\block\Block;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\block\Liquid;
    use 
    pocketmine\entity\PrimedTNT;
    use 
    pocketmine\event\entity\EntityExplodeEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\block\Obsidian;

    class 
    Main extends PluginBase implements Listener{
        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
        public function 
    onExplodeTnt(EntityExplodeEvent $event) {
    echo 
    '           Tnt Exploded BRUH            ';
            
    $blockList $event->getBlockList();
            foreach(
    $blockList as $key => $block) {
                if (
    $block->getId() === Block::OBSIDIAN) {
    echo 
    '           I found Obsidon Block BRUH            ';
                    
    $level $blockList[$key]->getLevel();
                    
    $level->setBlock($blockList[$key], Block::get(Block::AIR));
                }
            }
        }
    }
    The code only returns:
    [​IMG]

    Doesn't break the obsidian >:[
     
  2. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    try

    use pocketmine\block\Obsidian;
    if ($block instanceof Obsidian)

    and for your $level why get block via array, just use $block->getLevel()
    var_dump can help you, this is a function who paste your variable in your console. Use on $block->getId() or $blockList, it can help you
     
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    I've tried
    use pocketmine\block\Obsidian;
    if ($block instanceof Obsidian)
    which was my first code xD

    And I'll use the $block->getLevel90 :p
     
  4. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    ...
     
  5. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Wait no 90 was typo >:[
     
  6. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    i know but you don't use $block but your array with your $key
     
  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.