PocketMine-MP 5.15.1 git-be6754494fdbbb9dd57c058ba0e33a4a78c4581f
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
22declare(strict_types=1);
23
24namespace pocketmine\item\enchantment;
25
30use pocketmine\utils\NotCloneable;
31use pocketmine\utils\NotSerializable;
33
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
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}
__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
static validateCallableSignature(callable|CallbackType $signature, callable $subject)
Definition: Utils.php:571