diff --git a/hud.lua b/hud.lua index 8acb454..b9a8341 100644 --- a/hud.lua +++ b/hud.lua @@ -4,6 +4,11 @@ local ipairs local minetest, vector = minetest, vector +local rotate = include("rotate") + +local TEX_ROTATE_CLOCKWISE = "nc_extended_rotating_hud_rotate_clockwise.png" +local TEX_ROTATE_COUNTER_CLOCKWISE = "nc_extended_rotating_hud_rotate_counter_clockwise.png" + local player_huds = {} local function do_player_rotating_checks(player) @@ -11,6 +16,7 @@ local function do_player_rotating_checks(player) local hud_index = player_huds[name] if hud_index then + -- FIXME: Only remove / update HUD elements when necessary. player:hud_remove(hud_index) player_huds[name] = nil end @@ -27,13 +33,20 @@ local function do_player_rotating_checks(player) 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 + for pointed_thing in ray do + if pointed_thing.type == "node" then + node = minetest.get_node(pointed_thing.under) + break + end + end - if node then + if node and rotate.is_rotatable(node) then + local is_sneaking = player:get_player_control().sneak + local texture = is_sneaking and TEX_ROTATE_COUNTER_CLOCKWISE or TEX_ROTATE_CLOCKWISE hud_index = player:hud_add({ hud_elem_type = "image", name = "rotation hint", - text = "nc_extended_rotating_hud_rotate_clockwise.png", + text = texture, position = { x = 0.5, y = 0.5 }, offset = { x = 0, y = 0 }, alignment = { x = 0, y = 0 }, diff --git a/rotate.lua b/rotate.lua index cb6a164..caf193c 100644 --- a/rotate.lua +++ b/rotate.lua @@ -39,13 +39,19 @@ for up_index, up in ipairs(AXIS_LOOKUP) do end end +-- Returns whether the specified `node` is rotatable by this mod. +-- TODO: Register such that only certain nodes may be rotated. +local function is_rotatable(node) + local def = minetest.registered_nodes[node.name] + return def.paramtype2 == "facedir" +end +rotate.is_rotatable = is_rotatable + -- Rotates `node` at the specified `pos` around `axis` by `degrees` counter-clockwise. local function rotate_node(pos, node, axis, degrees) if degrees % 90 ~= 0 then error("degrees must be divisible by 90") end if axis_vector_to_index(axis) == nil then error("axis must be an axis vector") end - - local def = minetest.registered_nodes[node.name] - if def.paramtype2 ~= "facedir" then error("node's paramtype2 is not 'facedir'") end + if not is_rotatable(node) then error("node is not rotatable") end local up = AXIS_LOOKUP[1 + math.floor(node.param2 / 4)] local back = minetest.facedir_to_dir(node.param2) diff --git a/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png b/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png index 4ec901c..ac66a85 100644 Binary files a/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png and b/textures/nc_extended_rotating_hud_rotate_counter_clockwise.png differ