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
This commit is contained in:
Dylan K. Taylor 2023-08-01 12:33:36 +01:00
parent 46f24b165a
commit 0a90a5928a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
4 changed files with 61 additions and 40 deletions

View File

@ -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 [];
}

View File

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

View File

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

View File

@ -0,0 +1,54 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\block\utils;
use pocketmine\item\Item;
use pocketmine\item\VanillaItems;
/**
* @internal
*/
trait TallGrassTrait{
public function canBeReplaced() : bool{
return true;
}
public function getDropsForIncompatibleTool(Item $item) : array{
if(FortuneDropHelper::bonusChanceDivisor($item, 8, 2)){
return [
VanillaItems::WHEAT_SEEDS()
];
}
return [];
}
public function getFlameEncouragement() : int{
return 60;
}
public function getFlammability() : int{
return 100;
}
}