From c501ff6e1d3094d0ef429114da8546469da397d9 Mon Sep 17 00:00:00 2001 From: Araca Date: Wed, 21 Feb 2024 15:08:35 +0100 Subject: [PATCH] Add remaining use of a tool/weapon in tooltips --- mods/CORE/mcl_util/init.lua | 1 + mods/ENTITIES/mcl_item_entity/init.lua | 1 + mods/ENTITIES/mcl_mobs/combat.lua | 1 + mods/ENTITIES/mobs_mc/cow+mooshroom.lua | 1 + mods/ENTITIES/mobs_mc/sheep.lua | 1 + mods/ENTITIES/mobs_mc/snowman.lua | 1 + mods/HELP/mcl_tt/snippets_base.lua | 9 +++- mods/ITEMS/REDSTONE/mcl_dispensers/init.lua | 1 + mods/ITEMS/mcl_bows/bow.lua | 1 + mods/ITEMS/mcl_bows/crossbow.lua | 1 + mods/ITEMS/mcl_campfires/api.lua | 1 + mods/ITEMS/mcl_farming/hoes.lua | 49 +++++++++++---------- mods/ITEMS/mcl_fishing/init.lua | 2 + mods/ITEMS/mcl_tools/init.lua | 4 ++ 14 files changed, 48 insertions(+), 26 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 477d05b4e..90bf07ce2 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -534,6 +534,7 @@ end function mcl_util.use_item_durability(itemstack, n) local uses = mcl_util.calculate_durability(itemstack) itemstack:add_wear(65535 / uses * n) + tt.reload_itemstack_description(itemstack) -- update tooltip end function mcl_util.deal_damage(target, damage, mcl_reason) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 1734fa6af..19e91b460 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -448,6 +448,7 @@ function minetest.node_dig(pos, node, digger) end end end + tt.reload_itemstack_description(wielded) -- update tooltip digger:set_wielded_item(wielded) end diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index 745a06c5c..f39760fab 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -646,6 +646,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir) if def.tool_capabilities and def.tool_capabilities.punch_attack_uses then local wear = math.floor(65535/tool_capabilities.punch_attack_uses) weapon:add_wear(wear) + tt.reload_itemstack_description(weapon) -- update tooltip hitter:set_wielded_item(weapon) end end, hitter:get_player_name()) diff --git a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua index 4ee21b2ea..4722c157c 100644 --- a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua +++ b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua @@ -122,6 +122,7 @@ mooshroom_def.on_rightclick = function(self, clicker) if not minetest.is_creative_enabled(clicker:get_player_name()) then item:add_wear(mobs_mc.shears_wear) + tt.reload_itemstack_description(item) -- update tooltip clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item) end -- Use bucket to milk diff --git a/mods/ENTITIES/mobs_mc/sheep.lua b/mods/ENTITIES/mobs_mc/sheep.lua index 6ef8016e6..e0df5323c 100644 --- a/mods/ENTITIES/mobs_mc/sheep.lua +++ b/mods/ENTITIES/mobs_mc/sheep.lua @@ -249,6 +249,7 @@ mcl_mobs.register_mob("mobs_mc:sheep", { }) if not minetest.is_creative_enabled(clicker:get_player_name()) then item:add_wear(mobs_mc.shears_wear) + tt.reload_itemstack_description(item) -- update tooltip clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item) end return diff --git a/mods/ENTITIES/mobs_mc/snowman.lua b/mods/ENTITIES/mobs_mc/snowman.lua index 62b988b9a..595c7d63e 100644 --- a/mods/ENTITIES/mobs_mc/snowman.lua +++ b/mods/ENTITIES/mobs_mc/snowman.lua @@ -131,6 +131,7 @@ mcl_mobs.register_mob("mobs_mc:snowman", { -- Wear out if not minetest.is_creative_enabled(clicker:get_player_name()) then item:add_wear(mobs_mc.shears_wear) + tt.reload_itemstack_description(item) -- update tooltip clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item) end end diff --git a/mods/HELP/mcl_tt/snippets_base.lua b/mods/HELP/mcl_tt/snippets_base.lua index 4e200d539..7047d8939 100644 --- a/mods/HELP/mcl_tt/snippets_base.lua +++ b/mods/HELP/mcl_tt/snippets_base.lua @@ -35,7 +35,7 @@ local function newline(str) end -- Digging capabilities of tool -tt.register_snippet(function(itemstring, toolcaps) +tt.register_snippet(function(itemstring, toolcaps, itemstack) local def = minetest.registered_items[itemstring] if not toolcaps then return @@ -85,7 +85,12 @@ tt.register_snippet(function(itemstring, toolcaps) if def._doc_items_durability == nil and base_uses > 0 then local real_uses = base_uses * math.pow(3, maxlevel) if real_uses < 65535 then - miningusesstr = S("@1 uses", real_uses) + if itemstack then + local remaining_uses = math.round(real_uses - (itemstack:get_wear() * base_uses) / 65535) + miningusesstr = remaining_uses .. "/" .. real_uses + else + miningusesstr = S("@1 uses", real_uses) + end else miningusesstr = S("Unlimited uses") end diff --git a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua index ae419a512..9e5224b15 100644 --- a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua @@ -227,6 +227,7 @@ local dispenserdef = { entity.gotten = true minetest.sound_play("mcl_tools_shears_cut", { pos = pos }, true) stack:add_wear(65535 / stackdef._mcl_diggroups.shearsy.uses) + tt.reload_itemstack_description(stack) -- update tooltip inv:set_stack("main", stack_id, stack) break end diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 37c38a085..3d22c6df6 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -300,6 +300,7 @@ controls.register_on_release(function(player, key, time) durability = durability * (unbreaking + 1) end wielditem:add_wear(65535/durability) + tt.reload_itemstack_description(wielditem) -- update tooltip end player:set_wielded_item(wielditem) reset_bow_state(player, true) diff --git a/mods/ITEMS/mcl_bows/crossbow.lua b/mods/ITEMS/mcl_bows/crossbow.lua index b6a1a3ad6..54c6d7da2 100644 --- a/mods/ITEMS/mcl_bows/crossbow.lua +++ b/mods/ITEMS/mcl_bows/crossbow.lua @@ -350,6 +350,7 @@ controls.register_on_press(function(player, key, time) durability = durability / 3 end wielditem:add_wear(65535/durability) + tt.reload_itemstack_description(wielditem) -- update tooltip end player:set_wielded_item(wielditem) reset_bow_state(player, true) diff --git a/mods/ITEMS/mcl_campfires/api.lua b/mods/ITEMS/mcl_campfires/api.lua index 4c1ddc758..7fa495edb 100644 --- a/mods/ITEMS/mcl_campfires/api.lua +++ b/mods/ITEMS/mcl_campfires/api.lua @@ -323,6 +323,7 @@ function mcl_campfires.register_campfire(name, def) local wear = mcl_autogroup.get_wear(toolname, "shovely") if wear then itemstack:add_wear(wear) + tt.reload_itemstack_description(itemstack) -- update tooltip end end node.name = name diff --git a/mods/ITEMS/mcl_farming/hoes.lua b/mods/ITEMS/mcl_farming/hoes.lua index 72d8f7b7a..0a389522e 100644 --- a/mods/ITEMS/mcl_farming/hoes.lua +++ b/mods/ITEMS/mcl_farming/hoes.lua @@ -43,6 +43,7 @@ local hoe_on_place_function = function(wear_divisor) if create_soil(pointed_thing.under, user:get_inventory()) then if not minetest.is_creative_enabled(user:get_player_name()) then itemstack:add_wear(65535/wear_divisor) + tt.reload_itemstack_description(itemstack) -- update tooltip end return itemstack end @@ -54,7 +55,7 @@ local uses = { stone = 132, iron = 251, gold = 33, - diamond = 1562, + diamond = 1562, netherite = 2031, } @@ -274,26 +275,26 @@ minetest.register_craft({ {"mcl_core:diamond", "mcl_core:diamond"}, {"mcl_core:stick", ""}, {"mcl_core:stick", ""} - } -}) - -minetest.register_tool("mcl_farming:hoe_netherite", { - description = S("Netherite Hoe"), - _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.netherite), - _doc_items_longdesc = hoe_longdesc, - _doc_items_usagehelp = hoe_usagehelp, - inventory_image = "farming_tool_netheritehoe.png", - wield_scale = mcl_vars.tool_wield_scale, - on_place = hoe_on_place_function(uses.netherite), - groups = { tool=1, hoe=1, enchantability=10, fire_immune=1 }, - tool_capabilities = { - full_punch_interval = 0.25, - damage_groups = { fleshy = 4, }, - punch_attack_uses = uses.netherite, - }, - _repair_material = "mcl_nether:netherite_ingot", - _mcl_toollike_wield = true, - _mcl_diggroups = { - hoey = { speed = 8, level = 5, uses = uses.netherite } - }, -}) + } +}) + +minetest.register_tool("mcl_farming:hoe_netherite", { + description = S("Netherite Hoe"), + _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.netherite), + _doc_items_longdesc = hoe_longdesc, + _doc_items_usagehelp = hoe_usagehelp, + inventory_image = "farming_tool_netheritehoe.png", + wield_scale = mcl_vars.tool_wield_scale, + on_place = hoe_on_place_function(uses.netherite), + groups = { tool=1, hoe=1, enchantability=10, fire_immune=1 }, + tool_capabilities = { + full_punch_interval = 0.25, + damage_groups = { fleshy = 4, }, + punch_attack_uses = uses.netherite, + }, + _repair_material = "mcl_nether:netherite_ingot", + _mcl_toollike_wield = true, + _mcl_diggroups = { + hoey = { speed = 8, level = 5, uses = uses.netherite } + }, +}) diff --git a/mods/ITEMS/mcl_fishing/init.lua b/mods/ITEMS/mcl_fishing/init.lua index 4638325bd..15c16fc79 100644 --- a/mods/ITEMS/mcl_fishing/init.lua +++ b/mods/ITEMS/mcl_fishing/init.lua @@ -140,6 +140,7 @@ local fish = function(itemstack, player, pointed_thing) if not minetest.is_creative_enabled(player:get_player_name()) then local idef = itemstack:get_definition() itemstack:add_wear(65535/durability) -- 65 uses + tt.reload_itemstack_description(itemstack) -- update tooltip if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then minetest.sound_play(idef.sound.breaks, {pos=player:get_pos(), gain=0.5}, true) end @@ -154,6 +155,7 @@ local fish = function(itemstack, player, pointed_thing) if not minetest.is_creative_enabled(player:get_player_name()) then local idef = itemstack:get_definition() itemstack:add_wear((65535/durability)*2) -- if so and not creative then wear double like in MC. + tt.reload_itemstack_description(itemstack) -- update tooltip if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then minetest.sound_play(idef.sound.breaks, {pos=player:get_pos(), gain=0.5}, true) end diff --git a/mods/ITEMS/mcl_tools/init.lua b/mods/ITEMS/mcl_tools/init.lua index 6282da5c3..266adc6fc 100644 --- a/mods/ITEMS/mcl_tools/init.lua +++ b/mods/ITEMS/mcl_tools/init.lua @@ -186,6 +186,7 @@ local make_grass_path = function(itemstack, placer, pointed_thing) local wear = mcl_autogroup.get_wear(toolname, "shovely") if wear then itemstack:add_wear(wear) + tt.reload_itemstack_description(itemstack) -- update tooltip end end minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = above, max_hear_distance = 16}, true) @@ -209,6 +210,7 @@ local make_grass_path = function(itemstack, placer, pointed_thing) local wear = mcl_autogroup.get_wear(toolname, "shovely") if wear then itemstack:add_wear(wear) + tt.reload_itemstack_description(itemstack) -- update tooltip end end minetest.sound_play({name="default_grass_footstep", gain=1}, {pos = above, max_hear_distance = 16}, true) @@ -240,6 +242,7 @@ if minetest.get_modpath("mcl_farming") then local wear = mcl_autogroup.get_wear(toolname, "shearsy") if wear then itemstack:add_wear(wear) + tt.reload_itemstack_description(itemstack) -- update tooltip end end @@ -420,6 +423,7 @@ local function make_stripped_trunk(itemstack, placer, pointed_thing) local wear = mcl_autogroup.get_wear(toolname, "axey") if wear then itemstack:add_wear(wear) + tt.reload_itemstack_description(itemstack) -- update tooltip end end end