2019-08-19 21:43:41 -04:00
|
|
|
maggems_landmark = {}
|
|
|
|
local modstore = minetest.get_mod_storage()
|
|
|
|
|
|
|
|
function maggems_landmark.is_protected(pos, name)
|
|
|
|
local homes = maggems_landmark.homes
|
2019-09-01 16:46:55 -04:00
|
|
|
for id, area in pairs(homes:get_areas_for_pos(pos, true, true)) do
|
|
|
|
if (minetest.get_node(minetest.deserialize(area.data)).name ~= "maggems_landmark:home") then
|
2019-09-01 16:01:47 -04:00
|
|
|
homes:remove_area(id)
|
|
|
|
minetest.debug("orphaned area quietly deleted...")
|
|
|
|
else
|
|
|
|
minetest.debug("found an area!", dump(area))
|
|
|
|
local meta = minetest.get_meta(minetest.deserialize(area.data))
|
|
|
|
if (meta:get_string("owner") ~= name) then
|
|
|
|
minetest.chat_send_player(name, "Woah, buddy! That's "..meta:get_string("owner").."'s home!")
|
|
|
|
minetest.chat_send_player(meta:get_string("owner"), "Hey! "..name.."'s trying to build at "..meta:get_string("maggems_landmark:name").."!")
|
|
|
|
return true
|
|
|
|
end
|
2019-08-22 14:26:11 -04:00
|
|
|
end
|
2019-08-19 21:43:41 -04:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
local old_is_protected = minetest.is_protected
|
|
|
|
function minetest.is_protected(pos, name)
|
|
|
|
if (maggems_landmark.is_protected(pos, name)) then return true end
|
|
|
|
return old_is_protected(pos, name)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player)
|
|
|
|
local name = player:get_player_name()
|
2019-08-22 14:26:11 -04:00
|
|
|
if (maggems_landmark.homes ~= nil) then return end
|
2019-08-21 22:11:39 -04:00
|
|
|
maggems_landmark.homes = AreaStore()
|
|
|
|
local stored_homes = modstore:get("homes")
|
|
|
|
if (stored_homes) then
|
|
|
|
stored_homes = minetest.decode_base64(stored_homes)
|
|
|
|
maggems_landmark.homes:from_string(stored_homes)
|
2019-08-19 21:43:41 -04:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2019-09-02 10:57:33 -04:00
|
|
|
function maggems_landmark.save_homes()
|
2019-08-21 22:11:39 -04:00
|
|
|
local homes = maggems_landmark.homes
|
|
|
|
modstore:set_string("homes", minetest.encode_base64(homes:to_string()))
|
2019-08-20 21:05:21 -04:00
|
|
|
end
|
|
|
|
|
2019-09-02 10:57:33 -04:00
|
|
|
function maggems_landmark.update_formspec(pos)
|
2019-09-01 16:01:47 -04:00
|
|
|
local meta = minetest.get_meta(pos)
|
2019-09-01 15:40:34 -04:00
|
|
|
local formspec = "size[11,5.5]real_coordinates[true]"
|
|
|
|
formspec = formspec .. "field[1,1;9,0.5;name;Home name;${maggems_landmark:name}]"
|
|
|
|
local pos1 = minetest.deserialize(meta:get_string("maggems_landmark:pos1"))
|
|
|
|
formspec = formspec .. "field[1,2;3,0.5;minx;Min corner X;"..pos1.x-pos.x.."]"
|
|
|
|
formspec = formspec .. "field[4,2;3,0.5;miny;Min corner Y;"..pos1.y-pos.y.."]"
|
|
|
|
formspec = formspec .. "field[7,2;3,0.5;minz;Min corner Z;"..pos1.z-pos.z.."]"
|
|
|
|
local pos2 = minetest.deserialize(meta:get_string("maggems_landmark:pos2"))
|
|
|
|
formspec = formspec .. "field[1,3;3,0.5;maxx;Max corner X;"..pos2.x-pos.x.."]"
|
|
|
|
formspec = formspec .. "field[4,3;3,0.5;maxy;Max corner Y;"..pos2.y-pos.y.."]"
|
|
|
|
formspec = formspec .. "field[7,3;3,0.5;maxz;Max corner Z;"..pos2.z-pos.z.."]"
|
|
|
|
meta:set_string("formspec", formspec)
|
|
|
|
end
|
|
|
|
|
2019-09-02 14:12:16 -04:00
|
|
|
dofile(minetest.get_modpath("maggems_landmark").."/amenities.lua")
|
2019-09-02 10:57:33 -04:00
|
|
|
dofile(minetest.get_modpath("maggems_landmark").."/nodes.lua")
|