init.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. -- firefly/init.lua
  2. -- Load support for MT game translation.
  3. local S = minetest.get_translator("fireflies")
  4. minetest.register_node("fireflies:firefly", {
  5. description = S("Firefly"),
  6. drawtype = "plantlike",
  7. tiles = {{
  8. name = "fireflies_firefly_animated.png",
  9. animation = {
  10. type = "vertical_frames",
  11. aspect_w = 16,
  12. aspect_h = 16,
  13. length = 1.5
  14. },
  15. }},
  16. inventory_image = "fireflies_firefly.png",
  17. wield_image = "fireflies_firefly.png",
  18. waving = 1,
  19. paramtype = "light",
  20. sunlight_propagates = true,
  21. buildable_to = true,
  22. walkable = false,
  23. groups = {catchable = 1},
  24. selection_box = {
  25. type = "fixed",
  26. fixed = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1},
  27. },
  28. light_source = 6,
  29. floodable = true,
  30. on_place = function(itemstack, placer, pointed_thing)
  31. local player_name = placer:get_player_name()
  32. local pos = pointed_thing.above
  33. if not minetest.is_protected(pos, player_name) and
  34. not minetest.is_protected(pointed_thing.under, player_name) and
  35. minetest.get_node(pos).name == "air" then
  36. minetest.set_node(pos, {name = "fireflies:firefly"})
  37. minetest.get_node_timer(pos):start(1)
  38. itemstack:take_item()
  39. end
  40. return itemstack
  41. end,
  42. on_timer = function(pos, elapsed)
  43. if minetest.get_node_light(pos) > 11 then
  44. minetest.set_node(pos, {name = "fireflies:hidden_firefly"})
  45. end
  46. minetest.get_node_timer(pos):start(30)
  47. end
  48. })
  49. minetest.register_node("fireflies:hidden_firefly", {
  50. description = S("Hidden Firefly"),
  51. drawtype = "airlike",
  52. inventory_image = "fireflies_firefly.png^default_invisible_node_overlay.png",
  53. wield_image = "fireflies_firefly.png^default_invisible_node_overlay.png",
  54. paramtype = "light",
  55. sunlight_propagates = true,
  56. walkable = false,
  57. pointable = false,
  58. diggable = false,
  59. buildable_to = true,
  60. drop = "",
  61. groups = {not_in_creative_inventory = 1},
  62. floodable = true,
  63. on_place = function(itemstack, placer, pointed_thing)
  64. local player_name = placer:get_player_name()
  65. local pos = pointed_thing.above
  66. if not minetest.is_protected(pos, player_name) and
  67. not minetest.is_protected(pointed_thing.under, player_name) and
  68. minetest.get_node(pos).name == "air" then
  69. minetest.set_node(pos, {name = "fireflies:hidden_firefly"})
  70. minetest.get_node_timer(pos):start(1)
  71. itemstack:take_item()
  72. end
  73. return itemstack
  74. end,
  75. on_timer = function(pos, elapsed)
  76. if minetest.get_node_light(pos) <= 11 then
  77. minetest.set_node(pos, {name = "fireflies:firefly"})
  78. end
  79. minetest.get_node_timer(pos):start(30)
  80. end
  81. })
  82. -- bug net
  83. minetest.register_tool("fireflies:bug_net", {
  84. description = S("Bug Net"),
  85. inventory_image = "fireflies_bugnet.png",
  86. on_use = function(itemstack, player, pointed_thing)
  87. local player_name = player and player:get_player_name() or ""
  88. if not pointed_thing or pointed_thing.type ~= "node" or
  89. minetest.is_protected(pointed_thing.under, player_name) then
  90. return
  91. end
  92. local node_name = minetest.get_node(pointed_thing.under).name
  93. local inv = player:get_inventory()
  94. if minetest.get_item_group(node_name, "catchable") == 1 then
  95. minetest.set_node(pointed_thing.under, {name = "air"})
  96. local stack = ItemStack(node_name.." 1")
  97. local leftover = inv:add_item("main", stack)
  98. if leftover:get_count() > 0 then
  99. minetest.add_item(pointed_thing.under, node_name.." 1")
  100. end
  101. end
  102. if not minetest.is_creative_enabled(player_name) then
  103. itemstack:add_wear_by_uses(256)
  104. return itemstack
  105. end
  106. end
  107. })
  108. minetest.register_craft( {
  109. output = "fireflies:bug_net",
  110. recipe = {
  111. {"farming:string", "farming:string"},
  112. {"farming:string", "farming:string"},
  113. {"group:stick", ""}
  114. }
  115. })
  116. -- firefly in a bottle
  117. minetest.register_node("fireflies:firefly_bottle", {
  118. description = S("Firefly in a Bottle"),
  119. inventory_image = "fireflies_bottle.png",
  120. wield_image = "fireflies_bottle.png",
  121. tiles = {{
  122. name = "fireflies_bottle_animated.png",
  123. animation = {
  124. type = "vertical_frames",
  125. aspect_w = 16,
  126. aspect_h = 16,
  127. length = 1.5
  128. },
  129. }},
  130. drawtype = "plantlike",
  131. paramtype = "light",
  132. sunlight_propagates = true,
  133. light_source = 9,
  134. walkable = false,
  135. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  136. selection_box = {
  137. type = "fixed",
  138. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  139. },
  140. sounds = default.node_sound_glass_defaults(),
  141. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  142. local lower_pos = {x = pos.x, y = pos.y + 1, z = pos.z}
  143. if minetest.is_protected(pos, player:get_player_name()) or
  144. minetest.get_node(lower_pos).name ~= "air" then
  145. return
  146. end
  147. local upper_pos = {x = pos.x, y = pos.y + 2, z = pos.z}
  148. local firefly_pos
  149. if not minetest.is_protected(upper_pos, player:get_player_name()) and
  150. minetest.get_node(upper_pos).name == "air" then
  151. firefly_pos = upper_pos
  152. elseif not minetest.is_protected(lower_pos, player:get_player_name()) then
  153. firefly_pos = lower_pos
  154. end
  155. if firefly_pos then
  156. minetest.set_node(pos, {name = "vessels:glass_bottle"})
  157. minetest.set_node(firefly_pos, {name = "fireflies:firefly"})
  158. minetest.get_node_timer(firefly_pos):start(1)
  159. end
  160. end
  161. })
  162. minetest.register_craft( {
  163. output = "fireflies:firefly_bottle",
  164. recipe = {
  165. {"fireflies:firefly"},
  166. {"vessels:glass_bottle"}
  167. }
  168. })
  169. -- register fireflies as decorations
  170. if minetest.get_mapgen_setting("mg_name") == "v6" then
  171. minetest.register_decoration({
  172. name = "fireflies:firefly_low",
  173. deco_type = "simple",
  174. place_on = "default:dirt_with_grass",
  175. place_offset_y = 2,
  176. sidelen = 80,
  177. fill_ratio = 0.0002,
  178. y_max = 31000,
  179. y_min = 1,
  180. decoration = "fireflies:hidden_firefly",
  181. })
  182. minetest.register_decoration({
  183. name = "fireflies:firefly_high",
  184. deco_type = "simple",
  185. place_on = "default:dirt_with_grass",
  186. place_offset_y = 3,
  187. sidelen = 80,
  188. fill_ratio = 0.0002,
  189. y_max = 31000,
  190. y_min = 1,
  191. decoration = "fireflies:hidden_firefly",
  192. })
  193. else
  194. minetest.register_decoration({
  195. name = "fireflies:firefly_low",
  196. deco_type = "simple",
  197. place_on = {
  198. "default:dirt_with_grass",
  199. "default:dirt_with_coniferous_litter",
  200. "default:dirt_with_rainforest_litter",
  201. "default:dirt"
  202. },
  203. place_offset_y = 2,
  204. sidelen = 80,
  205. fill_ratio = 0.0005,
  206. biomes = {
  207. "deciduous_forest",
  208. "coniferous_forest",
  209. "rainforest",
  210. "rainforest_swamp"
  211. },
  212. y_max = 31000,
  213. y_min = -1,
  214. decoration = "fireflies:hidden_firefly",
  215. })
  216. minetest.register_decoration({
  217. name = "fireflies:firefly_high",
  218. deco_type = "simple",
  219. place_on = {
  220. "default:dirt_with_grass",
  221. "default:dirt_with_coniferous_litter",
  222. "default:dirt_with_rainforest_litter",
  223. "default:dirt"
  224. },
  225. place_offset_y = 3,
  226. sidelen = 80,
  227. fill_ratio = 0.0005,
  228. biomes = {
  229. "deciduous_forest",
  230. "coniferous_forest",
  231. "rainforest",
  232. "rainforest_swamp"
  233. },
  234. y_max = 31000,
  235. y_min = -1,
  236. decoration = "fireflies:hidden_firefly",
  237. })
  238. end
  239. -- get decoration IDs
  240. local firefly_low = minetest.get_decoration_id("fireflies:firefly_low")
  241. local firefly_high = minetest.get_decoration_id("fireflies:firefly_high")
  242. minetest.set_gen_notify({decoration = true}, {firefly_low, firefly_high})
  243. -- start nodetimers
  244. minetest.register_on_generated(function(minp, maxp, blockseed)
  245. local gennotify = minetest.get_mapgen_object("gennotify")
  246. local poslist = {}
  247. for _, pos in ipairs(gennotify["decoration#"..firefly_low] or {}) do
  248. local firefly_low_pos = {x = pos.x, y = pos.y + 3, z = pos.z}
  249. table.insert(poslist, firefly_low_pos)
  250. end
  251. for _, pos in ipairs(gennotify["decoration#"..firefly_high] or {}) do
  252. local firefly_high_pos = {x = pos.x, y = pos.y + 4, z = pos.z}
  253. table.insert(poslist, firefly_high_pos)
  254. end
  255. if #poslist ~= 0 then
  256. for i = 1, #poslist do
  257. local pos = poslist[i]
  258. minetest.get_node_timer(pos):start(1)
  259. end
  260. end
  261. end)