From 0a90a5928a86552003a3dcbceb2c019b0d2ccaa8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 1 Aug 2023 12:33:36 +0100 Subject: [PATCH] Added TallGrassTrait, remove weirdly specific logic from FortuneDropHelper this needs to be dealt with before release otherwise we'll be stuck with FortuneDropHelper::grass() this is the obvious solution and should have been done some time ago - stuff like flammability was already a problem for double tall grass anyway --- src/block/DoubleTallGrass.php | 7 +++- src/block/TallGrass.php | 19 +--------- src/block/utils/FortuneDropHelper.php | 21 ----------- src/block/utils/TallGrassTrait.php | 54 +++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 40 deletions(-) create mode 100644 src/block/utils/TallGrassTrait.php diff --git a/src/block/DoubleTallGrass.php b/src/block/DoubleTallGrass.php index e90f2ec61..42a6fb4dc 100644 --- a/src/block/DoubleTallGrass.php +++ b/src/block/DoubleTallGrass.php @@ -23,10 +23,13 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\block\utils\FortuneDropHelper; +use pocketmine\block\utils\TallGrassTrait; use pocketmine\item\Item; class DoubleTallGrass extends DoublePlant{ + use TallGrassTrait { + getDropsForIncompatibleTool as traitGetDropsForIncompatibleTool; + } public function canBeReplaced() : bool{ return true; @@ -34,7 +37,7 @@ class DoubleTallGrass extends DoublePlant{ public function getDropsForIncompatibleTool(Item $item) : array{ if($this->top){ - return FortuneDropHelper::grass($item); + return $this->traitGetDropsForIncompatibleTool($item); } return []; } diff --git a/src/block/TallGrass.php b/src/block/TallGrass.php index 019b911bc..d8c34b001 100644 --- a/src/block/TallGrass.php +++ b/src/block/TallGrass.php @@ -23,7 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; -use pocketmine\block\utils\FortuneDropHelper; +use pocketmine\block\utils\TallGrassTrait; use pocketmine\item\Item; use pocketmine\math\Facing; use pocketmine\math\Vector3; @@ -31,10 +31,7 @@ use pocketmine\player\Player; use pocketmine\world\BlockTransaction; class TallGrass extends Flowable{ - - public function canBeReplaced() : bool{ - return true; - } + use TallGrassTrait; private function canBeSupportedBy(Block $block) : bool{ return $block->hasTypeTag(BlockTypeTags::DIRT) || $block->hasTypeTag(BlockTypeTags::MUD); @@ -53,16 +50,4 @@ class TallGrass extends Flowable{ $this->position->getWorld()->useBreakOn($this->position); } } - - public function getDropsForIncompatibleTool(Item $item) : array{ - return FortuneDropHelper::grass($item); - } - - public function getFlameEncouragement() : int{ - return 60; - } - - public function getFlammability() : int{ - return 100; - } } diff --git a/src/block/utils/FortuneDropHelper.php b/src/block/utils/FortuneDropHelper.php index 4bce36138..4cf9b0249 100644 --- a/src/block/utils/FortuneDropHelper.php +++ b/src/block/utils/FortuneDropHelper.php @@ -25,7 +25,6 @@ namespace pocketmine\block\utils; use pocketmine\item\enchantment\VanillaEnchantments; use pocketmine\item\Item; -use pocketmine\item\VanillaItems; use function max; use function min; use function mt_getrandmax; @@ -85,26 +84,6 @@ final class FortuneDropHelper{ return $count; } - /** - * Grass have a fixed chance to drop wheat seed. - * Fortune level increases the maximum number of seeds that can be dropped. - * A discrete uniform distribution is used to determine the number of seeds dropped. - * - * TODO: I'm not sure this really belongs here, but it's preferable not to duplicate this code between grass and - * tall grass. - * - * @return Item[] - */ - public static function grass(Item $usedItem) : array{ - if(FortuneDropHelper::bonusChanceDivisor($usedItem, 8, 2)){ - return [ - VanillaItems::WHEAT_SEEDS() - ]; - } - - return []; - } - /** * Adds the fortune level to the base max and picks a random number between the minimim and adjusted maximum. * Each amount in the range has an equal chance of being picked. diff --git a/src/block/utils/TallGrassTrait.php b/src/block/utils/TallGrassTrait.php new file mode 100644 index 000000000..88fc36e12 --- /dev/null +++ b/src/block/utils/TallGrassTrait.php @@ -0,0 +1,54 @@ +