summaryrefslogtreecommitdiffstats
path: root/src/Enchantments.cpp
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-11-18 14:56:32 +0100
committerHowaner <franzi.moos@googlemail.com>2014-11-18 14:56:32 +0100
commit42120e2ea5db0cdb9920ff1c5efef33e0f496d48 (patch)
tree20ba1ae0a53f757cb8814b6cd6a466fe5acf1308 /src/Enchantments.cpp
parentFixed compile errors. (diff)
parentMerge pull request #1598 from mc-server/SignEditor (diff)
downloadcuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.gz
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.bz2
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.lz
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.xz
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.tar.zst
cuberite-42120e2ea5db0cdb9920ff1c5efef33e0f496d48.zip
Diffstat (limited to '')
-rw-r--r--src/Enchantments.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/Enchantments.cpp b/src/Enchantments.cpp
index 264878c22..80a9810b6 100644
--- a/src/Enchantments.cpp
+++ b/src/Enchantments.cpp
@@ -6,6 +6,7 @@
#include "Enchantments.h"
#include "WorldStorage/FastNBT.h"
#include "FastRandom.h"
+#include "Noise.h"
@@ -1019,3 +1020,30 @@ cEnchantments cEnchantments::GetRandomEnchantmentFromVector(cWeightedEnchantment
+
+cEnchantments cEnchantments::GenerateEnchantmentFromVector(cWeightedEnchantments & a_Enchantments, int a_Seed)
+{
+ int AllWeights = 0;
+ for (const auto Enchantment : a_Enchantments)
+ {
+ AllWeights += Enchantment.m_Weight;
+ }
+
+ cNoise Noise(a_Seed);
+ int RandomNumber = Noise.IntNoise1DInt(AllWeights) / 7 % AllWeights;
+
+ for (const auto Enchantment : a_Enchantments)
+ {
+ RandomNumber -= Enchantment.m_Weight;
+ if (RandomNumber < 0)
+ {
+ return Enchantment.m_Enchantments;
+ }
+ }
+
+ return cEnchantments();
+}
+
+
+
+