diff --git a/LICENSE.txt b/LICENSE.txt index d239649..047b849 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,28 +1,28 @@ - -License for Code ----------------- - -The MIT License (MIT) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -License for Textures ---------------------------------------- - -All textures are licensed under CC-BY-SA 4.0 + +License for Code +---------------- + +The MIT License (MIT) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +License for Textures +--------------------------------------- + +All textures are licensed under CC-BY-SA 4.0 diff --git a/README.md b/README.md index 78f3325..4bb1843 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ -[![ContentDB](https://content.minetest.net/packages/cool_beans/moth/shields/downloads/)](https://content.minetest.net/packages/cool_beans/moth/) # Moth -

A simple mod for minetest which adds moths that can send messages (like in Lord of the Rings).

-

Use a white dandilion to summon a moth, and use a moth to send a message.

-

Unfortunatly, there isn't giant eagles to call for to save you from Isengard!

+ +A simple mod adding moths that send messages (like in Lord of the Rings). + +Use a white dandilion to summon a moth, and use a moth to send a message. + +Unfortunately, there isn't giant eagles to call for to save you from Isengard! diff --git a/init.lua b/init.lua index b46ffce..fcaf220 100644 --- a/init.lua +++ b/init.lua @@ -1,41 +1,89 @@ -local function get_moth_formspec() - return "size[10,10]".. - "field[1,1;8,1;target;Recipent: ;name]".. - "textarea[1,3;8,5;message;Message: ;Help me!]".. - "button_exit[1,8;5,1;send;Fly Away...]" -end -minetest.register_node("moth:moth", { - description = "Moth", - inventory_image = "moth_img.png", - wield_image = "moth_img.png", - paramtype = "light", - sunlight_propagates = true, - drawtype = "plantlike", - walkable = false, - tiles = {{ - name = "moth.png", - animation = {type = "vertical_frames", aspect_w = 16, aspect_h = 16, length = 1} - }}, - groups = {oddly_breakable_by_hand=3}, - on_use = function(itemstack, player, pointed_thing) - minetest.show_formspec(player:get_player_name(), "moth_send", get_moth_formspec()) - end -}) -minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname == "moth_send" then - if fields.send then - local inv = player:get_inventory() - inv:remove_item("main", "moth:moth") - local rec = minetest.get_player_by_name(fields.target) - if rec then - local pos = rec:get_pos() - pos.y = pos.y + 1 - minetest.set_node(pos, {name = "moth:moth"}) - minetest.show_formspec(rec:get_player_name(), "moth_show", "size[10,10]".."label[0.5,0.5;A moth whispers to you...]".."label[0.5,1;(From "..minetest.formspec_escape(player:get_player_name())..")".."]".."textarea[0.5,2.5;7.5,7;;" ..minetest.formspec_escape(fields.message) .. ";]") - end - end - end -end) -if minetest.get_modpath("flowers") then - minetest.override_item("flowers:dandelion_white", {on_use = function(itemstack, player, pointed_thing) minetest.set_node(player:get_pos(), {name = "moth:moth"}) end}) -end \ No newline at end of file + +local function get_send_formspec() + return "formspec_version[8] size[8,7.75]" + .. "field[0.5,0.75;7,1;target;Recipent: ;]" + .. "textarea[0.5,2.25;7,4;message;Message: ;]" + .. "button_exit[2,6.5;4,1;send;Fly Away...]" +end + +local function get_message_formspec(from, msg) + return "formspec_version[8] size[8,7.75]" + .. "label[0.5,0.5;A moth whispers to you...]" + .. "label[0.5,1;(from "..core.formspec_escape(from)..")".."]" + .. "textarea[1,1.5;6.5,5.75;;" ..core.formspec_escape(msg) .. ";]" +end + +local function get_error_formspec(msg) + return "formspec_version[8] size[8,1]" + .. "label[0.5,0.5;"..core.formspec_escape(msg).."]" +end + + +core.register_node("moth:moth", { + description = "Moth", + inventory_image = "moth_img.png", + wield_image = "moth_img.png", + paramtype = "light", + sunlight_propagates = true, + drawtype = "plantlike", + walkable = false, + tiles = {{ + name = "moth.png", + animation = { type="vertical_frames", aspect_w=16, aspect_h=16, length=1 } + }}, + groups = { oddly_breakable_by_hand=2 }, + + on_use = function(itemstack, player, pointed_thing) + core.show_formspec(player:get_player_name(), "moth_send", get_send_formspec()) + end, +}) + + +local form_handlers = {} + +core.register_on_player_receive_fields(function(player, formname, fields) + local h = form_handlers[formname] + if h then return h(player, formname, fields) end +end) + +function form_handlers.moth_send(player, formname, fields) + if not fields.send then return end + + local name = player:get_player_name() + local target = core.get_player_by_name(fields.target) + if not target then + core.show_formspec(name, "moth_error", get_error_formspec("The moth wasn't able to find "..fields.target)) + return + end + + local pos = target:get_pos():offset(0,1,0) + local node = core.get_node(pos) + if node == "air" or core.registered_nodes[node.name].buildable_to then + core.set_node(pos, { name="moth:moth" }) + else + local target_inv = target:get_inventory() + local rem = target_inv:add_item("main", "moth:moth") + if not rem:is_empty() then + core.show_formspec(name, "moth_error", get_error_formspec("The moth couldn't get to "..fields.target)) + return + end + end + + local player_inv = player:get_inventory() + player_inv:remove_item("main", "moth:moth") + + core.show_formspec(target:get_player_name(), "moth_message", get_message_formspec(name, fields.message)) +end + + +if core.get_modpath("flowers") then + core.override_item("flowers:dandelion_white", { + on_use = function(itemstack, player, pointed_thing) + local pos = player:get_pos():offset(0,1,0) + local node = core.get_node(pos) + if node == "air" or core.registered_nodes[node.name].buildable_to then + core.set_node(pos, { name="moth:moth" }) + end + end, + }) +end diff --git a/mod.conf b/mod.conf index b20649b..6f4fcd8 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,11 @@ -name = moth -description = Adds moths which can send messages (from Lord of the Rings) -optional_depends = flowers \ No newline at end of file +name = moth +min_minetest_version = +max_minetest_version = +depends = +optional_depends = flowers +supported_games = minetest_game +unsupported_games = + +title = Moth +author = Iarbat, GoodClover +description = Moths that send messages. diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..eef0948 Binary files /dev/null and b/screenshot.png differ diff --git a/screenshot_1.png b/screenshot_1.png deleted file mode 100644 index 20ae097..0000000 Binary files a/screenshot_1.png and /dev/null differ diff --git a/screenshot_2.png b/screenshot_2.png deleted file mode 100644 index 354d5f8..0000000 Binary files a/screenshot_2.png and /dev/null differ diff --git a/textures/moth.png b/textures/moth.png index 352602b..9f1bcd1 100644 Binary files a/textures/moth.png and b/textures/moth.png differ diff --git a/textures/moth_img.png b/textures/moth_img.png index d1a47ac..b77cd25 100644 Binary files a/textures/moth_img.png and b/textures/moth_img.png differ