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.master^2
parent
7410b78d4e
commit
d3510645ca
|
@ -0,0 +1,35 @@
|
|||
maggems_landmark.amenity_names = {}
|
||||
maggems_landmark.amenity_add = {}
|
||||
maggems_landmark.amenity_remove = {}
|
||||
|
||||
function maggems_landmark.register_amenity(name, func_add, func_remove)
|
||||
maggems_landmark.amenity_names[#maggems_landmark.amenity_names + 1] = name
|
||||
maggems_landmark.amenity_add[name] = func_add
|
||||
maggems_landmark.amenity_remove[name] = func_remove
|
||||
end
|
||||
|
||||
function maggems_landmark.find_amenities(area)
|
||||
local _, amenities = minetest.find_nodes_in_area(area.min, area.max, maggems_landmark.amenity_names)
|
||||
for amen, count in pairs(amenities) do
|
||||
if (count > 0) then
|
||||
amenities[amen] = nil
|
||||
end
|
||||
end
|
||||
return amenities
|
||||
end
|
||||
|
||||
function maggems_landmark.update_amenities(area)
|
||||
local pos = minetest.deserialize(area.data)
|
||||
if (minetest.get_node(pos).name ~= "maggems_landmark:home") then return false end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local had_amenities = minetest.deserialize(meta:get("maggems_landmark:amenities"))
|
||||
had_amenities = had_amenities or {}
|
||||
local found_amenities = maggems_landmark.find_amenities(area)
|
||||
for amen in pairs(found_amenities) do
|
||||
if (had_amenities[amen] == nil) then maggems_landmark.amenity_add[amen](meta) end
|
||||
end
|
||||
for amen in pairs(had_amenities) do
|
||||
if (found_amenities[amen] == nil) then maggems_landmark.amenity_remove[amen](meta) end
|
||||
end
|
||||
meta:set_string("maggems_landmark:amenities", minetest.serialize(found_amenities))
|
||||
end
|
Loading…
Reference in New Issue