From e793c26f642015a9f9d96d6aead984a09b1bbb50 Mon Sep 17 00:00:00 2001 From: whosit Date: Fri, 14 May 2021 19:16:50 +0300 Subject: [PATCH] Just basic HUD waypoint toggle on use --- init.lua | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 init.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..2ad83e7 --- /dev/null +++ b/init.lua @@ -0,0 +1,47 @@ +local player_waypoints = {} + +minetest.register_tool("waypoint_compass:compass", { + description = "Waypoint compass", + inventory_image = "Waypoint_compass_inventory_image.png", + -- Display HUD waypoint on use + on_use = function(itemstack, user, pointed_thing) + if not itemstack then + return nil + end + local meta = itemstack:get_meta() + local waypoint_id = meta:get_string("waypoint_compass:id") + if user and user:is_player() then + local player = user + local player_name = player:get_player_name() + if (player_waypoints[player_name] and + player_waypoints[player_name][waypoint_id]) then + -- Waypoint is currently displayed, remove it + local hud_id = player_waypoints[player_name][waypoint_id] + print("hud_id remove", hud_id) + player_waypoints[player_name][waypoint_id] = nil + player:hud_remove(hud_id) + else + -- Show this waypoint + local waypoint_name = meta:get_string("waypoint_compass:name") ~= "" or "destination" + local hud_id = player:hud_add({ + hud_elem_type = "waypoint", + name = waypoint_name, + text = "m", + precision=1, + number = 0xFF, --0xFFFFFF, + world_pos = {x=0, y=0, z=0}, + }) + -- store HUD elemnt id to remove it later + if not player_waypoints[player_name] then + player_waypoints[player_name] = {} + end + print("hud_id add", hud_id) + player_waypoints[player_name][waypoint_id] = hud_id + end + + end + return nil + end, +}) + +