diff --git a/init.lua b/init.lua index ffaf59d..adf6b0e 100644 --- a/init.lua +++ b/init.lua @@ -1,10 +1,10 @@ -local update_interval = 1.31415 -local compass_precision = 10 -- set to 1 to show whole number or 10 for 1 decimal -local default_waypoint_color = 0xFFFFFF -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 +local UPDATE_INTERVAL = 1.31415 +local COMPASS_PRECISION = 10 -- set to 1 to show whole number or 10 for 1 decimal +local DEFAULT_WAYPOINT_COLOR = 0xFFFFFF +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 -- internal mod state @@ -51,7 +51,7 @@ local function get_compass_meta_color(meta) if color > 0 then return color else - return default_waypoint_color + return DEFAULT_WAYPOINT_COLOR end end @@ -78,7 +78,7 @@ end local function set_waypoint_at_pointed_place(itemstack, pointed_thing) 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() meta:set_string("description", string.format("Waypoint compass %s", minetest.pos_to_string(pointed_pos))) set_compass_meta_pos(meta, pointed_pos) @@ -96,7 +96,7 @@ local function raycast_crosshair(player, range) local p_eye_height = player:get_properties().eye_height local p_eye_pos = { x = p_pos.x, y = p_pos.y + p_eye_height, z = p_pos.z } local to = vector.add(p_eye_pos, vector.multiply(player:get_look_dir(), range)) - local ray = minetest.raycast(p_eye_pos, to, point_to_objects, point_to_liquids) + local ray = minetest.raycast(p_eye_pos, to, POINT_TO_OBJECTS, POINT_TO_LIQUIDS) local pointed_thing = ray:next() return pointed_thing -- while pointed_thing do @@ -128,7 +128,7 @@ local function show_hud_waypoint(player, compass_item_meta) hud_elem_type = "waypoint", name = waypoint_name, text = "m", - precision= compass_precision, + precision= COMPASS_PRECISION, number = waypoint_color, world_pos = waypoint_pos, }) @@ -177,7 +177,7 @@ end local timer = 0 minetest.register_globalstep(function(dtime) timer = timer + dtime - if timer > update_interval then + 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) @@ -260,7 +260,7 @@ local function compass_use_callback(itemstack, user, pointed_thing) if user:get_player_control()["sneak"] then if pointed_thing.type == "nothing" then if user and user:is_player() then - pointed_thing = raycast_crosshair(user, compass_range) + pointed_thing = raycast_crosshair(user, COMPASS_RANGE) end end set_waypoint_at_pointed_place(itemstack, pointed_thing)