Skip to content
This repository was archived by the owner on Jul 20, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[![ContentDB](https://content.minetest.net/packages/cool_beans/moth/shields/downloads/)](https://content.minetest.net/packages/cool_beans/moth/)
# Moth
<p> A simple mod for minetest which adds moths that can send messages (like in Lord of the Rings). </p>
<p> Use a white dandilion to summon a moth, and use a moth to send a message. </p>
<p> Unfortunatly, there isn't giant eagles to call for to save you from Isengard! </p>

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!
130 changes: 89 additions & 41 deletions init.lua
Original file line number Diff line number Diff line change
@@ -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

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
14 changes: 11 additions & 3 deletions mod.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
name = moth
description = Adds moths which can send messages (from Lord of the Rings)
optional_depends = flowers
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.
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed screenshot_1.png
Binary file not shown.
Binary file removed screenshot_2.png
Binary file not shown.
Binary file modified textures/moth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified textures/moth_img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.