From 71b96ab921bed0371d7c75ac4a2db99b94591de2 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 22 Sep 2020 11:08:12 +0100 Subject: Limit fortune level, style fixes --- src/Blocks/BlockHandler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Blocks/BlockHandler.cpp') diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 4272bc607..274460e50 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -649,16 +649,16 @@ bool cBlockHandler::ToolHasSilkTouch(const cItem * a_Tool) -unsigned int cBlockHandler::ToolFortuneLevel(const cItem * a_Tool) +unsigned char cBlockHandler::ToolFortuneLevel(const cItem * a_Tool) { - if (a_Tool != nullptr) + if ((a_Tool != nullptr) && ItemCategory::IsTool(a_Tool->m_ItemType)) { - return a_Tool->m_Enchantments.GetLevel(cEnchantments::enchFortune); - } - else // Not a tool - { - return 0; + // Return enchantment level, limited to avoid spawning excessive pickups (crashing the server) when modified items are used: + return std::min(8U, a_Tool->m_Enchantments.GetLevel(cEnchantments::enchFortune)); } + + // Not a tool: + return 0; } -- cgit v1.2.3