From 478015c563f8ebdd9e4c7d8621b784028b5880ee Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Thu, 14 Jul 2016 10:43:23 -0400 Subject: Try add letterbox --- init.lua | 195 +++++++++++++++++++++------------- textures/mailbox_blank16.png | Bin 96 -> 0 bytes textures/mailbox_letterbox.png | Bin 0 -> 3009 bytes textures/mailbox_letterbox_bottom.png | Bin 0 -> 2858 bytes textures/mailbox_letterbox_side.png | Bin 0 -> 2978 bytes textures/mailbox_letterbox_top.png | Bin 0 -> 2860 bytes textures/mailbox_mailbox.png | Bin 0 -> 2887 bytes textures/mailbox_mailbox_bottom.png | Bin 0 -> 2811 bytes textures/mailbox_mailbox_side.png | Bin 0 -> 2868 bytes textures/mailbox_mailbox_top.png | Bin 0 -> 2811 bytes textures/xdecor_mailbox.png | Bin 2887 -> 0 bytes textures/xdecor_mailbox_bottom.png | Bin 2811 -> 0 bytes textures/xdecor_mailbox_side.png | Bin 2868 -> 0 bytes textures/xdecor_mailbox_top.png | Bin 2811 -> 0 bytes 14 files changed, 123 insertions(+), 72 deletions(-) delete mode 100644 textures/mailbox_blank16.png create mode 100644 textures/mailbox_letterbox.png create mode 100644 textures/mailbox_letterbox_bottom.png create mode 100644 textures/mailbox_letterbox_side.png create mode 100644 textures/mailbox_letterbox_top.png create mode 100644 textures/mailbox_mailbox.png create mode 100644 textures/mailbox_mailbox_bottom.png create mode 100644 textures/mailbox_mailbox_side.png create mode 100644 textures/mailbox_mailbox_top.png delete mode 100644 textures/xdecor_mailbox.png delete mode 100644 textures/xdecor_mailbox_bottom.png delete mode 100644 textures/xdecor_mailbox_side.png delete mode 100644 textures/xdecor_mailbox_top.png diff --git a/init.lua b/init.lua index 29b7171..42a7abd 100644 --- a/init.lua +++ b/init.lua @@ -5,88 +5,139 @@ local mailbox = {} screwdriver = screwdriver or {} -minetest.register_craft({ - output = "mailbox:mailbox", - recipe = { - {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, - {"dye:red", "default:paper", "dye:red"}, - {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"} - } -}) -minetest.register_node("mailbox:mailbox", { - description = "Mailbox", - tiles = { - "xdecor_mailbox_top.png", "xdecor_mailbox_bottom.png", - "xdecor_mailbox_side.png", "xdecor_mailbox_side.png", - "xdecor_mailbox.png", "xdecor_mailbox.png", - }, - groups = {cracky = 3, oddly_breakable_by_hand = 1}, - on_rotate = screwdriver.rotate_simple, - sounds = default.node_sound_defaults(), - paramtype2 = "facedir", - after_place_node = function(pos, placer, _) - local meta = minetest.get_meta(pos) - local player_name = placer:get_player_name() +function mailbox.get_formspec(pos, owner, fs_type) + local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots + local spos = pos.x .. "," ..pos.y .. "," .. pos.z - meta:set_string("owner", player_name) - meta:set_string("infotext", player_name.."'s Mailbox") + if fs_type == 1 then + return "size[8,9]" .. xbg .. default.get_hotbar_bg(0, 5.25) .. + "checkbox[0,0;books_only;Only allow written books;false]" .. + "list[nodemeta:" .. spos .. ";mailbox;0,0.75;8,4;]" .. + "list[current_player;main;0,5.25;8,4;]" .. + "listring[]" + else + 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;]" .. + "listring[]" + end +end - local inv = meta:get_inventory() - inv:set_size("mailbox", 8*4) - inv:set_size("drop", 1) - end, - on_rightclick = function(pos, _, clicker, _) - local meta = minetest.get_meta(pos) - local player = clicker:get_player_name() - local owner = meta:get_string("owner") +minetest.register_on_player_receive_fields(function(player, formname, fields) + if not formname:match("mailbox:mailbox_") then + return + end - if player == owner then - minetest.show_formspec(player, "", mailbox.get_formspec(pos, owner, 1)) + if fields.books_only then + local pos = minetest.string_to_pos(formname:sub(17)) + if minetest.get_node(pos).name == "mailbox:mailbox" then + minetest.swap_node(pos, + {name = "mailbox:letterbox"}) else - minetest.show_formspec(player, "", mailbox.get_formspec(pos, owner, 0)) + minetest.swap_node(pos, + {name = "mailbox:mailbox"}) end - end, - can_dig = function(pos, player) + end +end) + + +mailbox.after_place_node = function(pos, placer, _) + local meta = minetest.get_meta(pos) + local player_name = placer:get_player_name() + + meta:set_string("owner", player_name) + meta:set_string("infotext", player_name.."'s Mailbox") + + local inv = meta:get_inventory() + inv:set_size("mailbox", 8*4) + inv:set_size("drop", 1) +end + +mailbox.on_rightclick = function(pos, _, clicker, _) + local meta = minetest.get_meta(pos) + local player = clicker:get_player_name() + local owner = meta:get_string("owner") + + if player == owner then + local spos = pos.x .. "," .. pos.y .. "," .. pos.z + minetest.show_formspec(player, "mailbox:mailbox_" .. spos, mailbox.get_formspec(pos, owner, 1)) + else + minetest.show_formspec(player, "mailbox:mailbox", mailbox.get_formspec(pos, owner, 0)) + end +end + +mailbox.can_dig = function(pos, player) + local meta = minetest.get_meta(pos) + local owner = meta:get_string("owner") + local player_name = player:get_player_name() + local inv = meta:get_inventory() + + return inv:is_empty("mailbox") and player and player_name == owner +end + +mailbox.on_metadata_inventory_put = function(pos, listname, _, stack, _) + local inv = minetest.get_meta(pos):get_inventory() + if listname == "drop" and inv:room_for_item("mailbox", stack) then + inv:remove_item("drop", stack) + inv:add_item("mailbox", stack) + end +end + +mailbox.allow_metadata_inventory_put = function(pos, listname, _, stack, _) + if listname == "drop" then local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - local player_name = player:get_player_name() local inv = meta:get_inventory() - - return inv:is_empty("mailbox") and player and player_name == owner - end, - on_metadata_inventory_put = function(pos, listname, _, stack, _) - local inv = minetest.get_meta(pos):get_inventory() - if listname == "drop" and inv:room_for_item("mailbox", stack) then - inv:remove_item("drop", stack) - inv:add_item("mailbox", stack) - end - end, - allow_metadata_inventory_put = function(pos, listname, _, stack, _) - if listname == "drop" then - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - if inv:room_for_item("mailbox", stack) then return -1 end + if inv:room_for_item("mailbox", stack) then + return -1 end - return 0 end + return 0 +end + + +minetest.register_node("mailbox:mailbox", { + description = "Mailbox", + tiles = { + "mailbox_mailbox_top.png", "mailbox_mailbox_bottom.png", + "mailbox_mailbox_side.png", "mailbox_mailbox_side.png", + "mailbox_mailbox.png", "mailbox_mailbox.png", + }, + groups = {cracky = 3, oddly_breakable_by_hand = 1}, + on_rotate = screwdriver.rotate_simple, + sounds = default.node_sound_defaults(), + paramtype2 = "facedir", + after_place_node = mailbox.after_place_node, + on_rightclick = mailbox.on_rightclick, + can_dig = mailbox.can_dig, + on_metadata_inventory_put = mailbox.on_metadata_inventory_put, + allow_metadata_inventory_put = mailbox.allow_metadata_inventory_put, }) -function mailbox.get_formspec(pos, owner, fs_type) - local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots - local spos = pos.x..","..pos.y..","..pos.z +minetest.register_node("mailbox:letterbox", { + description = "Mailbox", + tiles = { + "mailbox_letterbox_top.png", "mailbox_letterbox_bottom.png", + "mailbox_letterbox_side.png", "mailbox_letterbox_side.png", + "mailbox_letterbox.png", "mailbox_letterbox.png", + }, + groups = {cracky = 3, oddly_breakable_by_hand = 1}, + on_rotate = screwdriver.rotate_simple, + sounds = default.node_sound_defaults(), + paramtype2 = "facedir", + after_place_node = mailbox.after_place_node, + on_rightclick = mailbox.on_rightclick, + can_dig = mailbox.can_dig, + on_metadata_inventory_put = mailbox.on_metadata_inventory_put, + allow_metadata_inventory_put = mailbox.allow_metadata_inventory_put, +}) - if fs_type == 1 then - return "size[8,9]"..xbg..default.get_hotbar_bg(0,5.25).. - "label[0,0;You received...]" .. - "list[nodemeta:"..spos..";mailbox;0,0.75;8,4;]" .. - "list[current_player;main;0,5.25;8,4;]" .. - "listring[]" - else - 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;]" .. - "listring[]" - end -end +minetest.register_craft({ + output = "mailbox:mailbox", + recipe = { + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, + {"default:book", "default:chest", "default:book"}, + {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"} + } +}) diff --git a/textures/mailbox_blank16.png b/textures/mailbox_blank16.png deleted file mode 100644 index 849e622..0000000 Binary files a/textures/mailbox_blank16.png and /dev/null differ diff --git a/textures/mailbox_letterbox.png b/textures/mailbox_letterbox.png new file mode 100644 index 0000000..f8fd568 Binary files /dev/null and b/textures/mailbox_letterbox.png differ diff --git a/textures/mailbox_letterbox_bottom.png b/textures/mailbox_letterbox_bottom.png new file mode 100644 index 0000000..ed7fb18 Binary files /dev/null and b/textures/mailbox_letterbox_bottom.png differ diff --git a/textures/mailbox_letterbox_side.png b/textures/mailbox_letterbox_side.png new file mode 100644 index 0000000..b93514d Binary files /dev/null and b/textures/mailbox_letterbox_side.png differ diff --git a/textures/mailbox_letterbox_top.png b/textures/mailbox_letterbox_top.png new file mode 100644 index 0000000..6904c4f Binary files /dev/null and b/textures/mailbox_letterbox_top.png differ diff --git a/textures/mailbox_mailbox.png b/textures/mailbox_mailbox.png new file mode 100644 index 0000000..f94cc36 Binary files /dev/null and b/textures/mailbox_mailbox.png differ diff --git a/textures/mailbox_mailbox_bottom.png b/textures/mailbox_mailbox_bottom.png new file mode 100644 index 0000000..7b879d9 Binary files /dev/null and b/textures/mailbox_mailbox_bottom.png differ diff --git a/textures/mailbox_mailbox_side.png b/textures/mailbox_mailbox_side.png new file mode 100644 index 0000000..61df62b Binary files /dev/null and b/textures/mailbox_mailbox_side.png differ diff --git a/textures/mailbox_mailbox_top.png b/textures/mailbox_mailbox_top.png new file mode 100644 index 0000000..2b54fb1 Binary files /dev/null and b/textures/mailbox_mailbox_top.png differ diff --git a/textures/xdecor_mailbox.png b/textures/xdecor_mailbox.png deleted file mode 100644 index f94cc36..0000000 Binary files a/textures/xdecor_mailbox.png and /dev/null differ diff --git a/textures/xdecor_mailbox_bottom.png b/textures/xdecor_mailbox_bottom.png deleted file mode 100644 index 7b879d9..0000000 Binary files a/textures/xdecor_mailbox_bottom.png and /dev/null differ diff --git a/textures/xdecor_mailbox_side.png b/textures/xdecor_mailbox_side.png deleted file mode 100644 index 61df62b..0000000 Binary files a/textures/xdecor_mailbox_side.png and /dev/null differ diff --git a/textures/xdecor_mailbox_top.png b/textures/xdecor_mailbox_top.png deleted file mode 100644 index 2b54fb1..0000000 Binary files a/textures/xdecor_mailbox_top.png and /dev/null differ -- cgit v1.2.3