From b6ee94f9b2dc33d9aab28b0ab4072c84d17d8334 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 6 Jun 2017 19:05:28 +0200 Subject: [PATCH] Use new player attribute API for bed spawns --- mods/ITEMS/mcl_beds/functions.lua | 5 +-- mods/ITEMS/mcl_beds/init.lua | 2 - mods/ITEMS/mcl_beds/spawns.lua | 63 ------------------------------- 3 files changed, 2 insertions(+), 68 deletions(-) delete mode 100644 mods/ITEMS/mcl_beds/spawns.lua diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index db1ece7da..589ccfe2a 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -149,7 +149,7 @@ function mcl_beds.on_rightclick(pos, player) -- move to bed if not mcl_beds.player[name] then lay_down(player, ppos, pos) - mcl_beds.set_spawns() -- save respawn positions when entering bed + player:set_attribute("mcl_beds:spawn", minetest.pos_to_string(player:getpos())) -- save respawn position when entering bed else lay_down(player, nil, nil, false) end @@ -178,8 +178,7 @@ end if enable_respawn then -- respawn player at bed if enabled and valid position is found minetest.register_on_respawnplayer(function(player) - local name = player:get_player_name() - local pos = mcl_beds.spawn[name] + local pos = minetest.string_to_pos(player:get_attribute("mcl_beds:spawn")) if pos then player:setpos(pos) return true diff --git a/mods/ITEMS/mcl_beds/init.lua b/mods/ITEMS/mcl_beds/init.lua index 40b646522..72bfb3478 100644 --- a/mods/ITEMS/mcl_beds/init.lua +++ b/mods/ITEMS/mcl_beds/init.lua @@ -1,7 +1,6 @@ mcl_beds = {} mcl_beds.player = {} mcl_beds.pos = {} -mcl_beds.spawn = {} mcl_beds.formspec = "size[8,15;true]" .. "bgcolor[#080808BB; true]" .. @@ -14,4 +13,3 @@ local modpath = minetest.get_modpath("mcl_beds") dofile(modpath .. "/functions.lua") dofile(modpath .. "/api.lua") dofile(modpath .. "/beds.lua") -dofile(modpath .. "/spawns.lua") diff --git a/mods/ITEMS/mcl_beds/spawns.lua b/mods/ITEMS/mcl_beds/spawns.lua deleted file mode 100644 index 11b09b12e..000000000 --- a/mods/ITEMS/mcl_beds/spawns.lua +++ /dev/null @@ -1,63 +0,0 @@ -local world_path = minetest.get_worldpath() -local org_file = world_path .. "/beds_spawns" -local file = world_path .. "/beds_spawns" -local bkwd = false - --- check for PA's beds mod spawns -local cf = io.open(world_path .. "/beds_player_spawns", "r") -if cf ~= nil then - io.close(cf) - file = world_path .. "/beds_player_spawns" - bkwd = true -end - -function mcl_beds.save_spawns() - if not mcl_beds.spawn then - return - end - local data = {} - local output = io.open(org_file, "w") - for k, v in pairs(mcl_beds.spawn) do - table.insert(data, string.format("%.1f %.1f %.1f %s\n", v.x, v.y, v.z, k)) - end - output:write(table.concat(data)) - io.close(output) -end - -function mcl_beds.read_spawns() - local spawns = mcl_beds.spawn - local input = io.open(file, "r") - if input and not bkwd then - repeat - local x = input:read("*n") - if x == nil then - break - end - local y = input:read("*n") - local z = input:read("*n") - local name = input:read("*l") - spawns[name:sub(2)] = {x = x, y = y, z = z} - until input:read(0) == nil - io.close(input) - elseif input and bkwd then - mcl_beds.spawn = minetest.deserialize(input:read("*all")) - input:close() - mcl_beds.save_spawns() - os.rename(file, file .. ".backup") - file = org_file - end -end - -mcl_beds.read_spawns() - -function mcl_beds.set_spawns() - for name,_ in pairs(mcl_beds.player) do - local player = minetest.get_player_by_name(name) - local p = player:getpos() - -- but don't change spawn location if borrowing a bed - if not minetest.is_protected(p, name) then - mcl_beds.spawn[name] = p - end - end - mcl_beds.save_spawns() -end