split code into compass_use_callback to use with on_place and on_use
This commit is contained in:
parent
3633a0cabf
commit
0357e8a267
26
init.lua
26
init.lua
@ -2,7 +2,7 @@ local player_waypoints = {}
|
|||||||
local update_interval = 1.31415
|
local update_interval = 1.31415
|
||||||
local compass_precision = 10 -- set to 1 to show whole number or 10 for 1 decimal
|
local compass_precision = 10 -- set to 1 to show whole number or 10 for 1 decimal
|
||||||
local waypoint_color = 0xFC7D0A
|
local waypoint_color = 0xFC7D0A
|
||||||
local target_above = false
|
local target_above = false -- place waypoint inside the block or above it
|
||||||
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 = 180
|
local compass_range = 180
|
||||||
@ -24,8 +24,6 @@ local function set_compass_meta_label(meta, label)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function set_compass_meta_pos(meta, pos)
|
local function set_compass_meta_pos(meta, pos)
|
||||||
local pos_str = minetest.serialize(pos)
|
local pos_str = minetest.serialize(pos)
|
||||||
meta:set_string("waypoint_compass:position", pos_str)
|
meta:set_string("waypoint_compass:position", pos_str)
|
||||||
@ -75,7 +73,6 @@ local function raycast_crosshair(player, range)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function hide_hud_waypoint(player)
|
local function hide_hud_waypoint(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local hud_id = player_waypoints[player_name].hud_id
|
local hud_id = player_waypoints[player_name].hud_id
|
||||||
@ -147,6 +144,16 @@ minetest.register_globalstep(function(dtime)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
local function compass_use_callback(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)
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_tool(
|
minetest.register_tool(
|
||||||
"waypoint_compass:compass", {
|
"waypoint_compass:compass", {
|
||||||
description = "Waypoint compass",
|
description = "Waypoint compass",
|
||||||
@ -155,18 +162,11 @@ minetest.register_tool(
|
|||||||
wield_scale = {x = 0.5, y = 0.5, z = 0.5},
|
wield_scale = {x = 0.5, y = 0.5, z = 0.5},
|
||||||
range = 2.0, -- TODO what's the good range?
|
range = 2.0, -- TODO what's the good range?
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
set_waypoint_at_pointed_place(itemstack, pointed_thing)
|
compass_use_callback(itemstack, placer, pointed_thing)
|
||||||
update_hud_waypoint(placer, itemstack)
|
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
on_secondary_use = function(itemstack, user, pointed_thing)
|
on_secondary_use = function(itemstack, user, pointed_thing)
|
||||||
if pointed_thing.type == "nothing" then
|
compass_use_callback(itemstack, user, pointed_thing)
|
||||||
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
|
return itemstack
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user