summaryrefslogtreecommitdiffstats
path: root/src/ItemGrid.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-10-15 19:23:53 +0200
committerMattes D <github@xoft.cz>2014-10-15 19:23:53 +0200
commit06b466471fa59b2496af702c4d1cf1fd53df8063 (patch)
treeea46d2d2402dc9d116a94753ac5238a3e87f83d0 /src/ItemGrid.cpp
parentFunctions in cPluginManager get references instead of pointers. (diff)
parentUsing C++11 loops (diff)
downloadcuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar.gz
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar.bz2
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar.lz
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar.xz
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.tar.zst
cuberite-06b466471fa59b2496af702c4d1cf1fd53df8063.zip
Diffstat (limited to 'src/ItemGrid.cpp')
-rw-r--r--src/ItemGrid.cpp16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/ItemGrid.cpp b/src/ItemGrid.cpp
index 2344dc0a5..6a3d08679 100644
--- a/src/ItemGrid.cpp
+++ b/src/ItemGrid.cpp
@@ -637,7 +637,21 @@ void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, s
int Rnd = (Noise.IntNoise1DInt(i) / 7);
int LootRnd = Rnd % TotalProbab;
Rnd >>= 8;
- cItem CurrentLoot = cItem(E_ITEM_BOOK, 1, 0); // TODO: enchantment
+ cItem CurrentLoot = cItem(E_ITEM_ENCHANTED_BOOK, 1, 0);
+
+ // Choose the enchantments
+ cWeightedEnchantments Enchantments;
+ cEnchantments::AddItemEnchantmentWeights(Enchantments, E_ITEM_BOOK, 24 + Noise.IntNoise2DInt(a_Seed, TotalProbab) % 7);
+ int NumEnchantments = Noise.IntNoise3DInt(TotalProbab, Rnd, a_Seed) % 5; // The number of enchantments this book wil get.
+
+ for (int j = 0; j <= NumEnchantments; j++)
+ {
+ cEnchantments Enchantment = cEnchantments::GenerateEnchantmentFromVector(Enchantments, Noise.IntNoise2DInt(NumEnchantments, i));
+ CurrentLoot.m_Enchantments.Add(Enchantment);
+ cEnchantments::RemoveEnchantmentWeightFromVector(Enchantments, Enchantment);
+ cEnchantments::CheckEnchantmentConflictsFromVector(Enchantments, Enchantment);
+ }
+
for (size_t j = 0; j < a_CountLootProbabs; j++)
{
LootRnd -= a_LootProbabs[i].m_Weight;