Added setting for different compass modes instead of the hardcoded chain. Added "origin" mode
This commit is contained in:
parent
92917982ad
commit
27b8da1796
48
init.lua
48
init.lua
@ -1,25 +1,25 @@
|
|||||||
-- default to static_spawnpoint or 0/0/0
|
-- default to static_spawnpoint or 0/0/0
|
||||||
local default_spawn = minetest.setting_get_pos("static_spawnpoint") or {x=0, y=0, z=0}
|
local default_spawn = minetest.setting_get_pos("static_spawnpoint") or {x=0, y=0, z=0}
|
||||||
|
|
||||||
|
-- supported modes: default, sethome, beds, origin
|
||||||
|
local compass_mode = minetest.setting_get("compass_mode") or "default"
|
||||||
|
|
||||||
-- Get players spawn point (compass target) in order sethome, beds-spawn and static_spawnpoint
|
-- Get players spawn point (compass target) in order sethome, beds-spawn and static_spawnpoint
|
||||||
local function get_spawn(player)
|
local function get_destination(player, stack)
|
||||||
local playername = player:get_player_name()
|
if compass_mode == "default" then
|
||||||
local spawn
|
return minetest.setting_get_pos("static_spawnpoint") or default_spawn
|
||||||
if minetest.global_exists("sethome") then
|
elseif compass_mode == "sethome" then
|
||||||
spawn = sethome.get(playername)
|
return sethome.get(player:get_player_name()) or default_spawn
|
||||||
|
elseif compass_mode == "beds" then
|
||||||
|
return beds.spawn[player:get_player_name()] or default_spawn
|
||||||
|
elseif compass_mode == "origin" then
|
||||||
|
return minetest.string_to_pos(stack:get_metadata())
|
||||||
end
|
end
|
||||||
if not spawn and minetest.global_exists("beds") and beds.spawn then
|
|
||||||
spawn = beds.spawn[playername]
|
|
||||||
end
|
|
||||||
if not spawn then
|
|
||||||
spawn = default_spawn
|
|
||||||
end
|
|
||||||
return spawn
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- get right image number for players compas
|
-- get right image number for players compas
|
||||||
local function get_compass_image(player)
|
local function get_compass_stack(player, stack)
|
||||||
local spawn = get_spawn(player)
|
local spawn = get_destination(player, stack)
|
||||||
local pos = player:getpos()
|
local pos = player:getpos()
|
||||||
local dir = player:get_look_yaw()
|
local dir = player:get_look_yaw()
|
||||||
local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z))
|
local angle_north = math.deg(math.atan2(spawn.x - pos.x, spawn.z - pos.z))
|
||||||
@ -29,7 +29,8 @@ local function get_compass_image(player)
|
|||||||
local angle_dir = 90 - math.deg(dir)
|
local angle_dir = 90 - math.deg(dir)
|
||||||
local angle_relative = (angle_north - angle_dir) % 360
|
local angle_relative = (angle_north - angle_dir) % 360
|
||||||
local compass_image = math.floor((angle_relative/30) + 0.5)%12
|
local compass_image = math.floor((angle_relative/30) + 0.5)%12
|
||||||
return compass_image
|
|
||||||
|
return "compass:"..compass_image.." 1 0 "..stack:get_metadata()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- update inventory
|
-- update inventory
|
||||||
@ -37,11 +38,20 @@ minetest.register_globalstep(function(dtime)
|
|||||||
for i,player in ipairs(minetest.get_connected_players()) do
|
for i,player in ipairs(minetest.get_connected_players()) do
|
||||||
if player:get_inventory() then
|
if player:get_inventory() then
|
||||||
for i,stack in ipairs(player:get_inventory():get_list("main")) do
|
for i,stack in ipairs(player:get_inventory():get_list("main")) do
|
||||||
if i > 8 then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
if string.sub(stack:get_name(), 0, 8) == "compass:" then
|
if string.sub(stack:get_name(), 0, 8) == "compass:" then
|
||||||
player:get_inventory():set_stack("main", i, "compass:"..get_compass_image(player))
|
if compass_mode == "origin" then
|
||||||
|
local meta = stack:get_metadata()
|
||||||
|
if not meta or meta == "" then
|
||||||
|
meta = minetest.pos_to_string(player:getpos())
|
||||||
|
stack:set_metadata(meta)
|
||||||
|
player:get_inventory():set_stack("main", i, stack)
|
||||||
|
end
|
||||||
|
elseif i > 8 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if i <= 8 then
|
||||||
|
player:get_inventory():set_stack("main", i, get_compass_stack(player, stack))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
6
settingtypes.txt
Normal file
6
settingtypes.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Where the compass should point
|
||||||
|
# default = points to the "static_spawnpoint" setting coordinates or to 0,0,0 if nothing set
|
||||||
|
# sethome = points to the players home from sethome mod, default as fallback
|
||||||
|
# beds = points to the players spawn point trough the beds mod, default as fallback
|
||||||
|
# origin = points to the individual compass origin that means the place the compass was crafted or picked first time
|
||||||
|
compass_mode (Compass Mode) string default
|
Loading…
x
Reference in New Issue
Block a user