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.
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
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.
This was the code I used to destroy a obsidian with a tnt https://github.com/PrimusLV/FactionsPE/blob/reborn/src/factions/engine/ExploitEngine.php#L63-L81
Because I want to check the name, not other things. And your console will lag when you dump all blocks.
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.
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.