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
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
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}
__construct(private Translatable|string $name, private int $rarity, private int $maxLevel, ?\Closure $minEnchantingPower=null, private int $enchantingPowerRange=50)