From 664a04200898ef83b8286a1f7bcb02f0a98f95b8 Mon Sep 17 00:00:00 2001 From: Joshy3282 Date: Tue, 1 Oct 2024 21:37:33 -0500 Subject: [PATCH] add https://github.com/pmmp/PocketMine-MP/pull/5800 --- README.md | 1 + src/block/Block.php | 15 ++++++++++----- src/block/Jukebox.php | 6 +++--- src/block/tile/Jukebox.php | 5 ----- src/world/Explosion.php | 4 +--- src/world/World.php | 5 +---- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 50c1e8897ea..9c7cab48495 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Additions > https://github.com/pmmp/PocketMine-MP/pull/5502 > https://github.com/pmmp/PocketMine-MP/pull/5581 > https://github.com/pmmp/PocketMine-MP/pull/5583 +> https://github.com/pmmp/PocketMine-MP/pull/5800 ## What is this? diff --git a/src/block/Block.php b/src/block/Block.php index 10b4e3cdcb8..ec2d84f0813 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -476,14 +476,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 a61dd06dbe5..604e65f178d 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 54acd60eeb8..a94072bb191 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 601f9109e27..117f4a6a53b 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -209,9 +209,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(); $this->world->setBlockAt($pos->x, $pos->y, $pos->z, $airBlock); } } diff --git a/src/world/World.php b/src/world/World.php index 1d61e2403e8..ff22de46280 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2132,10 +2132,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(); } /**