Enchantment: Implement Silk Touch (#1912)

This commit is contained in:
Dylan K. Taylor
2018-01-14 13:37:27 +00:00
committed by GitHub
parent 96f6362117
commit 8d7c65585c
18 changed files with 92 additions and 2 deletions

View File

@ -27,6 +27,7 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\entity\Entity;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\Item;
use pocketmine\item\ItemFactory;
use pocketmine\level\Level;
@ -433,6 +434,10 @@ class Block extends Position implements BlockIds, Metadatable{
*/
public function getDrops(Item $item) : array{
if($this->isCompatibleWithTool($item)){
if($this->isAffectedBySilkTouch() and $item->hasEnchantment(Enchantment::SILK_TOUCH)){
return $this->getSilkTouchDrops($item);
}
return $this->getDropsForCompatibleTool($item);
}
@ -452,6 +457,29 @@ class Block extends Position implements BlockIds, Metadatable{
];
}
/**
* Returns an array of Items to be dropped when the block is broken using a compatible Silk Touch-enchanted tool.
*
* @param Item $item
*
* @return Item[]
*/
public function getSilkTouchDrops(Item $item) : array{
return [
ItemFactory::get($this->getItemId(), $this->getVariant())
];
}
/**
* Returns whether Silk Touch enchanted tools will cause this block to drop as itself. Since most blocks drop
* themselves anyway, this is implicitly true.
*
* @return bool
*/
public function isAffectedBySilkTouch() : bool{
return true;
}
/**
* Returns the item that players will equip when middle-clicking on this block.
* @return Item