From e4103941757205add1c3f0f06f866fc715bfa239 Mon Sep 17 00:00:00 2001 From: archfan <33993466+archfan7411@users.noreply.github.com> Date: Tue, 8 Jan 2019 15:56:58 -0500 Subject: [PATCH] Add files --- init.lua | 111 +++++++++++++++++++++++++ textures/envelopes_envelope_blank.png | Bin 0 -> 561 bytes textures/envelopes_envelope_opened.png | Bin 0 -> 634 bytes textures/envelopes_envelope_sealed.png | Bin 0 -> 569 bytes 4 files changed, 111 insertions(+) create mode 100644 init.lua create mode 100644 textures/envelopes_envelope_blank.png create mode 100644 textures/envelopes_envelope_opened.png create mode 100644 textures/envelopes_envelope_sealed.png diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..ad7882f --- /dev/null +++ b/init.lua @@ -0,0 +1,111 @@ +minetest.register_craftitem("envelopes:envelope_blank", { + description = "Blank Envelope", + inventory_image = "envelopes_envelope_blank.png", + on_use = function(itemstack, user, pointed_thing) + minetest.show_formspec(user:get_player_name(), "envelopes:input", + "size[5.5,5.5]" .. + "field[2,0.5;3.5,1;addressee;Addressee;]" .. + "label[0,0;Write a letter]" .. + "textarea[0.5,1.5;5,3;text;Text;]" .. + "field[3,4.8;2.5,1;attn;Attn. (Optional);]" .. + "button_exit[0.25,4.5;2,1;exit;Seal]") + return itemstack + end +}) + +minetest.register_craftitem("envelopes:envelope_sealed", { + description = "Sealed Envelope", + inventory_image = "envelopes_envelope_sealed.png", + stack_max = 1, + groups = {not_in_creative_inventory = 1}, + on_use = function(itemstack, user, pointed_thing) + meta = itemstack:get_meta() + if user:get_player_name() == meta:get_string("receiver") then + open_env = ItemStack("envelopes:envelope_opened") + open_meta = open_env:get_meta() + open_meta:set_string("sender", meta:get_string("sender")) + open_meta:set_string("receiver", meta:get_string("receiver")) + open_meta:set_string("text", meta:get_string("text")) + local desc = ("Opened Envelope\nTo: " .. meta:get_string("receiver") .. "\nFrom: " .. meta:get_string("sender")) + open_meta:set_string("description", desc) + if meta:get_string("attn") ~= "" then + open_meta:set_string("attn", meta:get_string("attn")) + desc = desc .. "\nAttn: " .. meta:get_string("attn") + open_meta:set_string("description", desc) + end + return open_env + end + minetest.chat_send_player(user:get_player_name(), "The seal can only be opened by the addressee!") + return itemstack + end +}) + +minetest.register_craftitem("envelopes:envelope_opened", { + description = "Opened Envelope", + inventory_image = "envelopes_envelope_opened.png", + stack_max = 1, + groups = {not_in_creative_inventory = 1}, + on_use = function(itemstack, user, pointed_thing) + local meta = itemstack:get_meta() + local sender = meta:get_string("sender") + local receiver = meta:get_string("receiver") + local text = meta:get_string("text") + local attn = meta:get_string("attn") or "" + local form = + "size[5,5]" .. + "label[0,0;A letter from " .. sender .. " to " .. receiver + if attn ~= "" then + form = form .. "\nAttn: " .. attn + end + form = form .. "\n" .. text .. "]" .. "button_exit[0,4;2,1;exit;Close]" + minetest.show_formspec(user:get_player_name(), "envelope:display", form) + end +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "envelopes:input" or not minetest.is_player(player) then + return false + end + + if fields.addressee == "" or fields.addressee == nil or fields.text == "" or fields.text == nil then + minetest.chat_send_player(player:get_player_name(), "Please fill out all required fields.") + return true + end + + local inv = player:get_inventory() + local letter = ItemStack('envelopes:envelope_sealed') + local blank = ItemStack('envelopes:envelope_blank') + local meta = letter:get_meta() + + meta:set_string("sender", player:get_player_name()) + meta:set_string("receiver", fields.addressee) + meta:set_string("text", fields.text) + + local desc = ("Sealed Envelope\nTo: " .. fields.addressee .. "\nFrom: " .. player:get_player_name()) + meta:set_string("description", desc) + + if fields.attn ~= "" then + meta:set_string("attn", fields.attn) + desc = desc .. "\nAttn: " .. fields.attn + meta:set_string("description", desc) + end + + if inv:room_for_item("main", letter) and inv:contains_item("main", blank) then + inv:add_item("main", letter) + inv:remove_item("main", blank) + else + minetest.chat_send_player(player:get_player_name(), "Unable to create letter! Check your inventory space.") + end + + return true +end) + +minetest.register_craft({ + type = "shaped", + output = "envelopes:envelope_blank 1", + recipe = { + {"", "", ""}, + {"default:paper", "default:paper", "default:paper"}, + {"default:paper", "default:paper", "default:paper"} + } +}) \ No newline at end of file diff --git a/textures/envelopes_envelope_blank.png b/textures/envelopes_envelope_blank.png new file mode 100644 index 0000000000000000000000000000000000000000..f50902b6a5af13c5cf2f5495697784c1e3745270 GIT binary patch literal 561 zcmV-10?z%3P)e zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00EgvL_t(I%e9j~YrPH+cpsq^?JRRAa9?|d_Jd2r2@tn06^DutX3;}31Hhcsj3Rk z^S~H`EX#=F80B&qEu#bObRF{Dx{2!enx3?Ygl?)N+D^*Uy=8T|;j-EN4Y z2>bmWNs@puhD;`dAP8{1Ug3Ejs?{ni%c7@%Mx!BYw_6YqE|&{9=KuiLb#XeKkjv$8 zJRVW2)i9Y%=xGP7R!eXk2fptk2m;8mj3|l_MG?X<1m_%w!{Hl5_!_C-?~|r!2*VIb zlHl=pKv5K&&u3(_StyEv-EId>)1d3R@U&UOFlf14lIyzU`#!~SOpGxiBI2AA5z%ls zq^Ai!)a`buR4PG|Boqn-NRkB3InwDgMxzm$&8F}x000Jq0ja8rd_E6R6hTC=EDP;+ zTX^}kJDme zSad^gZEa<4bO1wgWnpw>WFU8GbZ8()Nlj2!fese{00H7jL_t(I%e9j+OCv!P$A4?i zWmgv>3lU5qX%<47wX^k0Sf(<~eu)(M66v%E$aYFPv9L2~MAI1Tth5-&8c3WCv+KJe zaqqnIj^mDdFwF3n`OUol{2%;dSf3>?E-s`}sW7^``;aehZ2{0|GytgA>(-Ya4_{qf z$-%(^y% zBuQwu+e^q^NUAkDO_#IQA78LoESOHGJU%{>Wf{g8Ha9m>N)biTH^}QdBxSnNU=85# z@X)%wy+uUOT9fBF0NrjEfGCPkN)hg@%1K`f-3kqkj*hJHc#Kkt$z+1(c|=iEK!8G% zRO{kPfAT@E*OMR!NRoss%XoWx!}on=vl-=b8Q=GLcz7TP0ve6Rr#>Q%V;K&I^7Qm1 zN-3Go=VFWz5s^I4MMUK6>`Z>?M1Yf%6RFq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