maggems_landmark/init.lua

125 lines
4.1 KiB
Lua
Raw Normal View History

maggems_landmark = {}
local modstore = minetest.get_mod_storage()
function maggems_landmark.is_protected(pos, name)
local homes = maggems_landmark.homes
for _, area in pairs(homes:get_areas_for_pos(pos, true, true)) do
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
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)
local function save_homes()
local homes = maggems_landmark.homes
modstore:set_string("homes", minetest.encode_base64(homes:to_string()))
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", "")
-- TODO
--[[
2019-08-12 19:35:56 -04:00
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
--]]
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") .. ")")
meta:set_string("formspec", "size[11,5.5]real_coordinates[true]\
field[1,2.5;9,0.5;name;Home name;${maggems_landmark:name}]")
local homes = maggems_landmark.homes
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}
local id = homes:insert_area(pos1, pos2, minetest.serialize(pos))
assert(id ~= nil)
save_homes()
meta:set_int("maggems_landmark:home_id", id)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
local homes = maggems_landmark.homes
homes:remove_area(oldmetadata.fields["maggems_landmark:home_id"])
save_homes()
2019-08-12 19:35:56 -04:00
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
if (sender:get_player_name() ~= meta:get_string("owner")) or
(not fields.name) then return false end
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,
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'},
}
})