diff --git a/src/block/Block.php b/src/block/Block.php index fd644eae4c..463ea208af 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -483,14 +483,19 @@ public function getEnchantmentTags() : array{ * @param Item[] &$returnedItems Items to be added to the target's inventory (or dropped, if full) */ public function onBreak(Item $item, ?Player $player = null, array &$returnedItems = []) : bool{ - $world = $this->position->getWorld(); - if(($t = $world->getTile($this->position)) !== null){ - $t->onBlockDestroyed(); - } - $world->setBlock($this->position, VanillaBlocks::AIR()); + $this->position->getWorld()->setBlock($this->position, VanillaBlocks::AIR()); return true; } + /** + * Called when this block is destroyed either when a player breaks it or is hit by an explosion. + */ + public function onDestroy() : void{ + if(($t = $this->position->getWorld()->getTile($this->position)) !== null){ + $t->onBlockDestroyed(); //needed to create drops for inventories + } + } + /** * Called when this block or a block immediately adjacent to it changes state. */ diff --git a/src/block/Jukebox.php b/src/block/Jukebox.php index a61dd06dbe..604e65f178 100644 --- a/src/block/Jukebox.php +++ b/src/block/Jukebox.php @@ -84,9 +84,9 @@ public function stopSound() : void{ $this->position->getWorld()->addSound($this->position, new RecordStopSound()); } - public function onBreak(Item $item, ?Player $player = null, array &$returnedItems = []) : bool{ - $this->stopSound(); - return parent::onBreak($item, $player, $returnedItems); + public function onDestroy() : void{ + $this->ejectRecord(); + parent::onDestroy(); } public function getDropsForCompatibleTool(Item $item) : array{ diff --git a/src/block/tile/Jukebox.php b/src/block/tile/Jukebox.php index 54acd60eeb..a94072bb19 100644 --- a/src/block/tile/Jukebox.php +++ b/src/block/tile/Jukebox.php @@ -27,7 +27,6 @@ use pocketmine\item\Record; use pocketmine\nbt\tag\CompoundTag; use pocketmine\network\mcpe\convert\TypeConverter; -use pocketmine\world\sound\RecordStopSound; class Jukebox extends Spawnable{ private const TAG_RECORD = "RecordItem"; //Item CompoundTag @@ -63,8 +62,4 @@ protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->setTag(self::TAG_RECORD, TypeConverter::getInstance()->getItemTranslator()->toNetworkNbt($this->record)); } } - - protected function onBlockDestroyedHook() : void{ - $this->position->getWorld()->addSound($this->position, new RecordStopSound()); - } } diff --git a/src/world/Explosion.php b/src/world/Explosion.php index 9e83d06beb..26c68df663 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -250,9 +250,7 @@ public function explodeB() : bool{ $this->world->dropItem($pos->add(0.5, 0.5, 0.5), $drop); } } - if(($t = $this->world->getTileAt($pos->x, $pos->y, $pos->z)) !== null){ - $t->onBlockDestroyed(); //needed to create drops for inventories - } + $block->onDestroy(); $targetBlock = isset($this->fireIgnitions[$hash]) && $block->getSide(Facing::DOWN)->getSupportType(Facing::UP) === SupportType::FULL ? diff --git a/src/world/World.php b/src/world/World.php index 7917ea18c0..64e544af89 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2225,11 +2225,7 @@ private function destroyBlockInternal(Block $target, Item $item, ?Player $player } $target->onBreak($item, $player, $returnedItems); - - $tile = $this->getTile($target->getPosition()); - if($tile !== null){ - $tile->onBlockDestroyed(); - } + $target->onDestroy(); } /**