From 5e0a19550dc77293da54f960578301b808851823 Mon Sep 17 00:00:00 2001 From: darkrose Date: Tue, 13 Oct 2015 19:49:23 +1000 Subject: [PATCH] add support for extra_dug_item to restricted to certain tool levels --- src/content_mapnode.cpp | 5 ++++- src/content_toolitem.cpp | 13 +++++++++++++ src/content_toolitem.h | 2 +- src/mapnode.h | 6 ++++++ src/server.cpp | 8 +++++++- 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index 792a7de..6a05fd5 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -466,7 +466,8 @@ void content_mapnode_init(bool repeat) f->is_ground_content = true; f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->extra_dug_item = std::string("MaterialItem2 ")+itos(CONTENT_ROCK)+" 1"; - f->extra_dug_item_rarity = 5; + f->extra_dug_item_rarity = 3; + f->extra_dug_item_max_level = 1; f->type = CMT_DIRT; f->hardness = 1.0; f->farm_ploughable = true; @@ -498,6 +499,7 @@ void content_mapnode_init(bool repeat) f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->extra_dug_item = std::string("CraftItem2 ")+itos(CONTENT_CRAFTITEM_SALTPETER)+" 1"; f->extra_dug_item_rarity = 30; + f->extra_dug_item_min_level = 3; f->cook_result = std::string("MaterialItem2 ")+itos(CONTENT_GLASS)+" 1"; f->type = CMT_DIRT; f->hardness = 1.0; @@ -516,6 +518,7 @@ void content_mapnode_init(bool repeat) f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1"; f->extra_dug_item = std::string("CraftItem lump_of_flint 1"); f->extra_dug_item_rarity = 10; + f->extra_dug_item_min_level = 1; f->type = CMT_DIRT; f->hardness = 1.75; lists::add("creative",i); diff --git a/src/content_toolitem.cpp b/src/content_toolitem.cpp index 8a36acd..a1070cd 100644 --- a/src/content_toolitem.cpp +++ b/src/content_toolitem.cpp @@ -291,6 +291,7 @@ void content_toolitem_init() f->name = "WShovel"; f->description = wgettext("Stone Trowel"); f->type = TT_SHOVEL; + f->level = 1; f->hardness = 50.; f->dig_time = 0.4; crafting::set1over1Recipe(CONTENT_ROCK,CONTENT_CRAFTITEM_STICK,i); @@ -304,6 +305,7 @@ void content_toolitem_init() f->name = "STShovel"; f->description = wgettext("Stone Shovel"); f->type = TT_SHOVEL; + f->level = 1; f->hardness = 150.; f->dig_time = 0.2; crafting::setShovelRecipe(CONTENT_ROUGHSTONE,CONTENT_TOOLITEM_STSHOVEL); @@ -345,6 +347,7 @@ void content_toolitem_init() f->name = "WAxe"; f->description = wgettext("Small Stone Axe"); f->type = TT_AXE; + f->level = 1; f->hardness = 30.; f->dig_time = 1.5; { @@ -365,6 +368,7 @@ void content_toolitem_init() f->name = "STAxe"; f->description = wgettext("Stone Axe"); f->type = TT_AXE; + f->level = 1; f->hardness = 100.; f->dig_time = 0.75; crafting::setAxeRecipe(CONTENT_ROUGHSTONE,CONTENT_TOOLITEM_STAXE); @@ -408,6 +412,7 @@ void content_toolitem_init() f->type = TT_CLUB; f->hardness = 120.; f->dig_time = 1.5; + f->level = 1; crafting::setCol1Recipe(CONTENT_CRAFTITEM_WOOD_PLANK,i); crafting::setCol1Recipe(CONTENT_CRAFTITEM_JUNGLE_PLANK,i); lists::add("craftguide",i); @@ -422,6 +427,7 @@ void content_toolitem_init() f->type = TT_SWORD; f->hardness = 300.; f->dig_time = 1.0; + f->level = 1; crafting::setSwordRecipe(CONTENT_ROUGHSTONE,CONTENT_TOOLITEM_STSWORD); lists::add("craftguide",i); lists::add("creative",i); @@ -478,6 +484,7 @@ void content_toolitem_init() f->type = TT_BUCKET; f->hardness = 30.; f->dig_time = 0.0; + f->level = 1; f->damaging_nodes_diggable = false; crafting::setURecipe(CONTENT_CRAFTITEM_JUNGLE_PLANK,CONTENT_TOOLITEM_WBUCKET); crafting::setURecipe(CONTENT_CRAFTITEM_WOOD_PLANK,CONTENT_TOOLITEM_WBUCKET); @@ -568,6 +575,7 @@ void content_toolitem_init() f->description = wgettext("Fire Starter"); f->liquids_pointable = true; f->type = TT_SPECIAL; + f->level = 3; f->has_fire_effect = true; crafting::set1Any2Recipe(CONTENT_CRAFTITEM_FLINT,CONTENT_CRAFTITEM_STEEL_INGOT,CONTENT_TOOLITEM_FIRESTARTER); lists::add("craftguide",i); @@ -580,6 +588,7 @@ void content_toolitem_init() f->name = "crowbar"; f->description = wgettext("Crowbar"); f->type = TT_SPECIAL; + f->level = 3; f->has_rotate_effect = true; crafting::set1over1Recipe(CONTENT_CRAFTITEM_STEEL_INGOT,CONTENT_CRAFTITEM_STEEL_INGOT,CONTENT_TOOLITEM_CROWBAR); lists::add("craftguide",i); @@ -592,6 +601,7 @@ void content_toolitem_init() f->name = "key"; f->description = wgettext("Key"); f->type = TT_SPECIAL; + f->level = 4; f->has_unlock_effect = true; crafting::set1To1Recipe(CONTENT_CRAFTITEM_GOLD_INGOT,CONTENT_TOOLITEM_KEY); lists::add("craftguide",i); @@ -603,6 +613,7 @@ void content_toolitem_init() f->name = "stone_spear"; f->description = wgettext("Stone Spear"); f->type = TT_SPEAR; + f->level = 1; f->hardness = 100.; f->dig_time = 1.5; crafting::setSpearRecipe(CONTENT_ROUGHSTONE,CONTENT_TOOLITEM_STONESPEAR); @@ -644,6 +655,7 @@ void content_toolitem_init() f->name = "bow"; f->description = wgettext("Bow"); f->type = TT_SPECIAL; + f->level = 2; f->thrown_item = CONTENT_CRAFTITEM_ARROW; { content_t r[9] = { @@ -874,6 +886,7 @@ void content_toolitem_init() f->name = "mob_spawner"; f->description = wgettext("Mob Spawner"); f->type = TT_SPECIAL; + f->level = 4; f->param_type = CPT_DROP; { content_t r[9] = { diff --git a/src/content_toolitem.h b/src/content_toolitem.h index b2538ea..739f75c 100644 --- a/src/content_toolitem.h +++ b/src/content_toolitem.h @@ -80,7 +80,7 @@ struct ToolItemFeatures { type(TT_NONE), hardness(0.), dig_time(3.), - level(1), + level(0), param_type(CPT_NONE), thrown_item(CONTENT_IGNORE), onplace_replace_item(CONTENT_IGNORE), diff --git a/src/mapnode.h b/src/mapnode.h index 221986d..40d03a3 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -375,6 +375,10 @@ struct ContentFeatures // Extra dug item and its rarity std::string extra_dug_item; s32 extra_dug_item_rarity; + // the minimum tool level required to get the extra dug item + u8 extra_dug_item_min_level; + // the maximum tool level required to get the extra dug item + u8 extra_dug_item_max_level; // when dug, this node will replace the dug node content_t ondig_replace_node; @@ -540,6 +544,8 @@ struct ContentFeatures dug_item = ""; extra_dug_item = ""; extra_dug_item_rarity = 2; + extra_dug_item_min_level = 0; + extra_dug_item_max_level = 100; ondig_replace_node = CONTENT_IGNORE; ondig_replace_node_requires = CONTENT_IGNORE; ondig_special_drop = CONTENT_IGNORE; diff --git a/src/server.cpp b/src/server.cpp index df05388..6679901 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3503,7 +3503,13 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if (item == NULL) { std::string &extra_dug_s = selected_node_features.extra_dug_item; s32 extra_rarity = selected_node_features.extra_dug_item_rarity; - if (extra_dug_s != "" && extra_rarity != 0 && myrand() % extra_rarity == 0) { + if ( + extra_dug_s != "" + && extra_rarity != 0 + && selected_node_features.extra_dug_item_min_level <= wielded_tool_features.level + && selected_node_features.extra_dug_item_max_level >= wielded_tool_features.level + && myrand_range(0,extra_rarity) == 0 + ) { std::istringstream is(extra_dug_s, std::ios::binary); item = InventoryItem::deSerialize(is); }