From 9e58e928fda56da4f24213c828e495f7c74e7855 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 8 Mar 2017 20:09:46 +0100 Subject: [PATCH] Import wielditem name display Unified Inventory --- mods/HUD/mcl_item_names/LICENSE.md | 5 +++ mods/HUD/mcl_item_names/description.txt | 1 + mods/HUD/mcl_item_names/init.lua | 56 +++++++++++++++++++++++++ mods/HUD/mcl_item_names/mod.conf | 1 + 4 files changed, 63 insertions(+) create mode 100644 mods/HUD/mcl_item_names/LICENSE.md create mode 100644 mods/HUD/mcl_item_names/description.txt create mode 100644 mods/HUD/mcl_item_names/init.lua create mode 100644 mods/HUD/mcl_item_names/mod.conf diff --git a/mods/HUD/mcl_item_names/LICENSE.md b/mods/HUD/mcl_item_names/LICENSE.md new file mode 100644 index 000000000..ba26be1ca --- /dev/null +++ b/mods/HUD/mcl_item_names/LICENSE.md @@ -0,0 +1,5 @@ +This mod is licensed under GNU LGPLv2 or later. + +It was taken from the file “`item_names.lua`” found in the Unified Inventory mod maintained +by VanessaE. +Original author: 4aiman diff --git a/mods/HUD/mcl_item_names/description.txt b/mods/HUD/mcl_item_names/description.txt new file mode 100644 index 000000000..95a17237e --- /dev/null +++ b/mods/HUD/mcl_item_names/description.txt @@ -0,0 +1 @@ +Displays the name of the wielded item diff --git a/mods/HUD/mcl_item_names/init.lua b/mods/HUD/mcl_item_names/init.lua new file mode 100644 index 000000000..243b938b5 --- /dev/null +++ b/mods/HUD/mcl_item_names/init.lua @@ -0,0 +1,56 @@ +-- Based on 4itemnames mod by 4aiman + +local wield = {} +local huds = {} +local dtimes = {} +local dlimit = 3 -- HUD element will be hidden after this many seconds +local air_hud_mod = minetest.get_modpath("4air") +local hud_mod = minetest.get_modpath("hud") +local hudbars_mod = minetest.get_modpath("hudbars") + +local function set_hud(player) + local player_name = player:get_player_name() + local off = {x=0, y=-70} + if air_hud_mod or hud_mod then + off.y = off.y - 20 + elseif hudbars_mod then + off.y = off.y + 13 + end + huds[player_name] = player:hud_add({ + hud_elem_type = "text", + position = {x=0.5, y=1}, + offset = off, + alignment = {x=0, y=0}, + number = 0xFFFFFF , + text = "", + }) +end + +minetest.register_on_joinplayer(function(player) + minetest.after(0, set_hud, player) +end) + +minetest.register_globalstep(function(dtime) + for _, player in pairs(minetest.get_connected_players()) do + local player_name = player:get_player_name() + local wstack = player:get_wielded_item():get_name() + + if dtimes[player_name] and dtimes[player_name] < dlimit then + dtimes[player_name] = dtimes[player_name] + dtime + if dtimes[player_name] > dlimit and huds[player_name] then + player:hud_change(huds[player_name], 'text', "") + end + end + + if wstack ~= wield[player_name] then + wield[player_name] = wstack + dtimes[player_name] = 0 + if huds[player_name] then + local def = minetest.registered_items[wstack] + local desc = def and def.description or "" + player:hud_change(huds[player_name], 'text', desc) + end + end + end +end) + diff --git a/mods/HUD/mcl_item_names/mod.conf b/mods/HUD/mcl_item_names/mod.conf new file mode 100644 index 000000000..7b5450357 --- /dev/null +++ b/mods/HUD/mcl_item_names/mod.conf @@ -0,0 +1 @@ +name = mcl_item_names