maggems_landmark/init.lua
codefairy d3510645ca Add in basic groundwork for home amenities
Amenities are nodes that are placed within the home's area and offer
some kind of benefit to the area or the homeowner (while within the
area). An example would be one which expands the maximum area volume,
or one which provides healing while inside the home.
2019-09-02 14:12:16 -04:00

61 lines
2.5 KiB
Lua

maggems_landmark = {}
local modstore = minetest.get_mod_storage()
function maggems_landmark.is_protected(pos, name)
local homes = maggems_landmark.homes
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
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
end
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()
if (maggems_landmark.homes ~= nil) then return end
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)
end
end)
function maggems_landmark.save_homes()
local homes = maggems_landmark.homes
modstore:set_string("homes", minetest.encode_base64(homes:to_string()))
end
function maggems_landmark.update_formspec(pos)
local meta = minetest.get_meta(pos)
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
dofile(minetest.get_modpath("maggems_landmark").."/amenities.lua")
dofile(minetest.get_modpath("maggems_landmark").."/nodes.lua")