2
0

init.lua 6.4 KB

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