mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 12:27:51 +00:00
Fixed double plants and beds sometimes dropping in creative
This commit is contained in:
parent
592ce3c9e9
commit
b8ade18888
@ -206,10 +206,10 @@ class Bed extends Transparent{
|
|||||||
return false;
|
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);
|
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
|
||||||
if(($other = $this->getOtherHalf()) !== null){
|
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;
|
return true;
|
||||||
|
@ -161,11 +161,12 @@ class Block extends Position implements BlockIds, Metadatable{
|
|||||||
/**
|
/**
|
||||||
* Do the actions needed so the block is broken with the Item
|
* Do the actions needed so the block is broken with the Item
|
||||||
*
|
*
|
||||||
* @param Item $item
|
* @param Item $item
|
||||||
|
* @param Player|null $player
|
||||||
*
|
*
|
||||||
* @return bool
|
* @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);
|
return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ class Chest extends Transparent{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item) : bool{
|
public function onBreak(Item $item, Player $player = null) : bool{
|
||||||
$t = $this->getLevel()->getTile($this);
|
$t = $this->getLevel()->getTile($this);
|
||||||
if($t instanceof TileChest){
|
if($t instanceof TileChest){
|
||||||
$t->unpair();
|
$t->unpair();
|
||||||
|
@ -246,7 +246,7 @@ abstract class Door extends Transparent{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item) : bool{
|
public function onBreak(Item $item, Player $player = null) : bool{
|
||||||
if(($this->getDamage() & 0x08) === 0x08){
|
if(($this->getDamage() & 0x08) === 0x08){
|
||||||
$down = $this->getSide(Vector3::SIDE_DOWN);
|
$down = $this->getSide(Vector3::SIDE_DOWN);
|
||||||
if($down->getId() === $this->getId()){
|
if($down->getId() === $this->getId()){
|
||||||
|
@ -97,9 +97,9 @@ class DoublePlant extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item) : bool{
|
public function onBreak(Item $item, Player $player = null) : bool{
|
||||||
if(parent::onBreak($item) and $this->isValidHalfPlant()){
|
if(parent::onBreak($item, $player) 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));
|
$this->getLevel()->useBreakOn($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), $item, $player, $player !== null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -110,16 +110,20 @@ class DoublePlant extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item) : array{
|
public function getDrops(Item $item) : array{
|
||||||
if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern
|
if($this->meta & self::BITFLAG_TOP){
|
||||||
if(mt_rand(0, 24) === 0){
|
if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern
|
||||||
return [
|
if(mt_rand(0, 24) === 0){
|
||||||
ItemFactory::get(Item::SEEDS, 0, 1)
|
return [
|
||||||
];
|
ItemFactory::get(Item::SEEDS, 0, 1)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return parent::getDrops($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getDrops($item);
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -26,6 +26,7 @@ namespace pocketmine\block;
|
|||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\Tool;
|
use pocketmine\item\Tool;
|
||||||
use pocketmine\level\Level;
|
use pocketmine\level\Level;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
class Ice extends Transparent{
|
class Ice extends Transparent{
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ class Ice extends Transparent{
|
|||||||
return Tool::TYPE_PICKAXE;
|
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);
|
$this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -78,7 +78,7 @@ class ItemFrame extends Flowable{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item) : bool{
|
public function onBreak(Item $item, Player $player = null) : bool{
|
||||||
$tile = $this->level->getTile($this);
|
$tile = $this->level->getTile($this);
|
||||||
if($tile instanceof TileItemFrame){
|
if($tile instanceof TileItemFrame){
|
||||||
//TODO: add events
|
//TODO: add events
|
||||||
@ -86,7 +86,7 @@ class ItemFrame extends Flowable{
|
|||||||
$this->level->dropItem($tile->getBlock(), $tile->getItem());
|
$this->level->dropItem($tile->getBlock(), $tile->getItem());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parent::onBreak($item);
|
return parent::onBreak($item, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onUpdate(int $type){
|
public function onUpdate(int $type){
|
||||||
|
@ -1666,7 +1666,7 @@ class Level implements ChunkManager, Metadatable{
|
|||||||
$this->addParticle(new DestroyBlockParticle($target->add(0.5, 0.5, 0.5), $target));
|
$this->addParticle(new DestroyBlockParticle($target->add(0.5, 0.5, 0.5), $target));
|
||||||
}
|
}
|
||||||
|
|
||||||
$target->onBreak($item);
|
$target->onBreak($item, $player);
|
||||||
|
|
||||||
$tile = $this->getTile($target);
|
$tile = $this->getTile($target);
|
||||||
if($tile !== null){
|
if($tile !== null){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user