make hud update instant on using the compass
This commit is contained in:
parent
ef4adb9613
commit
3633a0cabf
85
init.lua
85
init.lua
@ -5,7 +5,7 @@ local waypoint_color = 0xFC7D0A
|
|||||||
local target_above = false
|
local target_above = false
|
||||||
local point_to_objects = false -- unimplemented
|
local point_to_objects = false -- unimplemented
|
||||||
local point_to_liquids = true
|
local point_to_liquids = true
|
||||||
local compass_range = 96
|
local compass_range = 180
|
||||||
|
|
||||||
-- lua metatables? what is that? :P
|
-- lua metatables? what is that? :P
|
||||||
-- local function get_compass_meta_id(meta)
|
-- local function get_compass_meta_id(meta)
|
||||||
@ -46,7 +46,7 @@ end
|
|||||||
-- return minetest.get_position_from_hash(meta:get_int("waypoint_compass:position"))
|
-- return minetest.get_position_from_hash(meta:get_int("waypoint_compass:position"))
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
local function set_waypoint_at_pointed_place(itemstack, user, pointed_thing)
|
local function set_waypoint_at_pointed_place(itemstack, pointed_thing)
|
||||||
if pointed_thing and pointed_thing.type == "node" then
|
if pointed_thing and pointed_thing.type == "node" then
|
||||||
local pointed_pos = target_above and pointed_thing.above or pointed_thing.under
|
local pointed_pos = target_above and pointed_thing.above or pointed_thing.under
|
||||||
local meta = itemstack:get_meta()
|
local meta = itemstack:get_meta()
|
||||||
@ -75,31 +75,9 @@ local function raycast_crosshair(player, range)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_tool(
|
|
||||||
"waypoint_compass:compass", {
|
|
||||||
description = "Waypoint compass",
|
|
||||||
short_description = "Waypoint compass",
|
|
||||||
inventory_image = "Waypoint_compass_inventory_image.png",
|
|
||||||
wield_scale = {x = 0.5, y = 0.5, z = 0.5},
|
|
||||||
range = 2.0, -- TODO what's the good range?
|
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
|
||||||
set_waypoint_at_pointed_place(itemstack, placer, pointed_thing)
|
|
||||||
return itemstack
|
|
||||||
end,
|
|
||||||
on_secondary_use = function(itemstack, user, pointed_thing)
|
|
||||||
if pointed_thing.type == "nothing" then
|
|
||||||
if user:is_player() then
|
|
||||||
pointed_thing = raycast_crosshair(user, compass_range)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
set_waypoint_at_pointed_place(itemstack, user, pointed_thing)
|
|
||||||
return itemstack
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
local function hide_hud_waypoint(player)
|
||||||
local function remove_hud_waypoint(player, player_name)
|
local player_name = player:get_player_name()
|
||||||
---print("hud remove")
|
|
||||||
local hud_id = player_waypoints[player_name].hud_id
|
local hud_id = player_waypoints[player_name].hud_id
|
||||||
player_waypoints[player_name] = nil
|
player_waypoints[player_name] = nil
|
||||||
player:hud_remove(hud_id)
|
player:hud_remove(hud_id)
|
||||||
@ -128,21 +106,20 @@ local function show_hud_waypoint(player, compass_item_meta)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local timer = 0
|
-- if item is a compass, then show stored waypoint
|
||||||
minetest.register_globalstep(function(dtime)
|
local function update_hud_waypoint(player, itemstack)
|
||||||
timer = timer + dtime
|
if not player:is_player() then
|
||||||
if timer > update_interval then
|
return
|
||||||
for _,player in pairs(minetest.get_connected_players()) do
|
end
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local item = player:get_wielded_item()
|
|
||||||
-- player is holding compass
|
-- player is holding compass
|
||||||
if (item and item:get_name() == "waypoint_compass:compass") then
|
if (itemstack and itemstack:get_name() == "waypoint_compass:compass") then
|
||||||
local meta = item:get_meta()
|
local meta = itemstack:get_meta()
|
||||||
local waypoint_pos = get_compass_meta_pos(meta)
|
local waypoint_pos = get_compass_meta_pos(meta)
|
||||||
-- remove different waypoint if it exists
|
-- remove different waypoint if it exists
|
||||||
if player_waypoints[player_name] and
|
if player_waypoints[player_name] and
|
||||||
(player_waypoints[player_name].pos ~= waypoint_pos) then
|
(player_waypoints[player_name].pos ~= waypoint_pos) then
|
||||||
remove_hud_waypoint(player, player_name)
|
hide_hud_waypoint(player)
|
||||||
end
|
end
|
||||||
-- show new waypoint
|
-- show new waypoint
|
||||||
if not player_waypoints[player_name] then
|
if not player_waypoints[player_name] then
|
||||||
@ -151,10 +128,46 @@ minetest.register_globalstep(function(dtime)
|
|||||||
else
|
else
|
||||||
-- not holding it anymore
|
-- not holding it anymore
|
||||||
if player_waypoints[player_name] then
|
if player_waypoints[player_name] then
|
||||||
remove_hud_waypoint(player, player_name)
|
hide_hud_waypoint(player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local timer = 0
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
timer = timer + dtime
|
||||||
|
if timer > update_interval then
|
||||||
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
|
local itemstack = player:get_wielded_item()
|
||||||
|
update_hud_waypoint(player, itemstack)
|
||||||
|
end
|
||||||
timer = 0
|
timer = 0
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_tool(
|
||||||
|
"waypoint_compass:compass", {
|
||||||
|
description = "Waypoint compass",
|
||||||
|
short_description = "Waypoint compass",
|
||||||
|
inventory_image = "Waypoint_compass_inventory_image.png",
|
||||||
|
wield_scale = {x = 0.5, y = 0.5, z = 0.5},
|
||||||
|
range = 2.0, -- TODO what's the good range?
|
||||||
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
set_waypoint_at_pointed_place(itemstack, pointed_thing)
|
||||||
|
update_hud_waypoint(placer, itemstack)
|
||||||
|
return itemstack
|
||||||
|
end,
|
||||||
|
on_secondary_use = function(itemstack, user, pointed_thing)
|
||||||
|
if pointed_thing.type == "nothing" then
|
||||||
|
if user and user:is_player() then
|
||||||
|
pointed_thing = raycast_crosshair(user, compass_range)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
set_waypoint_at_pointed_place(itemstack, pointed_thing)
|
||||||
|
update_hud_waypoint(user, itemstack)
|
||||||
|
return itemstack
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user