init.lua 7.6 KB

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