Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
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 @@ -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 ?
Expand Down
6 changes: 1 addition & 5 deletions src/world/World.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down