init.lua 7.5 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",
  53. wield_image = "fireflies_firefly.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. if not pointed_thing or pointed_thing.type ~= "node" or
  88. minetest.is_protected(pointed_thing.under, player:get_player_name()) then
  89. return
  90. end
  91. local node_name = minetest.get_node(pointed_thing.under).name
  92. local inv = player:get_inventory()
  93. if minetest.get_item_group(node_name, "catchable") == 1 then
  94. minetest.set_node(pointed_thing.under, {name = "air"})
  95. local stack = ItemStack(node_name.." 1")
  96. local leftover = inv:add_item("main", stack)
  97. if leftover:get_count() > 0 then
  98. minetest.add_item(pointed_thing.under, node_name.." 1")
  99. end
  100. end
  101. if not (creative and creative.is_enabled_for(player:get_player_name())) then
  102. itemstack:add_wear(256)
  103. return itemstack
  104. end
  105. end
  106. })
  107. minetest.register_craft( {
  108. output = "fireflies:bug_net",
  109. recipe = {
  110. {"farming:string", "farming:string"},
  111. {"farming:string", "farming:string"},
  112. {"group:stick", ""}
  113. }
  114. })
  115. -- firefly in a bottle
  116. minetest.register_node("fireflies:firefly_bottle", {
  117. description = S("Firefly in a Bottle"),
  118. inventory_image = "fireflies_bottle.png",
  119. wield_image = "fireflies_bottle.png",
  120. tiles = {{
  121. name = "fireflies_bottle_animated.png",
  122. animation = {
  123. type = "vertical_frames",
  124. aspect_w = 16,
  125. aspect_h = 16,
  126. length = 1.5
  127. },
  128. }},
  129. drawtype = "plantlike",
  130. paramtype = "light",
  131. sunlight_propagates = true,
  132. light_source = 9,
  133. walkable = false,
  134. groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
  135. selection_box = {
  136. type = "fixed",
  137. fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
  138. },
  139. sounds = default.node_sound_glass_defaults(),
  140. on_rightclick = function(pos, node, player, itemstack, pointed_thing)
  141. local lower_pos = {x = pos.x, y = pos.y + 1, z = pos.z}
  142. if minetest.is_protected(pos, player:get_player_name()) or
  143. minetest.get_node(lower_pos).name ~= "air" then
  144. return
  145. end
  146. local upper_pos = {x = pos.x, y = pos.y + 2, z = pos.z}
  147. local firefly_pos
  148. if not minetest.is_protected(upper_pos, player:get_player_name()) and
  149. minetest.get_node(upper_pos).name == "air" then
  150. firefly_pos = upper_pos
  151. elseif not minetest.is_protected(lower_pos, player:get_player_name()) then
  152. firefly_pos = lower_pos
  153. end
  154. if firefly_pos then
  155. minetest.set_node(pos, {name = "vessels:glass_bottle"})
  156. minetest.set_node(firefly_pos, {name = "fireflies:firefly"})
  157. minetest.get_node_timer(firefly_pos):start(1)
  158. end
  159. end
  160. })
  161. minetest.register_craft( {
  162. output = "fireflies:firefly_bottle",
  163. recipe = {
  164. {"fireflies:firefly"},
  165. {"vessels:glass_bottle"}
  166. }
  167. })
  168. -- register fireflies as decorations
  169. if minetest.get_mapgen_setting("mg_name") == "v6" then
  170. minetest.register_decoration({
  171. name = "fireflies:firefly_low",
  172. deco_type = "simple",
  173. place_on = "default:dirt_with_grass",
  174. place_offset_y = 2,
  175. sidelen = 80,
  176. fill_ratio = 0.0002,
  177. y_max = 31000,
  178. y_min = 1,
  179. decoration = "fireflies:hidden_firefly",
  180. })
  181. minetest.register_decoration({
  182. name = "fireflies:firefly_high",
  183. deco_type = "simple",
  184. place_on = "default:dirt_with_grass",
  185. place_offset_y = 3,
  186. sidelen = 80,
  187. fill_ratio = 0.0002,
  188. y_max = 31000,
  189. y_min = 1,
  190. decoration = "fireflies:hidden_firefly",
  191. })
  192. else
  193. minetest.register_decoration({
  194. name = "fireflies:firefly_low",
  195. deco_type = "simple",
  196. place_on = {
  197. "default:dirt_with_grass",
  198. "default:dirt_with_coniferous_litter",
  199. "default:dirt_with_rainforest_litter",
  200. "default:dirt"
  201. },
  202. place_offset_y = 2,
  203. sidelen = 80,
  204. fill_ratio = 0.0005,
  205. biomes = {
  206. "deciduous_forest",
  207. "coniferous_forest",
  208. "rainforest",
  209. "rainforest_swamp"
  210. },
  211. y_max = 31000,
  212. y_min = -1,
  213. decoration = "fireflies:hidden_firefly",
  214. })
  215. minetest.register_decoration({
  216. name = "fireflies:firefly_high",
  217. deco_type = "simple",
  218. place_on = {
  219. "default:dirt_with_grass",
  220. "default:dirt_with_coniferous_litter",
  221. "default:dirt_with_rainforest_litter",
  222. "default:dirt"
  223. },
  224. place_offset_y = 3,
  225. sidelen = 80,
  226. fill_ratio = 0.0005,
  227. biomes = {
  228. "deciduous_forest",
  229. "coniferous_forest",
  230. "rainforest",
  231. "rainforest_swamp"
  232. },
  233. y_max = 31000,
  234. y_min = -1,
  235. decoration = "fireflies:hidden_firefly",
  236. })
  237. end
  238. -- get decoration IDs
  239. local firefly_low = minetest.get_decoration_id("fireflies:firefly_low")
  240. local firefly_high = minetest.get_decoration_id("fireflies:firefly_high")
  241. minetest.set_gen_notify({decoration = true}, {firefly_low, firefly_high})
  242. -- start nodetimers
  243. minetest.register_on_generated(function(minp, maxp, blockseed)
  244. local gennotify = minetest.get_mapgen_object("gennotify")
  245. local poslist = {}
  246. for _, pos in ipairs(gennotify["decoration#"..firefly_low] or {}) do
  247. local firefly_low_pos = {x = pos.x, y = pos.y + 3, z = pos.z}
  248. table.insert(poslist, firefly_low_pos)
  249. end
  250. for _, pos in ipairs(gennotify["decoration#"..firefly_high] or {}) do
  251. local firefly_high_pos = {x = pos.x, y = pos.y + 4, z = pos.z}
  252. table.insert(poslist, firefly_high_pos)
  253. end
  254. if #poslist ~= 0 then
  255. for i = 1, #poslist do
  256. local pos = poslist[i]
  257. minetest.get_node_timer(pos):start(1)
  258. end
  259. end
  260. end)