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:
Dylan K. Taylor
2019-02-25 18:40:04 +00:00
parent fb378d9091
commit 6124f93cb4
4 changed files with 46 additions and 30 deletions

View File

@ -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

View File

@ -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);