init.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. icicle_farming = icicle_farming or {}
  2. icicle_farming.modpath = minetest.get_modpath("icicle_farming")
  3. local function can_grow(pos)
  4. -- Can't grow in nether, too hot so everything just melts.
  5. if pos.y < -22000 then return false end
  6. -- Grow underground, temperature is above freezing but not too hot.
  7. if pos.y < -48 then return true end
  8. -- If above-ground or near surface, then generally too cold,
  9. -- unless there is a heat-source nearby or at daytime.
  10. local light = minetest.get_node_light(pos)
  11. if not light then return false end -- Can't get light level.
  12. -- Light level 10 is chosen to be above the amount of light produced
  13. -- by glowing icicles. This way, glowing icicles do not count as a
  14. -- heat source. Players must use torches or better.
  15. if light >= 10 then return true end -- Grow in warmer area.
  16. return false -- Cannot grow.
  17. end
  18. local function grow_icicle(pos, node)
  19. if not can_grow(pos) then return end
  20. -- We've already determined that there is water nearby.
  21. local pbelow = {x=pos.x, y=pos.y-1, z=pos.z}
  22. local nbelow = minetest.get_node(pbelow)
  23. if nbelow.name == "air" then -- Grow icicle down.
  24. if minetest.find_node_near(pos, 1, "glowstone:minerals") then
  25. minetest.add_node(pbelow, {name="cavestuff:icicle_down_glowing"})
  26. else
  27. minetest.add_node(pbelow, {name="cavestuff:icicle_down"})
  28. end
  29. else -- Cannot grow below, try growing up.
  30. local pabove = {x=pos.x, y=pos.y+1, z=pos.z}
  31. local nabove = minetest.get_node(pabove)
  32. if nabove.name == "air" then -- Grow icicle up.
  33. if minetest.find_node_near(pos, 1, "glowstone:minerals") then
  34. minetest.add_node(pabove, {name="cavestuff:icicle_up_glowing"})
  35. else
  36. minetest.add_node(pabove, {name="cavestuff:icicle_up"})
  37. end
  38. end
  39. end
  40. end
  41. minetest.register_abm({
  42. label = "Grow Icicles",
  43. nodenames = {"ice:thin_ice"},
  44. neighbors = {"group:water"},
  45. interval = 20 * default.ABM_TIMER_MULTIPLIER,
  46. chance = 50 * default.ABM_CHANCE_MULTIPLIER,
  47. catch_up = false,
  48. action = grow_icicle,
  49. })