mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 20:07:09 +00:00
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:
parent
46f24b165a
commit
0a90a5928a
@ -23,10 +23,13 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\FortuneDropHelper;
|
use pocketmine\block\utils\TallGrassTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
|
|
||||||
class DoubleTallGrass extends DoublePlant{
|
class DoubleTallGrass extends DoublePlant{
|
||||||
|
use TallGrassTrait {
|
||||||
|
getDropsForIncompatibleTool as traitGetDropsForIncompatibleTool;
|
||||||
|
}
|
||||||
|
|
||||||
public function canBeReplaced() : bool{
|
public function canBeReplaced() : bool{
|
||||||
return true;
|
return true;
|
||||||
@ -34,7 +37,7 @@ class DoubleTallGrass extends DoublePlant{
|
|||||||
|
|
||||||
public function getDropsForIncompatibleTool(Item $item) : array{
|
public function getDropsForIncompatibleTool(Item $item) : array{
|
||||||
if($this->top){
|
if($this->top){
|
||||||
return FortuneDropHelper::grass($item);
|
return $this->traitGetDropsForIncompatibleTool($item);
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\FortuneDropHelper;
|
use pocketmine\block\utils\TallGrassTrait;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
@ -31,10 +31,7 @@ use pocketmine\player\Player;
|
|||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
|
||||||
class TallGrass extends Flowable{
|
class TallGrass extends Flowable{
|
||||||
|
use TallGrassTrait;
|
||||||
public function canBeReplaced() : bool{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function canBeSupportedBy(Block $block) : bool{
|
private function canBeSupportedBy(Block $block) : bool{
|
||||||
return $block->hasTypeTag(BlockTypeTags::DIRT) || $block->hasTypeTag(BlockTypeTags::MUD);
|
return $block->hasTypeTag(BlockTypeTags::DIRT) || $block->hasTypeTag(BlockTypeTags::MUD);
|
||||||
@ -53,16 +50,4 @@ class TallGrass extends Flowable{
|
|||||||
$this->position->getWorld()->useBreakOn($this->position);
|
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ namespace pocketmine\block\utils;
|
|||||||
|
|
||||||
use pocketmine\item\enchantment\VanillaEnchantments;
|
use pocketmine\item\enchantment\VanillaEnchantments;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\VanillaItems;
|
|
||||||
use function max;
|
use function max;
|
||||||
use function min;
|
use function min;
|
||||||
use function mt_getrandmax;
|
use function mt_getrandmax;
|
||||||
@ -85,26 +84,6 @@ final class FortuneDropHelper{
|
|||||||
return $count;
|
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.
|
* 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.
|
* Each amount in the range has an equal chance of being picked.
|
||||||
|
54
src/block/utils/TallGrassTrait.php
Normal file
54
src/block/utils/TallGrassTrait.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user