PocketMine-MP 5.33.2 git-919492bdcad8510eb6606439eb77e1c604f1d1ea
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
27use pocketmine\utils\NotCloneable;
28use pocketmine\utils\NotSerializable;
30
35 use NotCloneable;
36 use NotSerializable;
37
39 private \Closure $minEnchantingPower;
40
46 public function __construct(
47 private Translatable|string $name,
48 private int $rarity,
49 private int $maxLevel,
50 ?\Closure $minEnchantingPower = null,
51 private int $enchantingPowerRange = 50
52 ){
53 $this->minEnchantingPower = $minEnchantingPower ?? fn(int $level) : int => 1;
54
55 Utils::validateCallableSignature(fn(int $level) : int => die(), $this->minEnchantingPower);
56 }
57
61 public function getName() : Translatable|string{
62 return $this->name;
63 }
64
68 public function getRarity() : int{
69 return $this->rarity;
70 }
71
75 public function getMaxLevel() : int{
76 return $this->maxLevel;
77 }
78
82 public function isCompatibleWith(Enchantment $other) : bool{
83 return IncompatibleEnchantmentRegistry::getInstance()->areCompatible($this, $other);
84 }
85
94 public function getMinEnchantingPower(int $level) : int{
95 return ($this->minEnchantingPower)($level);
96 }
97
106 public function getMaxEnchantingPower(int $level) : int{
107 return $this->getMinEnchantingPower($level) + $this->enchantingPowerRange;
108 }
109}
__construct(private Translatable|string $name, private int $rarity, private int $maxLevel, ?\Closure $minEnchantingPower=null, private int $enchantingPowerRange=50)