mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 08:49:42 +00:00
Make EnchantmentInstance immutable, remove enchantment clone from Item
it doesn't make sense to set the level of an existing enchantment instance because under the old API it would have no effect anyway (if it was returned from an itemstack) or you had access to the constructor (if applying a new enchantment). Allowing this to be mutable creates needless complexity and performance headaches.
This commit is contained in:
parent
fec8c75fd8
commit
af73c5f2b1
@ -45,7 +45,6 @@ use pocketmine\nbt\tag\StringTag;
|
|||||||
use pocketmine\nbt\TreeRoot;
|
use pocketmine\nbt\TreeRoot;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\utils\Binary;
|
use pocketmine\utils\Binary;
|
||||||
use function array_map;
|
|
||||||
use function base64_decode;
|
use function base64_decode;
|
||||||
use function base64_encode;
|
use function base64_encode;
|
||||||
use function get_class;
|
use function get_class;
|
||||||
@ -848,6 +847,5 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
}
|
}
|
||||||
$this->canPlaceOn = $this->canPlaceOn->copy();
|
$this->canPlaceOn = $this->canPlaceOn->copy();
|
||||||
$this->canDestroy = $this->canDestroy->copy();
|
$this->canDestroy = $this->canDestroy->copy();
|
||||||
$this->enchantments = array_map(function(EnchantmentInstance $i){ return clone $i; }, $this->enchantments);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,10 @@ namespace pocketmine\item\enchantment;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Container for enchantment data applied to items.
|
* Container for enchantment data applied to items.
|
||||||
|
*
|
||||||
|
* Note: This class is assumed to be immutable. Consider this before making alterations.
|
||||||
*/
|
*/
|
||||||
class EnchantmentInstance{
|
final class EnchantmentInstance{
|
||||||
/** @var Enchantment */
|
/** @var Enchantment */
|
||||||
private $enchantment;
|
private $enchantment;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
@ -66,17 +68,4 @@ class EnchantmentInstance{
|
|||||||
public function getLevel() : int{
|
public function getLevel() : int{
|
||||||
return $this->level;
|
return $this->level;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the level of the enchantment.
|
|
||||||
*
|
|
||||||
* @param int $level
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setLevel(int $level){
|
|
||||||
$this->level = $level;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user