Redo.
This commit is contained in:
parent
66ae0e277a
commit
91bdedee09
|
@ -1,7 +1,9 @@
|
|||
# Moth
|
||||
|
||||
A simple mod for minetest which adds moths that can send messages (like in Lord of the Rings).
|
||||
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.
|
||||
|
||||
Unfortunatly, there isn't giant eagles to call for to save you from Isengard!
|
||||
|
||||
Fork of [Iarbat's mod](<https://content.minetest.net/packages/cool_beans/moth/>).
|
||||
|
|
61
init.lua
61
init.lua
|
@ -1,11 +1,23 @@
|
|||
|
||||
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!]"
|
||||
.. "field[1,1;8,1;target;Recipent: ;]"
|
||||
.. "textarea[1,3;8,5;message;Message: ;]"
|
||||
.. "button_exit[1,8;5,1;send;Fly Away...]"
|
||||
end
|
||||
|
||||
local function get_message_formspec(from, msg)
|
||||
return "size[10,10]"
|
||||
.. "label[0.5,0.5;A moth whispers to you...]"
|
||||
.. "label[0.5,1;(From "..core.formspec_escape(from)..")".."]"
|
||||
.. "textarea[0.5,2.5;7.5,7;;" ..core.formspec_escape(msg) .. ";]"
|
||||
end
|
||||
|
||||
local function get_error_formspec(msg)
|
||||
return "size[5,0.5]"
|
||||
.. "label[0,0;"..core.formspec_escape(msg).."]"
|
||||
end
|
||||
|
||||
core.register_node("moth:moth", {
|
||||
description = "Moth",
|
||||
inventory_image = "moth_img.png",
|
||||
|
@ -18,7 +30,7 @@ core.register_node("moth:moth", {
|
|||
name = "moth.png",
|
||||
animation = { type="vertical_frames", aspect_w=16, aspect_h=16, length=1 }
|
||||
}},
|
||||
groups = { oddly_breakable_by_hand=3 },
|
||||
groups = { oddly_breakable_by_hand=2 },
|
||||
|
||||
on_use = function(itemstack, player, pointed_thing)
|
||||
core.show_formspec(player:get_player_name(), "moth_send", get_moth_formspec())
|
||||
|
@ -26,25 +38,44 @@ core.register_node("moth:moth", {
|
|||
})
|
||||
|
||||
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 = core.get_player_by_name(fields.target)
|
||||
if rec then
|
||||
local pos = rec:get_pos()
|
||||
pos.y = pos.y + 1
|
||||
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
|
||||
if formname ~= "moth_send" then return end
|
||||
if not fields.send then return end
|
||||
local success = false
|
||||
|
||||
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_show", 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)
|
||||
core.set_node(player:get_pos(), { name="moth:moth" })
|
||||
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
|
||||
|
|
10
mod.conf
10
mod.conf
|
@ -1,3 +1,11 @@
|
|||
name = moth
|
||||
description = Adds moths which can send messages (from Lord of the Rings)
|
||||
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.
|
||||
|
|
Loading…
Reference in New Issue