mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
Move enchanting seed generation to EnchantmentHelper
This commit is contained in:
parent
29fdc8b08d
commit
d942748203
@ -37,6 +37,7 @@ use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\inventory\PlayerEnderInventory;
|
||||
use pocketmine\inventory\PlayerInventory;
|
||||
use pocketmine\inventory\PlayerOffHandInventory;
|
||||
use pocketmine\item\enchantment\EnchantmentHelper;
|
||||
use pocketmine\item\enchantment\VanillaEnchantments;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\Totem;
|
||||
@ -66,7 +67,6 @@ use pocketmine\network\mcpe\protocol\types\PlayerListEntry;
|
||||
use pocketmine\network\mcpe\protocol\types\PlayerPermissions;
|
||||
use pocketmine\network\mcpe\protocol\UpdateAbilitiesPacket;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\utils\Limits;
|
||||
use pocketmine\world\sound\TotemUseSound;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\UuidInterface;
|
||||
@ -76,7 +76,6 @@ use function array_key_exists;
|
||||
use function array_merge;
|
||||
use function array_values;
|
||||
use function min;
|
||||
use function mt_rand;
|
||||
|
||||
class Human extends Living implements ProjectileSource, InventoryHolder{
|
||||
|
||||
@ -219,8 +218,8 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
||||
$this->xpSeed = $seed;
|
||||
}
|
||||
|
||||
public function generateEnchantmentSeed() : int{
|
||||
return mt_rand(Limits::INT32_MIN, Limits::INT32_MAX);
|
||||
public function regenerateEnchantmentSeed() : void{
|
||||
$this->xpSeed = EnchantmentHelper::generateSeed();
|
||||
}
|
||||
|
||||
public function getXpDropAmount() : int{
|
||||
@ -346,7 +345,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
|
||||
if(($xpSeedTag = $nbt->getTag(self::TAG_XP_SEED)) instanceof IntTag){
|
||||
$this->xpSeed = $xpSeedTag->getValue();
|
||||
}else{
|
||||
$this->xpSeed = $this->generateEnchantmentSeed();
|
||||
$this->xpSeed = EnchantmentHelper::generateSeed();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ class EnchantTransaction extends InventoryTransaction{
|
||||
//In this case, as much XP as possible will be taken.
|
||||
$this->source->getXpManager()->subtractXpLevels(min($this->cost, $this->source->getXpManager()->getXpLevel()));
|
||||
}
|
||||
$this->source->setEnchantmentSeed($this->source->generateEnchantmentSeed());
|
||||
$this->source->regenerateEnchantmentSeed();
|
||||
}
|
||||
|
||||
protected function callExecuteEvent() : bool{
|
||||
|
@ -28,6 +28,7 @@ use pocketmine\item\enchantment\AvailableEnchantmentRegistry as EnchantmentRegis
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemTypeIds;
|
||||
use pocketmine\item\VanillaItems as Items;
|
||||
use pocketmine\utils\Limits;
|
||||
use pocketmine\utils\Random;
|
||||
use pocketmine\world\Position;
|
||||
use function abs;
|
||||
@ -37,6 +38,7 @@ use function count;
|
||||
use function floor;
|
||||
use function max;
|
||||
use function min;
|
||||
use function mt_rand;
|
||||
use function ord;
|
||||
use function round;
|
||||
|
||||
@ -47,6 +49,13 @@ final class EnchantmentHelper{
|
||||
//NOOP
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new random seed for enchant option randomization.
|
||||
*/
|
||||
public static function generateSeed() : int{
|
||||
return mt_rand(Limits::INT32_MIN, Limits::INT32_MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param EnchantmentInstance[] $enchantments
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user