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

Block detection by explosion

Discussion in 'Development' started by KingDeadKnight, Dec 5, 2016.

  1. KelvinCyaX

    KelvinCyaX Silverfish

    Messages:
    18
    GitHub:
    CyanKelv
    Well im trying to help him and what i mean is only replace certain blocks with air and keep some of them. For example prevent grass from destroying but obsidian.
     
  2. KingDeadKnight

    KingDeadKnight Spider

    Messages:
    8
    GitHub:
    kingdeadknight
    PHP:
    public function onExplode(EntityExplodeEvent $e) {
          foreach(
    $e->getBlockList() as $b){
             if(
    var_dump($e->getBlockList()) == Block::get(Block::OBSIDIAN)){
                  
    $x $b->getX();
                  
    $y $b->getY();
                  
    $z $b->getZ();
                  
    $this->getLevel()->setBlock(new Vector3($x$y$z), Block::get(Block::AIR));
                }
            }
        }
    Can it work?
    Thanks
    PS: If you think that I'm a noob, help me instead of criticizing what I'm doing, it was just just to be frank
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    No.
    It is not whether we want to help you, but whether you know what you are doing at all. If you don't know what you are doing, if you just put something in the code and call it an "attempt", it is not an attempt at all.
    Please read.
     
    Primus likes this.
  4. Primus

    Primus Zombie Pigman

    Messages:
    749
  5. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Because I want to check the name, not other things. And your console will lag when you dump all blocks.
     
  6. imYannic

    imYannic Baby Zombie

    Messages:
    113
    The obsidian block is not in the list, because it's not destroyed.
     
  7. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    If you just want it to explode obsidian as well, you could set the force superhigh so it explodes every block (except bedrock then) around it.
     
    LilCrispy2o9 likes this.
  8. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    PHP:
    public function onExplode(EntityExplodeEvent $e) {
            
    $blocks $e->getBlockList();
            foreach(
    $blocks as $num => $block){
                if(
    $block instanceof Obsidian) { //Remember to use pocketmine\block\Obsidian;
                   
    unset($blocks[$num]);
                }
             }
              
    $e->setBlockList($blocks);
        }
    This removes all obsidian blocks out of the blockList.
     
  9. imYannic

    imYannic Baby Zombie

    Messages:
    113
    get_class() returns the class name, not all its properties.
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Sorry I read wrongly. Deleted posts.
     
    imYannic likes this.
  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.