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-08-21 22:11:39 -04:00
|
|
|
for _, area in pairs(homes:get_areas_for_pos(pos, true, true)) do
|
2019-08-21 22:52:58 -04:00
|
|
|
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-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-21 22:11:39 -04:00
|
|
|
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)
|
2019-08-19 21:43:41 -04:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2019-08-22 14:18:09 -04:00
|
|
|
local function 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-08-12 19:35:56 -04:00
|
|
|
minetest.register_node("maggems_landmark:home", {
|
|
|
|
description = "Misi Home",
|
|
|
|
tiles = {"maggems_landmark_home_side.png"},
|
|
|
|
is_ground_content = false,
|
|
|
|
paramtype = "light",
|
|
|
|
light_source = 3,
|
|
|
|
groups = {cracky = 1, level = 1},
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("owner", "")
|
2019-08-19 21:43:41 -04:00
|
|
|
-- TODO
|
|
|
|
--[[
|
2019-08-12 19:35:56 -04:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("main", 8*4)
|
2019-08-19 21:43:41 -04:00
|
|
|
--]]
|
2019-08-12 19:35:56 -04:00
|
|
|
end,
|
|
|
|
after_place_node = function(pos, placer)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
meta:set_string("owner", placer:get_player_name() or "")
|
|
|
|
meta:set_string("maggems_landmark:name", "Home")
|
|
|
|
meta:set_string("infotext", meta:get_string("maggems_landmark:name") ..
|
|
|
|
" (" .. meta:get_string("owner") .. ")")
|
2019-08-12 20:58:47 -04:00
|
|
|
meta:set_string("formspec", "size[11,5.5]real_coordinates[true]\
|
|
|
|
field[1,2.5;9,0.5;name;Home name;${maggems_landmark:name}]")
|
2019-08-21 22:11:39 -04:00
|
|
|
local homes = maggems_landmark.homes
|
2019-08-20 21:05:21 -04:00
|
|
|
local pos1 = {x=pos.x-3,y=pos.y-3,z=pos.z-3}
|
|
|
|
local pos2 = {x=pos.x+4,y=pos.y+4,z=pos.z+4}
|
2019-08-21 22:52:58 -04:00
|
|
|
local id = homes:insert_area(pos1, pos2, minetest.serialize(pos))
|
2019-08-20 21:05:21 -04:00
|
|
|
assert(id ~= nil)
|
2019-08-22 14:18:09 -04:00
|
|
|
save_homes()
|
2019-08-20 21:05:21 -04:00
|
|
|
meta:set_int("maggems_landmark:home_id", id)
|
2019-08-19 21:43:41 -04:00
|
|
|
end,
|
|
|
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
2019-08-21 22:11:39 -04:00
|
|
|
local homes = maggems_landmark.homes
|
2019-08-19 21:43:41 -04:00
|
|
|
homes:remove_area(oldmetadata.fields["maggems_landmark:home_id"])
|
2019-08-22 14:18:09 -04:00
|
|
|
save_homes()
|
2019-08-12 19:35:56 -04:00
|
|
|
end,
|
2019-08-12 20:58:47 -04:00
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2019-08-13 21:44:52 -04:00
|
|
|
if (sender:get_player_name() ~= meta:get_string("owner")) or
|
2019-08-17 17:38:09 -04:00
|
|
|
(not fields.name) then return false end
|
2019-08-12 20:58:47 -04:00
|
|
|
meta:set_string("maggems_landmark:name", fields.name)
|
|
|
|
meta:set_string("infotext", meta:get_string("maggems_landmark:name") ..
|
|
|
|
" (" .. meta:get_string("owner") .. ")")
|
|
|
|
return true
|
2019-08-12 19:35:56 -04:00
|
|
|
end,
|
2019-08-12 20:58:47 -04:00
|
|
|
on_blast = function() end,
|
2019-08-12 19:35:56 -04:00
|
|
|
--[[
|
|
|
|
-- TODO: proper home features
|
|
|
|
can_dig = function(pos,player)
|
|
|
|
local meta = minetest.get_meta(pos);
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:is_empty("main") and
|
|
|
|
default.can_interact_with_node(player, pos)
|
|
|
|
end,
|
|
|
|
allow_metadata_inventory_move = function(pos, from_list, from_index,
|
|
|
|
to_list, to_index, count, player)
|
|
|
|
if not default.can_interact_with_node(player, pos) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
return count
|
|
|
|
end,
|
|
|
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
|
|
if not default.can_interact_with_node(player, pos) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
|
|
if not default.can_interact_with_node(player, pos) then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
--]]
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = 'maggems_landmark:home',
|
|
|
|
recipe = {
|
|
|
|
{'maggems:misi'},
|
|
|
|
{'default:mese_crystal_fragment'},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|