From 7dcc4891ca2d841aaa9bb757308a9f1a2940e147 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 11 Jun 2021 19:09:14 +0100 Subject: [PATCH] Block: added getDropsForIncompatibleTool() --- src/block/Block.php | 9 +++++++++ src/block/DeadBush.php | 12 ++++-------- src/block/DoubleTallGrass.php | 10 ++++------ src/block/TallGrass.php | 6 +----- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/block/Block.php b/src/block/Block.php index 1dceaf22d..0657c94b3 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -369,6 +369,15 @@ class Block{ return [$this->asItem()]; } + /** + * Returns the items dropped by this block when broken with an incorrect tool type (or tool with a too-low tier). + * + * @return Item[] + */ + public function getDropsForIncompatibleTool(Item $item) : array{ + return []; + } + /** * Returns an array of Items to be dropped when the block is broken using a compatible Silk Touch-enchanted tool. * diff --git a/src/block/DeadBush.php b/src/block/DeadBush.php index 3f6f4d8a7..7d7a933bc 100644 --- a/src/block/DeadBush.php +++ b/src/block/DeadBush.php @@ -47,14 +47,10 @@ class DeadBush extends Flowable{ } } - public function getDrops(Item $item) : array{ - if(!$this->breakInfo->isToolCompatible($item)){ - return [ - VanillaItems::STICK()->setCount(mt_rand(0, 2)) - ]; - } - - return parent::getDrops($item); + public function getDropsForIncompatibleTool(Item $item) : array{ + return [ + VanillaItems::STICK()->setCount(mt_rand(0, 2)) + ]; } public function isAffectedBySilkTouch() : bool{ diff --git a/src/block/DoubleTallGrass.php b/src/block/DoubleTallGrass.php index 7c6769800..6fee40e32 100644 --- a/src/block/DoubleTallGrass.php +++ b/src/block/DoubleTallGrass.php @@ -33,12 +33,10 @@ class DoubleTallGrass extends DoublePlant{ return true; } - public function getDrops(Item $item) : array{ - if($this->top and !$this->breakInfo->isToolCompatible($item) and mt_rand(0, 7) === 0){ - return [ - VanillaItems::WHEAT_SEEDS() - ]; + public function getDropsForIncompatibleTool(Item $item) : array{ + if($this->top and mt_rand(0, 7) === 0){ + return [VanillaItems::WHEAT_SEEDS()]; } - return parent::getDrops($item); + return []; } } diff --git a/src/block/TallGrass.php b/src/block/TallGrass.php index fd23ec720..6140a855c 100644 --- a/src/block/TallGrass.php +++ b/src/block/TallGrass.php @@ -52,11 +52,7 @@ class TallGrass extends Flowable{ } } - public function getDrops(Item $item) : array{ - if($this->breakInfo->isToolCompatible($item)){ - return parent::getDrops($item); - } - + public function getDropsForIncompatibleTool(Item $item) : array{ if(mt_rand(0, 15) === 0){ return [ VanillaItems::WHEAT_SEEDS()