diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index ff5fe2af5..8f7b6102f 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -207,6 +207,10 @@ class Bed extends Transparent{ return []; } + public function isAffectedBySilkTouch() : bool{ + return false; + } + public function getAffectedBlocks() : array{ if(($other = $this->getOtherHalf()) !== null){ return [$this, $other]; diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 6c962356c..d910015e6 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -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 diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 8ac27faaf..49f352b43 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -89,6 +89,10 @@ class Cake extends Transparent implements FoodSource{ return []; } + public function isAffectedBySilkTouch() : bool{ + return false; + } + public function onActivate(Item $item, Player $player = null) : bool{ if($player !== null){ $player->consumeObject($this); diff --git a/src/pocketmine/block/CocoaBlock.php b/src/pocketmine/block/CocoaBlock.php index f98ec386f..fca535a99 100644 --- a/src/pocketmine/block/CocoaBlock.php +++ b/src/pocketmine/block/CocoaBlock.php @@ -44,4 +44,8 @@ class CocoaBlock extends Transparent{ } //TODO + + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index e0569bf8f..1e425fb19 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -95,4 +95,8 @@ abstract class Crops extends Flowable{ return false; } + + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 06a2a4521..bea2e6d23 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -278,6 +278,10 @@ abstract class Door extends Transparent{ return []; } + public function isAffectedBySilkTouch() : bool{ + return false; + } + public function getAffectedBlocks() : array{ if(($this->getDamage() & 0x08) === 0x08){ $down = $this->getSide(Vector3::SIDE_DOWN); diff --git a/src/pocketmine/block/DoubleSlab.php b/src/pocketmine/block/DoubleSlab.php index 7ccecccd0..903e994fa 100644 --- a/src/pocketmine/block/DoubleSlab.php +++ b/src/pocketmine/block/DoubleSlab.php @@ -44,4 +44,7 @@ abstract class DoubleSlab extends Solid{ ]; } + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index 789c97845..054866fda 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -112,4 +112,8 @@ class Farmland extends Transparent{ ItemFactory::get(Item::DIRT) ]; } + + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index 1434f18dd..c5c9c581c 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -114,4 +114,7 @@ class FlowerPot extends Flowable{ return $items; } + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/Ice.php b/src/pocketmine/block/Ice.php index 549517b70..f99653e6d 100644 --- a/src/pocketmine/block/Ice.php +++ b/src/pocketmine/block/Ice.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\item\enchantment\Enchantment; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\Player; @@ -56,7 +57,10 @@ class Ice extends Transparent{ } public function onBreak(Item $item, Player $player = null) : bool{ - return $this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true); + if(!$item->hasEnchantment(Enchantment::SILK_TOUCH)){ + return $this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true); + } + return parent::onBreak($item, $player); } public function ticksRandomly() : bool{ diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index a650beda9..4ae4baddf 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -112,4 +112,8 @@ class ItemFrame extends Flowable{ return $drops; } + + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/MonsterSpawner.php b/src/pocketmine/block/MonsterSpawner.php index af7038f8e..555af6f62 100644 --- a/src/pocketmine/block/MonsterSpawner.php +++ b/src/pocketmine/block/MonsterSpawner.php @@ -53,4 +53,8 @@ class MonsterSpawner extends Transparent{ public function getDropsForCompatibleTool(Item $item) : array{ return []; } + + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/NetherWartPlant.php b/src/pocketmine/block/NetherWartPlant.php index 7ca4b236f..f6c180498 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -90,4 +90,8 @@ class NetherWartPlant extends Flowable{ ItemFactory::get($this->getItemId(), 0, ($this->getDamage() === 3 ? mt_rand(2, 4) : 1)) ]; } + + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index 34f43c35c..9e4c6c425 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -81,4 +81,8 @@ class Skull extends Flowable{ return []; } + + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index af6a00ce3..68501f3c9 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -96,4 +96,8 @@ class SnowLayer extends Flowable{ ItemFactory::get(Item::SNOWBALL) //TODO: check layer count ]; } + + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/StandingBanner.php b/src/pocketmine/block/StandingBanner.php index 4b9d6b01e..bb5cea38d 100644 --- a/src/pocketmine/block/StandingBanner.php +++ b/src/pocketmine/block/StandingBanner.php @@ -105,4 +105,8 @@ class StandingBanner extends Transparent{ return [$drop]; } + + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/block/Tripwire.php b/src/pocketmine/block/Tripwire.php index fc5a6010a..9a1f718ee 100644 --- a/src/pocketmine/block/Tripwire.php +++ b/src/pocketmine/block/Tripwire.php @@ -43,4 +43,8 @@ class Tripwire extends Flowable{ ItemFactory::get(Item::STRING) ]; } + + public function isAffectedBySilkTouch() : bool{ + return false; + } } diff --git a/src/pocketmine/item/enchantment/Enchantment.php b/src/pocketmine/item/enchantment/Enchantment.php index 3d95cd6a8..ff79d1a8f 100644 --- a/src/pocketmine/item/enchantment/Enchantment.php +++ b/src/pocketmine/item/enchantment/Enchantment.php @@ -95,7 +95,7 @@ class Enchantment{ self::registerEnchantment(new Enchantment(self::RESPIRATION, "%enchantment.oxygen", self::RARITY_RARE, self::SLOT_HEAD, 3)); self::registerEnchantment(new Enchantment(self::EFFICIENCY, "%enchantment.digging", self::RARITY_COMMON, self::SLOT_DIG | self::SLOT_SHEARS, 5)); - + self::registerEnchantment(new Enchantment(self::SILK_TOUCH, "%enchantment.untouching", self::RARITY_MYTHIC, self::SLOT_DIG | self::SLOT_SHEARS, 1)); self::registerEnchantment(new Enchantment(self::UNBREAKING, "%enchantment.durability", self::RARITY_UNCOMMON, self::SLOT_ALL, 3)); //TODO: item type flags need to be split up }