mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 07:39:42 +00:00
Moved enchantment ID handling to pocketmine/data/bedrock package
this permits plugins to register their own enchantments mapped to MCPE IDs again.
This commit is contained in:
@@ -31,7 +31,7 @@ use function constant;
|
||||
class Enchantment{
|
||||
|
||||
/** @var int */
|
||||
private $id;
|
||||
private $internalRuntimeId;
|
||||
/** @var string */
|
||||
private $name;
|
||||
/** @var int */
|
||||
@@ -43,8 +43,8 @@ class Enchantment{
|
||||
/** @var int */
|
||||
private $maxLevel;
|
||||
|
||||
public function __construct(int $id, string $name, int $rarity, int $primaryItemFlags, int $secondaryItemFlags, int $maxLevel){
|
||||
$this->id = $id;
|
||||
public function __construct(int $internalRuntimeId, string $name, int $rarity, int $primaryItemFlags, int $secondaryItemFlags, int $maxLevel){
|
||||
$this->internalRuntimeId = $internalRuntimeId;
|
||||
$this->name = $name;
|
||||
$this->rarity = $rarity;
|
||||
$this->primaryItemFlags = $primaryItemFlags;
|
||||
@@ -53,10 +53,11 @@ class Enchantment{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of this enchantment as per Minecraft PE
|
||||
* Returns the internal runtime ID of this enchantment.
|
||||
* WARNING: DO NOT STORE THIS IDENTIFIER - IT MAY CHANGE AFTER RESTART
|
||||
*/
|
||||
public function getId() : int{
|
||||
return $this->id;
|
||||
public function getRuntimeId() : int{
|
||||
return $this->internalRuntimeId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -53,10 +53,11 @@ final class EnchantmentInstance{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type identifier of this enchantment instance.
|
||||
* Returns the runtime type identifier of this enchantment instance.
|
||||
* WARNING: DO NOT STORE THIS IDENTIFIER - IT MAY CHANGE AFTER SERVER RESTART
|
||||
*/
|
||||
public function getId() : int{
|
||||
return $this->enchantment->getId();
|
||||
public function getRuntimeId() : int{
|
||||
return $this->enchantment->getRuntimeId();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -38,8 +38,8 @@ class ProtectionEnchantment extends Enchantment{
|
||||
*
|
||||
* @param int[]|null $applicableDamageTypes EntityDamageEvent::CAUSE_* constants which this enchantment type applies to, or null if it applies to all types of damage.
|
||||
*/
|
||||
public function __construct(int $id, string $name, int $rarity, int $primaryItemFlags, int $secondaryItemFlags, int $maxLevel, float $typeModifier, ?array $applicableDamageTypes){
|
||||
parent::__construct($id, $name, $rarity, $primaryItemFlags, $secondaryItemFlags, $maxLevel);
|
||||
public function __construct(int $internalRuntimeId, string $name, int $rarity, int $primaryItemFlags, int $secondaryItemFlags, int $maxLevel, float $typeModifier, ?array $applicableDamageTypes){
|
||||
parent::__construct($internalRuntimeId, $name, $rarity, $primaryItemFlags, $secondaryItemFlags, $maxLevel);
|
||||
|
||||
$this->typeModifier = $typeModifier;
|
||||
if($applicableDamageTypes !== null){
|
||||
|
@@ -25,7 +25,6 @@ namespace pocketmine\item\enchantment;
|
||||
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\utils\RegistryTrait;
|
||||
use function array_key_exists;
|
||||
|
||||
/**
|
||||
* This doc-block is generated automatically, do not modify it manually.
|
||||
@@ -55,12 +54,6 @@ use function array_key_exists;
|
||||
final class VanillaEnchantments{
|
||||
use RegistryTrait;
|
||||
|
||||
/**
|
||||
* @var Enchantment[]
|
||||
* @phpstan-var array<int, Enchantment>
|
||||
*/
|
||||
private static $mcpeIdMap = [];
|
||||
|
||||
protected static function setup() : void{
|
||||
self::register("PROTECTION", new ProtectionEnchantment(EnchantmentIds::PROTECTION, "%enchantment.protect.all", Rarity::COMMON, ItemFlags::ARMOR, ItemFlags::NONE, 4, 0.75, null));
|
||||
self::register("FIRE_PROTECTION", new ProtectionEnchantment(EnchantmentIds::FIRE_PROTECTION, "%enchantment.protect.fire", Rarity::UNCOMMON, ItemFlags::ARMOR, ItemFlags::NONE, 4, 1.25, [
|
||||
@@ -103,17 +96,7 @@ final class VanillaEnchantments{
|
||||
}
|
||||
|
||||
protected static function register(string $name, Enchantment $member) : void{
|
||||
if(array_key_exists($member->getId(), self::$mcpeIdMap)){
|
||||
throw new \InvalidArgumentException("MCPE enchantment ID " . $member->getId() . " is already assigned");
|
||||
}
|
||||
self::_registryRegister($name, $member);
|
||||
self::$mcpeIdMap[$member->getId()] = $member;
|
||||
}
|
||||
|
||||
public static function byMcpeId(int $id) : ?Enchantment{
|
||||
//TODO: this shouldn't be in here, it's unnecessarily limiting
|
||||
self::checkInit();
|
||||
return self::$mcpeIdMap[$id] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user