Heyo! Recently i wanted to add some cool custom blocks, by using command blocks.... but after making them... i realized that onBreak does not get called... I tried setting isBreakable to true, (even though its true by default in Block), tried messing with the hardness... but nothing... all i get is the breaking animation, and then just nothing... the block just stays there..... Is it even possible? I would like to do this without any external listeners or tasks.... but if its needed i might ue them.. Thanks in advance!
Demo video I have a youtube channel, where I answer the threads from pmmp.io Follow spoilers, all files are in the same namespace / directory, so no need additional folders. This code just demonstration, and have issues. Good luck! I took some information "how to" from this thread. Spoiler: Your onEnable should include this --> PHP: $this->getServer()->getPluginManager()->registerEvents(new BedrockBreakEvent(), $this);BlockFactory::registerBlock(new Bedrock(), true); Spoiler: BedrockBreakEvent --> PHP: <?phpnamespace mlsdmitry\ForumThreads;use pocketmine\block\Block;use pocketmine\event\Listener;use pocketmine\event\server\DataPacketReceiveEvent;use pocketmine\network\mcpe\protocol\PlayerActionPacket;class BedrockBreakEvent implements Listener{ public function onDataReceive(DataPacketReceiveEvent $event) { $pk = $event->getPacket(); $p = $event->getPlayer(); if ($pk instanceof PlayerActionPacket) { if ($pk->action === PlayerActionPacket::ACTION_START_BREAK) { $block = $p->getLevel()->getBlockAt($pk->x, $pk->y, $pk->z); if ($block->getId() === Block::BEDROCK) { ForumThreads::make()->getScheduler()->scheduleRepeatingTask( new BedrockBreakTask($p->getInventory()->getItemInHand(), $block), 1); } } } }} Spoiler: Bedrock class (custom) PHP: <?phpnamespace mlsdmitry\ForumThreads;use pocketmine\block\BlockToolType;use pocketmine\item\Item;class Bedrock extends \pocketmine\block\Bedrock{ public function isBreakable(Item $item): bool { return true; } public function getHardness(): float { return 0.3; } public function getToolType() : int{ return BlockToolType::TYPE_PICKAXE; } public function getBlastResistance(): float { return 30; } public function getBreakTime(Item $item): float { return parent::getBreakTime($item); // TODO: Change the autogenerated stub }} Spoiler: BedrockBreakTask PHP: <?phpnamespace mlsdmitry\ForumThreads;use pocketmine\block\Block;use pocketmine\item\Item;use pocketmine\item\Tool;use pocketmine\math\Vector3;class BedrockBreakTask extends \pocketmine\scheduler\Task{ /** @var Block $block */ private $block; /** @var Tool $tool */ private $tool; private $ticks = 0; public function __construct(Item $tool, Block $block) { $this->tool = $tool; $this->block = $block; } /** * @inheritDoc */ public function onRun(int $currentTick) { if ($this->ticks >= $this->block->getBreakTime($this->tool) * 20) { $level = $this->block->getLevel(); $level->setBlock($this->block->asVector3(), new Block(Block::AIR)); $level->dropItem($this->block->asVector3()->add(0, 0.3, 0), new Item(Item::BEDROCK), new Vector3(0, 0, 0)); $this->getHandler()->cancel(); } $this->ticks++; }}