mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Player: Clean up item frame drop-item hack
This is now re-routed through a newly-created attack-block handler. Closes #339
This commit is contained in:
@ -380,6 +380,20 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this block is attacked (left-clicked). This is called when a player left-clicks the block to try and
|
||||
* start to break it in survival mode.
|
||||
*
|
||||
* @param Item $item
|
||||
* @param int $face
|
||||
* @param Player|null $player
|
||||
*
|
||||
* @return bool if an action took place, prevents starting to break the block if true.
|
||||
*/
|
||||
public function onAttack(Item $item, int $face, ?Player $player = null) : bool{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a base value used to compute block break times.
|
||||
* @return float
|
||||
|
@ -156,6 +156,18 @@ class ItemFrame extends Flowable{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onAttack(Item $item, int $face, ?Player $player = null) : bool{
|
||||
if($this->framedItem === null){
|
||||
return false;
|
||||
}
|
||||
if(lcg_value() <= $this->itemDropChance){
|
||||
$this->level->dropItem($this->add(0.5, 0.5, 0.5), $this->getFramedItem());
|
||||
}
|
||||
$this->setFramedItem(null);
|
||||
$this->level->setBlock($this, $this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
if(!$this->getSide(Facing::opposite($this->facing))->isSolid()){
|
||||
$this->level->useBreakOn($this);
|
||||
|
Reference in New Issue
Block a user