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 compass_precision = 10 -- set to 1 to show whole number or 10 for 1 decimal
|
||||
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_liquids = true
|
||||
local compass_range = 180
|
||||
@ -24,8 +24,6 @@ local function set_compass_meta_label(meta, label)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
local function set_compass_meta_pos(meta, pos)
|
||||
local pos_str = minetest.serialize(pos)
|
||||
meta:set_string("waypoint_compass:position", pos_str)
|
||||
@ -75,7 +73,6 @@ local function raycast_crosshair(player, range)
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function hide_hud_waypoint(player)
|
||||
local player_name = player:get_player_name()
|
||||
local hud_id = player_waypoints[player_name].hud_id
|
||||
@ -147,6 +144,16 @@ minetest.register_globalstep(function(dtime)
|
||||
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(
|
||||
"waypoint_compass:compass", {
|
||||
description = "Waypoint compass",
|
||||
@ -155,18 +162,11 @@ minetest.register_tool(
|
||||
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)
|
||||
compass_use_callback(itemstack, placer, pointed_thing)
|
||||
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)
|
||||
compass_use_callback(itemstack, user, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user