diff --git a/README.md b/README.md index 78f3325..d8919df 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ [![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 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! diff --git a/init.lua b/init.lua index 44c7353..4aa1f51 100644 --- a/init.lua +++ b/init.lua @@ -1,41 +1,50 @@ + 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...]" + 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 + +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=3 }, + + on_use = function(itemstack, player, pointed_thing) + core.show_formspec(player:get_player_name(), "moth_send", get_moth_formspec()) + end, }) -minetest.register_on_player_receive_fields(function(player, formname, fields) + +core.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) + local rec = core.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) .. ";]") + core.set_node(pos, { name="moth:moth" }) + core.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 "..core.formspec_escape(player:get_player_name())..")".."]".."textarea[0.5,2.5;7.5,7;;" ..core.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}) + +if core.get_modpath("flowers") then + core.override_item("flowers:dandelion_white", { + on_use = function(itemstack, player, pointed_thing) + core.set_node(player:get_pos(), { name="moth:moth" }) + end, + }) end