2020-08-05 01:08:33 +02:00
|
|
|
local S = minetest.get_translator("inbox")
|
2017-01-29 22:41:03 +01:00
|
|
|
|
2014-07-19 01:45:26 +02:00
|
|
|
local inbox = {}
|
|
|
|
|
2015-03-31 00:51:48 +02:00
|
|
|
local mb_cbox = {
|
|
|
|
type = "fixed",
|
|
|
|
fixed = { -5/16, -8/16, -8/16, 5/16, 2/16, 8/16 }
|
|
|
|
}
|
|
|
|
|
2022-02-14 23:54:32 +01:00
|
|
|
homedecor.register("inbox", {
|
2015-01-20 23:59:50 +01:00
|
|
|
paramtype = "light",
|
2015-03-31 00:51:48 +02:00
|
|
|
drawtype = "mesh",
|
2022-02-14 23:54:32 +01:00
|
|
|
mesh = "homedecor_inbox_mailbox.obj",
|
2017-01-29 22:41:03 +01:00
|
|
|
description = S("Mailbox"),
|
2015-03-31 00:51:48 +02:00
|
|
|
tiles = {
|
2022-02-14 23:54:32 +01:00
|
|
|
"homedecor_inbox_red_metal.png",
|
|
|
|
"homedecor_inbox_white_metal.png",
|
|
|
|
"homedecor_inbox_grey_metal.png",
|
2015-03-31 00:51:48 +02:00
|
|
|
},
|
2022-02-14 23:54:32 +01:00
|
|
|
inventory_image = "homedecor_mailbox_inv.png",
|
2015-03-31 00:51:48 +02:00
|
|
|
selection_box = mb_cbox,
|
|
|
|
collision_box = mb_cbox,
|
2015-01-20 23:59:50 +01:00
|
|
|
paramtype2 = "facedir",
|
|
|
|
groups = {choppy=2,oddly_breakable_by_hand=2},
|
2022-04-11 06:03:37 +02:00
|
|
|
_sound_def = {
|
|
|
|
key = "node_sound_wood_defaults",
|
|
|
|
},
|
2020-08-05 01:08:33 +02:00
|
|
|
on_rotate = minetest.get_modpath("screwdriver") and screwdriver.rotate_simple or nil,
|
2015-01-20 23:59:50 +01:00
|
|
|
after_place_node = function(pos, placer, itemstack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local owner = placer:get_player_name()
|
|
|
|
meta:set_string("owner", owner)
|
2017-01-29 22:41:03 +01:00
|
|
|
meta:set_string("infotext", S("@1's Mailbox", owner))
|
2015-01-20 23:59:50 +01:00
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("main", 8*4)
|
|
|
|
inv:set_size("drop", 1)
|
|
|
|
end,
|
|
|
|
on_rightclick = function(pos, node, clicker, itemstack)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local player = clicker:get_player_name()
|
|
|
|
local owner = meta:get_string("owner")
|
2017-01-01 03:47:09 +01:00
|
|
|
if owner == player or
|
|
|
|
minetest.check_player_privs(player, "protection_bypass") and
|
|
|
|
clicker:get_player_control().aux1 then
|
2015-01-20 23:59:50 +01:00
|
|
|
minetest.show_formspec(
|
2017-02-27 21:31:21 +01:00
|
|
|
player,
|
2017-02-03 04:27:02 +01:00
|
|
|
"inbox:mailbox",
|
2015-01-20 23:59:50 +01:00
|
|
|
inbox.get_inbox_formspec(pos))
|
|
|
|
else
|
|
|
|
minetest.show_formspec(
|
2017-02-27 21:31:21 +01:00
|
|
|
player,
|
2017-02-03 04:27:02 +01:00
|
|
|
"inbox:mailbox",
|
2015-01-20 23:59:50 +01:00
|
|
|
inbox.get_inbox_insert_formspec(pos))
|
|
|
|
end
|
2016-07-31 01:17:23 +02:00
|
|
|
return itemstack
|
2015-01-20 23:59:50 +01:00
|
|
|
end,
|
|
|
|
can_dig = function(pos,player)
|
|
|
|
local meta = minetest.get_meta(pos);
|
2016-07-31 01:42:11 +02:00
|
|
|
local name = player and player:get_player_name()
|
2015-01-20 23:59:50 +01:00
|
|
|
local owner = meta:get_string("owner")
|
|
|
|
local inv = meta:get_inventory()
|
2016-08-27 21:11:16 +02:00
|
|
|
return name == owner and inv:is_empty("main")
|
2015-01-20 23:59:50 +01:00
|
|
|
end,
|
|
|
|
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if listname == "drop" and inv:room_for_item("main", stack) then
|
|
|
|
inv:remove_item("drop", stack)
|
|
|
|
inv:add_item("main", stack)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
|
|
|
if listname == "main" then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
if listname == "drop" then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
if inv:room_for_item("main", stack) then
|
|
|
|
return -1
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
2017-05-25 05:57:42 +02:00
|
|
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local owner = meta:get_string("owner")
|
|
|
|
if player:get_player_name() == owner or
|
|
|
|
minetest.check_player_privs(player, "protection_bypass") and
|
2020-08-05 01:08:33 +02:00
|
|
|
player:get_player_control().aux1 then
|
2017-05-25 05:57:42 +02:00
|
|
|
return stack:get_count()
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end,
|
|
|
|
allow_metadata_inventory_move = function(pos)
|
|
|
|
return 0
|
|
|
|
end,
|
2022-04-11 06:03:37 +02:00
|
|
|
crafts = {
|
|
|
|
{
|
|
|
|
recipe = {
|
|
|
|
{"","steel_ingot",""},
|
|
|
|
{"steel_ingot","","steel_ingot"},
|
|
|
|
{"steel_ingot","steel_ingot","steel_ingot"}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-19 01:45:26 +02:00
|
|
|
})
|
|
|
|
|
2022-02-14 23:54:32 +01:00
|
|
|
minetest.register_alias("inbox:empty", "homedecor:inbox")
|
|
|
|
|
2014-07-19 01:45:26 +02:00
|
|
|
function inbox.get_inbox_formspec(pos)
|
|
|
|
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
|
|
|
|
local formspec =
|
|
|
|
"size[8,9]"..
|
|
|
|
"list[nodemeta:".. spos .. ";main;0,0;8,4;]"..
|
2016-08-27 21:10:43 +02:00
|
|
|
"list[current_player;main;0,5;8,4;]" ..
|
|
|
|
"listring[]"
|
2014-07-19 01:45:26 +02:00
|
|
|
return formspec
|
|
|
|
end
|
|
|
|
|
|
|
|
function inbox.get_inbox_insert_formspec(pos)
|
|
|
|
local spos = pos.x .. "," .. pos.y .. "," ..pos.z
|
|
|
|
local formspec =
|
|
|
|
"size[8,9]"..
|
|
|
|
"list[nodemeta:".. spos .. ";drop;3.5,2;1,1;]"..
|
2016-08-27 21:10:43 +02:00
|
|
|
"list[current_player;main;0,5;8,4;]"..
|
|
|
|
"listring[]"
|
2014-07-19 01:45:26 +02:00
|
|
|
return formspec
|
|
|
|
end
|