Skip to content

Commit

Permalink
add pmmp#5800
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshy3282 committed Oct 2, 2024
1 parent 86bef06 commit 664a042
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
15 changes: 10 additions & 5 deletions src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/block/Jukebox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 0 additions & 5 deletions src/block/tile/Jukebox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
4 changes: 1 addition & 3 deletions src/world/Explosion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/world/World.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 664a042

Please sign in to comment.