init.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. nethervine = nethervine or {}
  2. nethervine.modpath = minetest.get_modpath("nethervine")
  3. dofile(nethervine.modpath .. "/functions.lua")
  4. nethervine.vine_on_construct = function(pos)
  5. local timer = minetest.get_node_timer(pos)
  6. timer:start(math.random(60*3, 60*6))
  7. end
  8. nethervine.vine_on_timer = function(pos, elapsed)
  9. return nethervine.grow(pos, minetest.get_node(pos))
  10. end
  11. nethervine.grow = function(pos, node)
  12. local timer = minetest.get_node_timer(pos)
  13. pos.y = pos.y + 1
  14. local name = minetest.get_node(pos).name
  15. if name ~= "rackstone:dauthsand_stable" and name ~= "rackstone:nether_grit" then
  16. return
  17. end
  18. local have_heat = false
  19. if minetest.find_node_near(pos, 4, "group:flame") or
  20. minetest.find_node_near(pos, 5, "group:lava") then
  21. have_heat = true
  22. end
  23. if not have_heat then
  24. return
  25. end
  26. local have_minerals = false
  27. if minetest.find_node_near(pos, 4, "glowstone:minerals") then
  28. have_minerals = true
  29. end
  30. pos.y = pos.y - 1
  31. local height = 0
  32. while node.name == "nethervine:vine" and height < 4 do
  33. height = height - 1
  34. pos.y = pos.y - 1
  35. node = minetest.get_node(pos)
  36. end
  37. if height == 4 or node.name ~= "air" then
  38. return
  39. end
  40. minetest.add_node(pos, {name = "nethervine:vine"})
  41. if have_minerals then
  42. timer:start(math.random(60*1, 60*2))
  43. else
  44. timer:start(math.random(60*3, 60*6))
  45. end
  46. end
  47. function nethervine.on_grass_timer(pos, elapsed)
  48. -- Dry out nethergrass if too near lava.
  49. if minetest.find_node_near(pos, 3, "group:lava") then
  50. minetest.swap_node(pos, {name="nether:grass_dried"})
  51. return false
  52. end
  53. return nethervine.on_flora_timer(pos, elapsed)
  54. end
  55. local eat_function = minetest.item_eat(0)
  56. function nethervine.eat_dried_grass(itemstack, user, pt)
  57. if not user or not user:is_player() then return end
  58. if user:get_hp() == 0 then return end
  59. user:set_hp(user:get_hp() + 4)
  60. return eat_function(itemstack, user, pt)
  61. end
  62. function nethervine.eat_grass(itemstack, user, pt)
  63. if not user or not user:is_player() then return end
  64. local pname = user:get_player_name()
  65. local msg = "# Server: <" .. rename.gpn(pname) .. "> ate forbidden grass. Desperate!"
  66. hb4.delayed_harm({name=pname, step=2, min=1, max=3, msg=msg, poison=true})
  67. return eat_function(itemstack, user, pt)
  68. end
  69. if not nethervine.registered then
  70. minetest.register_node("nethervine:vine", {
  71. description = "Wormroot",
  72. drawtype = "plantlike",
  73. tiles = {"nethervine_vine.png"},
  74. inventory_image = "nethervine_vine.png",
  75. wield_image = "nethervine_vine.png",
  76. paramtype = "light",
  77. sunlight_propagates = true,
  78. walkable = false,
  79. selection_box = {
  80. type = "fixed",
  81. fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
  82. },
  83. climbable = true,
  84. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  85. drop = "",
  86. shears_drop = true,
  87. flowerpot_drop = "nethervine:vine",
  88. -- Nethervines shall not be flammable. They often generate next to lava.
  89. groups = utility.dig_groups("plant", {
  90. hanging_node = 1,
  91. }),
  92. sounds = default.node_sound_leaves_defaults(),
  93. on_construct = function(...)
  94. return nethervine.vine_on_construct(...)
  95. end,
  96. on_timer = function(...)
  97. return nethervine.vine_on_timer(...)
  98. end,
  99. })
  100. for i = 1, 3 do
  101. minetest.register_node(":nether:grass_" .. i, {
  102. description = "Nether Grass",
  103. drawtype = "plantlike",
  104. waving = 1,
  105. tiles = {"nethergrass_" .. i .. ".png"},
  106. inventory_image = "nethergrass_3.png",
  107. wield_image = "nethergrass_3.png",
  108. paramtype = "light",
  109. paramtype2 = "meshoptions",
  110. place_param2 = 2,
  111. sunlight_propagates = true,
  112. walkable = false,
  113. buildable_to = true,
  114. drop = "nether:grass",
  115. flowerpot_drop = "nether:grass",
  116. groups = utility.dig_groups("plant", {netherflora = 1, attached_node = 1, not_in_creative_inventory = 1, grass = 1, flammable = 1}),
  117. sounds = default.node_sound_leaves_defaults(),
  118. selection_box = {
  119. type = "fixed",
  120. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
  121. },
  122. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  123. on_construct = function(...)
  124. return nethervine.on_flora_construct(...)
  125. end,
  126. on_destruct = function(...)
  127. return nethervine.on_flora_destruct(...)
  128. end,
  129. on_timer = function(...)
  130. -- Call custom function which adds the conversion to dried grass.
  131. return nethervine.on_grass_timer(...)
  132. end,
  133. on_punch = function(...)
  134. return nethervine.on_flora_punch(...)
  135. end,
  136. })
  137. end
  138. -- This node is not meant to be placed in the world.
  139. -- Instead, placing it causes 1 of several other nodetypes to be placed instead.
  140. minetest.register_node(":nether:grass", {
  141. description = "Forbidden Grass",
  142. drawtype = "plantlike",
  143. waving = 1,
  144. tiles = {"nethergrass_3.png"},
  145. -- Use texture of a taller grass stage in inventory
  146. inventory_image = "nethergrass_3.png",
  147. wield_image = "nethergrass_3.png",
  148. paramtype = "light",
  149. paramtype2 = "meshoptions",
  150. place_param2 = 2,
  151. sounds = default.node_sound_leaves_defaults(),
  152. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  153. flowerpot_insert = {"nether:grass_1", "nether:grass_2", "nether:grass_3"},
  154. -- Zero-width selection box.
  155. selection_box = {
  156. type = "fixed",
  157. fixed = {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
  158. },
  159. on_place = function(itemstack, placer, pt)
  160. -- place a random grass node
  161. local stack = ItemStack("nether:grass_" .. math.random(1,3))
  162. local ret = minetest.item_place(stack, placer, pt)
  163. return ItemStack("nether:grass " .. itemstack:get_count() - (1 - ret:get_count()))
  164. end,
  165. on_use = function(...)
  166. return nethervine.eat_grass(...)
  167. end,
  168. })
  169. -- Dried nethergrass has edible property!
  170. minetest.register_node(":nether:grass_dried", {
  171. description = "Saltified Forbidden Grass",
  172. drawtype = "plantlike",
  173. waving = 1,
  174. tiles = {"nethergrass_dried.png"},
  175. -- Use texture of a taller grass stage in inventory
  176. inventory_image = "nethergrass_dried.png",
  177. wield_image = "nethergrass_dried.png",
  178. paramtype = "light",
  179. paramtype2 = "meshoptions",
  180. place_param2 = 2,
  181. walkable = false,
  182. sounds = default.node_sound_leaves_defaults(),
  183. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  184. groups = utility.dig_groups("plant", {netherflora = 1, attached_node = 1, not_in_creative_inventory = 1, grass = 1, flammable = 3}),
  185. selection_box = {
  186. type = "fixed",
  187. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
  188. },
  189. on_use = function(...)
  190. return nethervine.eat_dried_grass(...)
  191. end,
  192. })
  193. -- This particular flower does not grow!
  194. minetest.register_node(":nether:glowflower", {
  195. description = "Nevermore Flower",
  196. drawtype = "plantlike",
  197. --waving = 1, -- Plant does not respond to wind.
  198. tiles = {"nether_glowflower.png"},
  199. inventory_image = "nether_glowflower.png",
  200. wield_image = "nether_glowflower.png",
  201. paramtype = "light",
  202. walkable = false,
  203. sounds = default.node_sound_leaves_defaults(),
  204. movement_speed_multiplier = default.SLOW_SPEED_PLANTS,
  205. groups = utility.dig_groups("plant", {attached_node = 1, not_in_creative_inventory = 1, flammable = 3}),
  206. light_source = 10,
  207. drop = "farming:cotton", -- Drop string.
  208. shears_drop = true, -- Drop self.
  209. flowerpot_drop = "nether:glowflower",
  210. selection_box = {
  211. type = "fixed",
  212. fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
  213. },
  214. })
  215. minetest.register_craft({
  216. type = "fuel",
  217. recipe = "nethervine:vine",
  218. burntime = 1,
  219. })
  220. local c = "nethervine:core"
  221. local f = nethervine.modpath .. "/init.lua"
  222. reload.register_file(c, f, false)
  223. nethervine.registered = true
  224. end