PocketMine-MP
5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
Enchantment.php
1
<?php
2
3
/*
4
*
5
* ____ _ _ __ __ _ __ __ ____
6
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10
*
11
* This program is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU Lesser General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
15
*
16
* @author PocketMine Team
17
* @link http://www.pocketmine.net/
18
*
19
*
20
*/
21
22
declare(strict_types=1);
23
24
namespace
pocketmine\item\enchantment;
25
26
use
DaveRandom\CallbackValidator\CallbackType
;
27
use
DaveRandom\CallbackValidator\ParameterType
;
28
use
DaveRandom\CallbackValidator\ReturnType
;
29
use
pocketmine\lang\Translatable
;
30
use pocketmine\utils\NotCloneable;
31
use pocketmine\utils\NotSerializable;
32
use
pocketmine\utils\Utils
;
33
37
class
Enchantment
{
38
use NotCloneable;
39
use NotSerializable;
40
42
private \Closure $minEnchantingPower;
43
49
public
function
__construct
(
50
private
Translatable
|
string
$name,
51
private
int
$rarity,
52
private
int
$maxLevel,
53
?\Closure $minEnchantingPower =
null
,
54
private
int
$enchantingPowerRange = 50
55
){
56
$this->minEnchantingPower = $minEnchantingPower ?? fn(
int
$level) :
int
=> 1;
57
58
Utils::validateCallableSignature(
new
CallbackType
(
59
new
ReturnType
(
"int"
),
60
new
ParameterType
(
"level"
,
"int"
)
61
), $this->minEnchantingPower);
62
}
63
67
public
function
getName
() :
Translatable
|string{
68
return $this->name;
69
}
70
74
public
function
getRarity
() : int{
75
return $this->rarity;
76
}
77
81
public
function
getMaxLevel
() : int{
82
return $this->maxLevel;
83
}
84
88
public
function
isCompatibleWith
(
Enchantment
$other) : bool{
89
return
IncompatibleEnchantmentRegistry
::getInstance()->areCompatible($this, $other);
90
}
91
100
public
function
getMinEnchantingPower
(
int
$level) : int{
101
return ($this->minEnchantingPower)($level);
102
}
103
112
public
function
getMaxEnchantingPower
(
int
$level) : int{
113
return $this->getMinEnchantingPower($level) + $this->enchantingPowerRange;
114
}
115
}
DaveRandom\CallbackValidator\CallbackType
Definition
CallbackType.php:6
DaveRandom\CallbackValidator\ParameterType
Definition
ParameterType.php:6
DaveRandom\CallbackValidator\ReturnType
Definition
ReturnType.php:6
pocketmine\item\enchantment\Enchantment
Definition
Enchantment.php:37
pocketmine\item\enchantment\Enchantment\getMaxLevel
getMaxLevel()
Definition
Enchantment.php:81
pocketmine\item\enchantment\Enchantment\isCompatibleWith
isCompatibleWith(Enchantment $other)
Definition
Enchantment.php:88
pocketmine\item\enchantment\Enchantment\__construct
__construct(private Translatable|string $name, private int $rarity, private int $maxLevel, ?\Closure $minEnchantingPower=null, private int $enchantingPowerRange=50)
Definition
Enchantment.php:49
pocketmine\item\enchantment\Enchantment\getMinEnchantingPower
getMinEnchantingPower(int $level)
Definition
Enchantment.php:100
pocketmine\item\enchantment\Enchantment\getRarity
getRarity()
Definition
Enchantment.php:74
pocketmine\item\enchantment\Enchantment\getName
getName()
Definition
Enchantment.php:67
pocketmine\item\enchantment\Enchantment\getMaxEnchantingPower
getMaxEnchantingPower(int $level)
Definition
Enchantment.php:112
pocketmine\item\enchantment\IncompatibleEnchantmentRegistry
Definition
IncompatibleEnchantmentRegistry.php:37
pocketmine\lang\Translatable
Definition
Translatable.php:26
pocketmine\utils\Utils
Definition
Utils.php:103
src
item
enchantment
Enchantment.php
Generated by
1.12.0