From fda0e23677d600f36a0038c0e1a88371624cdb7b Mon Sep 17 00:00:00 2001 From: oilboi <47129783+oilboi@users.noreply.github.com> Date: Fri, 15 May 2020 17:55:43 -0400 Subject: [PATCH] Add in csm WAIH (What Am I Holding) --- init.lua | 1 + waila.lua | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/init.lua b/init.lua index e7c2aad..5f83326 100644 --- a/init.lua +++ b/init.lua @@ -7,6 +7,7 @@ player_movement_state = nil nether = nil aether = nil run = nil + function initialize_all() --declare globals for now weather_intake = minetest.mod_channel_join("weather_intake") diff --git a/waila.lua b/waila.lua index 44c3da7..c72febc 100644 --- a/waila.lua +++ b/waila.lua @@ -33,7 +33,25 @@ local hud_node = minetest.localplayer:hud_add({ }) +local waih_name = minetest.localplayer:hud_add({ + name = "hud_name", + position = {x=0.5,y=1}, + hud_elem_type = "text", + number = 0xFFFFFF, + alignment = 0, + offset = { x = 0, y = -150}, + text = "", + z_index = 1, +}) + + +local pos_min = 10 +local pos_max = -150 +local waih_timer = 0 +local old_item = "" + local function update() + --waila if minetest.camera then local pos = minetest.camera:get_pos() local pos2 = vector.add(pos,vector.multiply(minetest.camera:get_look_dir(), 4)) @@ -57,6 +75,25 @@ local function update() hud_item_name = "" end end + + + --waih + local item = minetest.localplayer:get_wielded_item():get_name() + if waih_timer > 0 then + waih_timer = waih_timer - 0.01 + if waih_timer <= 0 then + waih_timer = 0 + minetest.localplayer:hud_change(waih_name, "text", "") + end + end + if item ~= old_item then + waih_timer = 1 + local description = minetest.get_item_def(item).description + minetest.localplayer:hud_change(waih_name, "text", description) + end + old_item = item + + minetest.after(0.01, function() update() end) -- 2.44.0