From 8947147c25e2640519897bfdc8807e97ee291d70 Mon Sep 17 00:00:00 2001 From: KingCol13 <48412633+KingCol13@users.noreply.github.com> Date: Fri, 2 Oct 2020 00:33:32 +0300 Subject: Enchanting table shows detail on hover. Enchanting is deterministic. (#4937) * Use lapis for enchanting, subtract correct number of levels, ClientHandle now selects from pregenerated list. Co-authored-by: Tiger Wang --- src/Entities/Player.cpp | 23 +++++++++++++++++++++++ src/Entities/Player.h | 8 ++++++++ 2 files changed, 31 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index bbe237d39..d7455f371 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -151,6 +151,8 @@ cPlayer::cPlayer(const cClientHandlePtr & a_Client, const AString & a_PlayerName SetWorld(World); // Use default world + m_EnchantmentSeed = GetRandomProvider().RandInt(); // Use a random number to seed the enchantment generator + FLOGD("Player \"{0}\" is connecting for the first time, spawning at default world spawn {1:.2f}", a_PlayerName, GetPosition() ); @@ -1861,6 +1863,25 @@ void cPlayer::SetVisible(bool a_bVisible) +MTRand cPlayer::GetEnchantmentRandomProvider() +{ + return m_EnchantmentSeed; +} + + + + + +void cPlayer::PermuteEnchantmentSeed() +{ + // Get a new random integer and save that as the seed: + m_EnchantmentSeed = GetRandomProvider().RandInt(); +} + + + + + bool cPlayer::HasPermission(const AString & a_Permission) { if (a_Permission.empty()) @@ -2277,6 +2298,7 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World) m_LifetimeTotalXp = root.get("xpTotal", 0).asInt(); m_CurrentXp = root.get("xpCurrent", 0).asInt(); m_IsFlying = root.get("isflying", 0).asBool(); + m_EnchantmentSeed = root.get("enchantmentSeed", GetRandomProvider().RandInt()).asUInt(); Json::Value & JSON_KnownItems = root["knownItems"]; for (UInt32 i = 0; i < JSON_KnownItems.size(); i++) @@ -2439,6 +2461,7 @@ bool cPlayer::SaveToDisk() root["SpawnY"] = GetLastBedPos().y; root["SpawnZ"] = GetLastBedPos().z; root["SpawnWorld"] = m_SpawnWorld->GetName(); + root["enchantmentSeed"] = m_EnchantmentSeed; if (m_World != nullptr) { diff --git a/src/Entities/Player.h b/src/Entities/Player.h index ba219a84d..568929f44 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -263,6 +263,13 @@ public: // tolua_end + /** Get a copy of the PRNG for enchanting related generation, don't use this for other purposes. + The PRNG's state is initialised with an internal seed, such that until PermuteEnchantmentSeed is called, this function returns the same PRNG. */ + MTRand GetEnchantmentRandomProvider(); + + /** Permute the seed for enchanting related PRNGs, don't use this for other purposes. */ + void PermuteEnchantmentSeed(); + /** Returns the SharedPtr to client handle associated with the player. */ cClientHandlePtr GetClientHandlePtr(void) const { return m_ClientHandle; } @@ -718,6 +725,7 @@ protected: /** Player Xp level */ int m_LifetimeTotalXp; int m_CurrentXp; + unsigned int m_EnchantmentSeed; // flag saying we need to send a xp update to client bool m_bDirtyExperience; -- cgit v1.2.3