Enchanting
#91
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.
Reply
Thanks given by:
#92
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).
How can i then use the weight?
Reply
Thanks given by:
#93
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.
Reply
Thanks given by:
#94
Now it's compiling.
https://github.com/mc-server/MCServer/pull/890
Reply
Thanks given by:
#95
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());
Reply
Thanks given by:
#96
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;
Reply
Thanks given by:
#97
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.
Reply
Thanks given by:
#98
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.
Reply
Thanks given by:
#99
Thanks, i will push the code now.
Reply
Thanks given by:
I added some enchantment handlings. https://github.com/daniel0916/MCServer/c...Enchanting
Does anyone know where the arrow will be removed from the inventory? I need this for the Infinity enchantment
Reply
Thanks given by:




Users browsing this thread: 6 Guest(s)