PocketMine-MP
5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
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
51
public
function
__construct
(
52
private
Translatable
|
string
$name,
53
private
int
$rarity,
54
private
int
$primaryItemFlags,
55
private
int
$secondaryItemFlags,
56
private
int
$maxLevel,
57
?\Closure $minEnchantingPower =
null
,
58
private
int
$enchantingPowerRange = 50
59
){
60
$this->minEnchantingPower = $minEnchantingPower ?? fn(
int
$level) :
int
=> 1;
61
62
Utils::validateCallableSignature(
new
CallbackType
(
63
new
ReturnType
(
"int"
),
64
new
ParameterType
(
"level"
,
"int"
)
65
), $this->minEnchantingPower);
66
}
67
71
public
function
getName
() :
Translatable
|string{
72
return $this->name;
73
}
74
78
public
function
getRarity
() : int{
79
return $this->rarity;
80
}
81
88
public
function
getPrimaryItemFlags
() : int{
89
return $this->primaryItemFlags;
90
}
91
99
public
function
getSecondaryItemFlags
() : int{
100
return $this->secondaryItemFlags;
101
}
102
109
public
function
hasPrimaryItemType
(
int
$flag) : bool{
110
return ($this->primaryItemFlags & $flag) !== 0;
111
}
112
119
public
function
hasSecondaryItemType
(
int
$flag) : bool{
120
return ($this->secondaryItemFlags & $flag) !== 0;
121
}
122
126
public
function
getMaxLevel
() : int{
127
return $this->maxLevel;
128
}
129
133
public
function
isCompatibleWith
(
Enchantment
$other) : bool{
134
return
IncompatibleEnchantmentRegistry
::getInstance()->areCompatible($this, $other);
135
}
136
145
public
function
getMinEnchantingPower
(
int
$level) : int{
146
return ($this->minEnchantingPower)($level);
147
}
148
157
public
function
getMaxEnchantingPower
(
int
$level) : int{
158
return $this->getMinEnchantingPower($level) + $this->enchantingPowerRange;
159
}
160
}
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\getPrimaryItemFlags
getPrimaryItemFlags()
Definition
Enchantment.php:88
pocketmine\item\enchantment\Enchantment\getMaxLevel
getMaxLevel()
Definition
Enchantment.php:126
pocketmine\item\enchantment\Enchantment\isCompatibleWith
isCompatibleWith(Enchantment $other)
Definition
Enchantment.php:133
pocketmine\item\enchantment\Enchantment\hasPrimaryItemType
hasPrimaryItemType(int $flag)
Definition
Enchantment.php:109
pocketmine\item\enchantment\Enchantment\getMinEnchantingPower
getMinEnchantingPower(int $level)
Definition
Enchantment.php:145
pocketmine\item\enchantment\Enchantment\getSecondaryItemFlags
getSecondaryItemFlags()
Definition
Enchantment.php:99
pocketmine\item\enchantment\Enchantment\__construct
__construct(private Translatable|string $name, private int $rarity, private int $primaryItemFlags, private int $secondaryItemFlags, private int $maxLevel, ?\Closure $minEnchantingPower=null, private int $enchantingPowerRange=50)
Definition
Enchantment.php:51
pocketmine\item\enchantment\Enchantment\getRarity
getRarity()
Definition
Enchantment.php:78
pocketmine\item\enchantment\Enchantment\getName
getName()
Definition
Enchantment.php:71
pocketmine\item\enchantment\Enchantment\hasSecondaryItemType
hasSecondaryItemType(int $flag)
Definition
Enchantment.php:119
pocketmine\item\enchantment\Enchantment\getMaxEnchantingPower
getMaxEnchantingPower(int $level)
Definition
Enchantment.php:157
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