X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=mailbox.lua;h=fafd724c9864654e74ffc2e65cf874358d0f941e;hb=f0d50395b99a9216bf20f5a5221116f8e2b6347f;hp=0a362573cc64e9d79adb6a56f4ae045ac18bd720;hpb=5722aca8585bcc65b9020ddd6c58111c369e52d7;p=xdecor.git diff --git a/mailbox.lua b/mailbox.lua index 0a36257..fafd724 100644 --- a/mailbox.lua +++ b/mailbox.lua @@ -1,4 +1,6 @@ local mailbox = {} +screwdriver = screwdriver or {} +local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots xdecor.register("mailbox", { description = "Mailbox", @@ -7,7 +9,8 @@ xdecor.register("mailbox", { "xdecor_mailbox_side.png", "xdecor_mailbox_side.png", "xdecor_mailbox.png", "xdecor_mailbox.png", }, - groups = {cracky=2}, + groups = {cracky=3, oddly_breakable_by_hand=1}, + on_rotate = screwdriver.rotate_simple, after_place_node = function(pos, placer, _) local meta = minetest.get_meta(pos) local owner = placer:get_player_name() @@ -25,9 +28,8 @@ xdecor.register("mailbox", { local owner = meta:get_string("owner") if owner == player then - minetest.show_formspec(player, "default:chest_locked", - mailbox.get_formspec(pos)) - else minetest.show_formspec(player, "default:chest_locked", + minetest.show_formspec(player, "", mailbox.get_formspec(pos)) + else minetest.show_formspec(player, "", mailbox.get_insert_formspec(pos, owner)) end end, @@ -36,45 +38,33 @@ xdecor.register("mailbox", { local owner = meta:get_string("owner") local inv = meta:get_inventory() - if not inv:is_empty("main") then return false end - return player:get_player_name() == owner + return inv:is_empty("main") and player and player:get_player_name() == owner end, on_metadata_inventory_put = function(pos, listname, _, stack, _) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - + local inv = minetest.get_meta(pos):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, _, stack, _) - 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 + if inv:room_for_item("main", stack) then return -1 end end + return 0 end }) function mailbox.get_formspec(pos) local spos = pos.x..","..pos.y..","..pos.z - local formspec = - "size[8,9]"..bg.. - "label[0,0;You received...]".. - "list[nodemeta:"..spos..";main;0,0.75;8,4;]".. - "list[current_player;main;0,5.25;8,4;]" - return formspec + return "size[8,9]"..xbg..default.get_hotbar_bg(0,5.25).. + "label[0,0;You received...]list[nodemeta:"..spos..";main;0,0.75;8,4;]list[current_player;main;0,5.25;8,4;]" end function mailbox.get_insert_formspec(pos, owner) local spos = pos.x..","..pos.y..","..pos.z - local formspec = - "size[8,5]"..bg.. - "label[0.5,0;Send your goods\nto "..owner.." :]".. - "list[nodemeta:"..spos..";drop;3.5,0;1,1;]".. - "list[current_player;main;0,1.25;8,4;]" - return formspec + return "size[8,5]"..xbg..default.get_hotbar_bg(0,1.25).. + "label[0.5,0;Send your goods\nto "..owner.." :]list[nodemeta:"..spos..";drop;3.5,0;1,1;]list[current_player;main;0,1.25;8,4;]" end