I know, I know...another obsidian thread, but this time it's mainly to do with making the obsidian blow up after a couple of hits with TNT instead of just one explosion. PHP: <?phpdeclare(strict_types=1);namespace BlobKing21\ObbyDestroyer;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\block\Block;use pocketmine\block\Obsidian;use pocketmine\block\BlockFactory;class Main extends PluginBase implements Listener{ public function onEnable() { BlockFactory::registerBlock(new MyObsidian(), true); }}class MyObsidian extends \pocketmine\block\Obsidian{ public function getBlastResistance() : float { return 7.5;//same as stone }} This code works, but as I previously said, I want to make some way of blowing up the obsidian after, say 4 times. If you guys could point me in the right direction of how to do this, that will be greatly appreciated, Thanks! Edit: I know that I could just set the hardness to 77, and it be the hardest block that TNT can break, but that isn't the way I want it to break, just so you know!
this may not be the best way, but it works PHP: //MAINpublic function onExplodeEntity(EntityExplodeEvent $e){$list = [];foreach($e->getBlockList() as $b){if($b instanceof Obsidian){ $b->onExplode(); }else{ $list[] = $b } }$e->setBlockList($list);}///Obsidian classclass Obsidian extends \pocketmine\block\Obsidian{const MAX_EXPLODE_COUNT = 3; //durabilitypublic function onExplode(){if(($this->meta + 1) >= self::MAX_EXPLODE_COUNT){$this->getLevel()->setBlock($this, new Block(0));}else{$this->meta += 1;$this->getLevel()->setBlock($this, $this); } }}
Didn't work for me... PHP: //Main File<?phpnamespace NickteeChunky;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\event\entity\EntityExplodeEvent;use pocketmine\block\Block;use pocketmine\block\BlockFactory;class Main extends PluginBase implements Listener{ public function onEnable() { BlockFactory::registerBlock(new MyObsidian(), true); } public function onExplodeEntity(EntityExplodeEvent $e){ $list = []; foreach($e->getBlockList() as $b){ if($b instanceof MyObsidian){ $b->onExplode(); }else{ $list[] = $b; } } $e->setBlockList($list); }}//Obsidian File<?phpnamespace NickteeChunky;use pocketmine\block\Obsidian;class MyObsidian extends \pocketmine\block\Obsidian{const MAX_EXPLODE_COUNT = 3; //durability public function onExplode(){ if(($this->meta + 1) >= self::MAX_EXPLODE_COUNT){ $this->getLevel()->setBlock($this, new Block(0)); }else{ $this->meta += 1; $this->getLevel()->setBlock($this, $this); } }}
You didnt register events, plus missing PHP: public function getBlastResistance() : float { return 7.5;//same as stone } in MyObsidian class
Ah okay, got it, but what if I wanted to know a block's current durability after x amount of explosions. Say for example, the block blows up when it's exploded 4 times, I've exploded it twice and I want to know how many more explosions it needs to blow up, how would I get this number via interaction? Thanks in advance. @wolfdale @GamakCZ