diff options
| author | void_17 <61356189+void2012@users.noreply.github.com> | 2026-03-06 02:11:18 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-06 02:11:18 +0700 |
| commit | 55231bb8d3e1a4e2752ac3d444c4287eb0ca4e8b (patch) | |
| tree | 953c537a5c66e328e9f4ab29626cf738112d53c0 /Minecraft.World/AnvilMenu.cpp | |
| parent | 7d6658fe5b3095f35093701b5ab669ffc291e875 (diff) | |
Remove AUTO_VAR macro and _toString function (#592)
Diffstat (limited to 'Minecraft.World/AnvilMenu.cpp')
| -rw-r--r-- | Minecraft.World/AnvilMenu.cpp | 103 |
1 files changed, 53 insertions, 50 deletions
diff --git a/Minecraft.World/AnvilMenu.cpp b/Minecraft.World/AnvilMenu.cpp index 2ef00e3e..83d38142 100644 --- a/Minecraft.World/AnvilMenu.cpp +++ b/Minecraft.World/AnvilMenu.cpp @@ -134,64 +134,67 @@ void AnvilMenu::createResult() unordered_map<int, int> *additionalEnchantments = EnchantmentHelper::getEnchantments(addition); - for(AUTO_VAR(it, additionalEnchantments->begin()); it != additionalEnchantments->end(); ++it) + if ( additionalEnchantments ) { - int id = it->first; - Enchantment *enchantment = Enchantment::enchantments[id]; - AUTO_VAR(localIt, enchantments->find(id)); - int current = localIt != enchantments->end() ? localIt->second : 0; - int level = it->second; - level = (current == level) ? level += 1 : max(level, current); - int extra = level - current; - bool compatible = enchantment->canEnchant(input); - - if (player->abilities.instabuild || input->id == EnchantedBookItem::enchantedBook_Id) compatible = true; - - for(AUTO_VAR(it2, enchantments->begin()); it2 != enchantments->end(); ++it2) + for (const auto& it : *additionalEnchantments) { - int other = it2->first; - if (other != id && !enchantment->isCompatibleWith(Enchantment::enchantments[other])) + int id = it.first; + Enchantment* enchantment = Enchantment::enchantments[id]; + auto localIt = enchantments->find(id); + int current = localIt != enchantments->end() ? localIt->second : 0; + int level = it.second; + level = (current == level) ? level += 1 : std::max<int>(level, current); + int extra = level - current; + bool compatible = enchantment->canEnchant(input); + + if (player->abilities.instabuild || input->id == EnchantedBookItem::enchantedBook_Id) compatible = true; + + for (auto& it2 : *enchantments) { - compatible = false; - - price += extra; - if (DEBUG_COST) + int other = it2.first; + if (other != id && !enchantment->isCompatibleWith(Enchantment::enchantments[other])) { - app.DebugPrintf("Enchantment incompatibility fee; price is now %d (went up by %d)\n", price, extra); + compatible = false; + + price += extra; + if (DEBUG_COST) + { + app.DebugPrintf("Enchantment incompatibility fee; price is now %d (went up by %d)\n", price, extra); + } } } - } - if (!compatible) continue; - if (level > enchantment->getMaxLevel()) level = enchantment->getMaxLevel(); - (*enchantments)[id] = level; - int fee = 0; + if (!compatible) continue; + if (level > enchantment->getMaxLevel()) level = enchantment->getMaxLevel(); + (*enchantments)[id] = level; + int fee = 0; - switch (enchantment->getFrequency()) - { - case Enchantment::FREQ_COMMON: - fee = 1; - break; - case Enchantment::FREQ_UNCOMMON: - fee = 2; - break; - case Enchantment::FREQ_RARE: - fee = 4; - break; - case Enchantment::FREQ_VERY_RARE: - fee = 8; - break; - } + switch (enchantment->getFrequency()) + { + case Enchantment::FREQ_COMMON: + fee = 1; + break; + case Enchantment::FREQ_UNCOMMON: + fee = 2; + break; + case Enchantment::FREQ_RARE: + fee = 4; + break; + case Enchantment::FREQ_VERY_RARE: + fee = 8; + break; + } - if (usingBook) fee = max(1, fee / 2); + if (usingBook) fee = max(1, fee / 2); - price += fee * extra; - if (DEBUG_COST) - { - app.DebugPrintf("Enchantment increase fee; price is now %d (went up by %d)\n", price, fee*extra); + price += fee * extra; + if (DEBUG_COST) + { + app.DebugPrintf("Enchantment increase fee; price is now %d (went up by %d)\n", price, fee * extra); + } } + delete additionalEnchantments; } - delete additionalEnchantments; } } @@ -233,11 +236,11 @@ void AnvilMenu::createResult() } int count = 0; - for(AUTO_VAR(it, enchantments->begin()); it != enchantments->end(); ++it) + for( const auto& it : *enchantments ) { - int id = it->first; + int id = it.first; Enchantment *enchantment = Enchantment::enchantments[id]; - int level = it->second; + int level = it.second; int fee = 0; count++; @@ -258,7 +261,7 @@ void AnvilMenu::createResult() break; } - if (usingBook) fee = max(1, fee / 2); + if (usingBook) fee = std::max<int>(1, fee / 2); tax += count + level * fee; if (DEBUG_COST) |
