![]() |
Enchanting - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html) +--- Forum: Development (https://forum.cuberite.org/forum-13.html) +--- Thread: Enchanting (/thread-1321.html) |
RE: Enchanting - xoft - 04-17-2014 STR, no, this is much more effective CPU-wise. Only I'm afraid the coords are wrong, each X and Z needs +2, because they are not relative to the area center, but to its XM-ZM corner. That's probably why it doesn't work, right, Daniel? Sorry for misleading you in the code comment, didn't think of that back then. RE: Enchanting - daniel0916 - 04-17-2014 Okay, i will try it. Thanks. Can you please explain, how this should work? Code: Store the weight together with the enchantments in cEnchantmentsVector (call it cWeightedEnchantments). RE: Enchanting - xoft - 04-17-2014 Like this: struct cWeightedEnchantment { int m_Weight; cEnchantments m_Enchantments; }; typedef std::vector<cWeightedEnchantment> cWeightedEnchantments; To use the weight, you sum up the individual m_Weight members, then generate a random number in range 0 - (sum - 1). Then you walk the vector again and subtract each m_Weight from the generated random number; as soon as it becomes negative, you use that item in the vector. RE: Enchanting - daniel0916 - 04-18-2014 Now it's compiling. https://github.com/mc-server/MCServer/pull/890 RE: Enchanting - daniel0916 - 04-19-2014 How can i do this without string operations? So how can i get the enchantment (without EnchantmentLevel) from cEnchantments. Old Code: int EnchantmentID = atoi(StringSplit((*it).m_Enchantments.ToString(), "=")[0].c_str()); RE: Enchanting - xoft - 04-19-2014 There's this nifty little function in cEnchantments: /// Returns the level for the specified enchantment; 0 if not stored int GetLevel(int a_EnchantmentID) const; RE: Enchanting - daniel0916 - 04-19-2014 This code don't do this what i want. I need the enchantment ID from a cEnchantments. Example: cEnchantments("Sharpness=4"). My old code get the id from sharpness. The method from you get the enchantment level. So this method will return 4. RE: Enchanting - xoft - 04-19-2014 Yes, but your code only uses the ID to check if the enchantment is there. Which is exactly what you get with this function: if (it->GetLevel(a_EnchantmentID) > 0) { // This weighted enchantment contains the enchantment we don't want, erase it: a_Enchantments->erase(it); // Do not break, there may be more incompatible enchantments }The code also shouldn't break from the for-loop, since there may be multiple weighted enchantments that need removing. But then you need to care about iterator validity after calling the erase() function. RE: Enchanting - daniel0916 - 04-19-2014 Thanks, i will push the code now. RE: Enchanting - daniel0916 - 04-25-2014 I added some enchantment handlings. https://github.com/daniel0916/MCServer/commits/Enchanting Does anyone know where the arrow will be removed from the inventory? I need this for the Infinity enchantment |