diff --git a/hud.lua b/hud.lua new file mode 100644 index 0000000..8acb454 --- /dev/null +++ b/hud.lua @@ -0,0 +1,55 @@ +local ipairs + = ipairs + +local minetest, vector + = minetest, vector + +local player_huds = {} + +local function do_player_rotating_checks(player) + local name = player:get_player_name() + + local hud_index = player_huds[name] + if hud_index then + player:hud_remove(hud_index) + player_huds[name] = nil + end + + local look_dir = player:get_look_dir() + local player_pos = vector.copy(player:get_pos()) + local eye_offset = vector.divide(player:get_eye_offset(), 10) + local eye_height = player:get_properties().eye_height; + local eye_pos = player_pos + eye_offset + vector.new(0, eye_height, 0) + + local default_reach = minetest.registered_items[""].range or 4 + local wielded_reach = player:get_wielded_item():get_definition().reach + local reach = wielded_reach or default_reach + + local node = nil + local ray = minetest.raycast(eye_pos, eye_pos + look_dir * reach, false, false) + for pointed_thing in ray do node = pointed_thing end + + if node then + hud_index = player:hud_add({ + hud_elem_type = "image", + name = "rotation hint", + text = "nc_extended_rotating_hud_rotate_clockwise.png", + position = { x = 0.5, y = 0.5 }, + offset = { x = 0, y = 0 }, + alignment = { x = 0, y = 0 }, + scale = { x = 1, y = 1 }, + }) + player_huds[name] = hud_index + end +end + +minetest.register_globalstep(function(delta_time) + for _, player in ipairs(minetest.get_connected_players()) do + do_player_rotating_checks(player) + end +end) + +minetest.register_on_leaveplayer(function(player) + local name = player:get_player_name() + player_huds[name] = nil +end) diff --git a/init.lua b/init.lua index 9064164..99e69b4 100755 --- a/init.lua +++ b/init.lua @@ -2,6 +2,7 @@ local minetest, vector, include = minetest, vector, include local rotate = include("rotate") +local hud = include("hud") minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) local def = minetest.registered_nodes[node.name] diff --git a/textures/nc_extended_rotating_hud_rotate_clockwise.png b/textures/nc_extended_rotating_hud_rotate_clockwise.png new file mode 100644 index 0000000..5c7c50f Binary files /dev/null and b/textures/nc_extended_rotating_hud_rotate_clockwise.png differ diff --git a/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png b/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png new file mode 100644 index 0000000..4ec901c Binary files /dev/null and b/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png differ