init.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. -- butterflies/init.lua
  2. -- Load support for MT game translation.
  3. local S = minetest.get_translator("butterflies")
  4. -- Legacy compatibility, when pointabilities don't exist, pointable is set to true.
  5. local pointable_compat = not minetest.features.item_specific_pointabilities
  6. -- register butterflies
  7. local butter_list = {
  8. {"white", S("White Butterfly")},
  9. {"red", S("Red Butterfly")},
  10. {"violet", S("Violet Butterfly")}
  11. }
  12. for i in ipairs (butter_list) do
  13. local name = butter_list[i][1]
  14. local desc = butter_list[i][2]
  15. minetest.register_node("butterflies:butterfly_"..name, {
  16. description = desc,
  17. drawtype = "plantlike",
  18. tiles = {{
  19. name = "butterflies_butterfly_"..name.."_animated.png",
  20. animation = {
  21. type = "vertical_frames",
  22. aspect_w = 16,
  23. aspect_h = 16,
  24. length = 3
  25. },
  26. }},
  27. inventory_image = "butterflies_butterfly_"..name..".png",
  28. wield_image = "butterflies_butterfly_"..name..".png",
  29. waving = 1,
  30. paramtype = "light",
  31. sunlight_propagates = true,
  32. buildable_to = true,
  33. walkable = false,
  34. pointable = pointable_compat,
  35. groups = {catchable = 1},
  36. selection_box = {
  37. type = "fixed",
  38. fixed = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1},
  39. },
  40. floodable = true,
  41. on_construct = function(pos)
  42. minetest.get_node_timer(pos):start(1)
  43. end,
  44. on_timer = function(pos, elapsed)
  45. if minetest.get_node_light(pos) < 11 then
  46. minetest.set_node(pos, {name = "butterflies:hidden_butterfly_"..name})
  47. end
  48. minetest.get_node_timer(pos):start(30)
  49. end
  50. })
  51. minetest.register_node("butterflies:hidden_butterfly_"..name, {
  52. drawtype = "airlike",
  53. inventory_image = "butterflies_butterfly_"..name..".png^default_invisible_node_overlay.png",
  54. wield_image = "butterflies_butterfly_"..name..".png^default_invisible_node_overlay.png",
  55. paramtype = "light",
  56. sunlight_propagates = true,
  57. walkable = false,
  58. pointable = false,
  59. diggable = false,
  60. drop = "",
  61. groups = {not_in_creative_inventory = 1},
  62. floodable = true,
  63. on_construct = function(pos)
  64. minetest.get_node_timer(pos):start(1)
  65. end,
  66. on_timer = function(pos, elapsed)
  67. if minetest.get_node_light(pos) >= 11 then
  68. minetest.set_node(pos, {name = "butterflies:butterfly_"..name})
  69. end
  70. minetest.get_node_timer(pos):start(30)
  71. end
  72. })
  73. end
  74. -- register decoration
  75. minetest.register_decoration({
  76. name = "butterflies:butterfly",
  77. deco_type = "simple",
  78. place_on = {"default:dirt_with_grass"},
  79. place_offset_y = 2,
  80. sidelen = 80,
  81. fill_ratio = 0.005,
  82. biomes = {"grassland", "deciduous_forest"},
  83. y_max = 31000,
  84. y_min = 1,
  85. decoration = {
  86. "butterflies:butterfly_white",
  87. "butterflies:butterfly_red",
  88. "butterflies:butterfly_violet"
  89. },
  90. spawn_by = "group:flower",
  91. num_spawn_by = 1
  92. })
  93. -- get decoration ID
  94. local butterflies = minetest.get_decoration_id("butterflies:butterfly")
  95. minetest.set_gen_notify({decoration = true}, {butterflies})
  96. -- start nodetimers
  97. minetest.register_on_generated(function(minp, maxp, blockseed)
  98. local gennotify = minetest.get_mapgen_object("gennotify")
  99. local poslist = {}
  100. for _, pos in ipairs(gennotify["decoration#"..butterflies] or {}) do
  101. local deco_pos = {x = pos.x, y = pos.y + 3, z = pos.z}
  102. table.insert(poslist, deco_pos)
  103. end
  104. if #poslist ~= 0 then
  105. for i = 1, #poslist do
  106. local pos = poslist[i]
  107. minetest.get_node_timer(pos):start(1)
  108. end
  109. end
  110. end)