diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index c8b6029e1..3cbad3758 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -206,10 +206,10 @@ class Bed extends Transparent{ return false; } - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true); if(($other = $this->getOtherHalf()) !== null){ - $this->getLevel()->useBreakOn($other); //make sure tiles get removed + $this->getLevel()->useBreakOn($other, $item, $player, $player !== null); //make sure tiles get removed } return true; diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index adc015868..37bd54387 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -161,11 +161,12 @@ class Block extends Position implements BlockIds, Metadatable{ /** * Do the actions needed so the block is broken with the Item * - * @param Item $item + * @param Item $item + * @param Player|null $player * * @return bool */ - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true); } diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 3ed499621..a3a3376c1 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -124,7 +124,7 @@ class Chest extends Transparent{ return true; } - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ $t = $this->getLevel()->getTile($this); if($t instanceof TileChest){ $t->unpair(); diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index bec9b2998..bd6b2f899 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -246,7 +246,7 @@ abstract class Door extends Transparent{ return false; } - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ if(($this->getDamage() & 0x08) === 0x08){ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === $this->getId()){ diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index f2abf8a9a..4050536c6 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -97,9 +97,9 @@ class DoublePlant extends Flowable{ return false; } - public function onBreak(Item $item) : bool{ - if(parent::onBreak($item) and $this->isValidHalfPlant()){ - return $this->getLevel()->setBlock($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), BlockFactory::get(Block::AIR)); + public function onBreak(Item $item, Player $player = null) : bool{ + if(parent::onBreak($item, $player) and $this->isValidHalfPlant()){ + $this->getLevel()->useBreakOn($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), $item, $player, $player !== null); } return false; @@ -110,16 +110,20 @@ class DoublePlant extends Flowable{ } public function getDrops(Item $item) : array{ - if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern - if(mt_rand(0, 24) === 0){ - return [ - ItemFactory::get(Item::SEEDS, 0, 1) - ]; + if($this->meta & self::BITFLAG_TOP){ + if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern + if(mt_rand(0, 24) === 0){ + return [ + ItemFactory::get(Item::SEEDS, 0, 1) + ]; + } + + return []; } - return []; + return parent::getDrops($item); } - return parent::getDrops($item); + return []; } } \ No newline at end of file diff --git a/src/pocketmine/block/Ice.php b/src/pocketmine/block/Ice.php index bbf20fbcb..3829fa4a6 100644 --- a/src/pocketmine/block/Ice.php +++ b/src/pocketmine/block/Ice.php @@ -26,6 +26,7 @@ namespace pocketmine\block; use pocketmine\item\Item; use pocketmine\item\Tool; use pocketmine\level\Level; +use pocketmine\Player; class Ice extends Transparent{ @@ -51,7 +52,7 @@ class Ice extends Transparent{ return Tool::TYPE_PICKAXE; } - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ $this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true); return true; diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index cc8abd8d9..d92e16a3a 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -78,7 +78,7 @@ class ItemFrame extends Flowable{ return true; } - public function onBreak(Item $item) : bool{ + public function onBreak(Item $item, Player $player = null) : bool{ $tile = $this->level->getTile($this); if($tile instanceof TileItemFrame){ //TODO: add events @@ -86,7 +86,7 @@ class ItemFrame extends Flowable{ $this->level->dropItem($tile->getBlock(), $tile->getItem()); } } - return parent::onBreak($item); + return parent::onBreak($item, $player); } public function onUpdate(int $type){ diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index b22f2756e..0d80423c6 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -1666,7 +1666,7 @@ class Level implements ChunkManager, Metadatable{ $this->addParticle(new DestroyBlockParticle($target->add(0.5, 0.5, 0.5), $target)); } - $target->onBreak($item); + $target->onBreak($item, $player); $tile = $this->getTile($target); if($tile !== null){