init.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. -- Localize for performance.
  2. local math_floor = math.floor
  3. local math_min = math.min
  4. local math_max = math.max
  5. minetest.register_node("nyancat:nyancat", {
  6. description = "Nyan Cat",
  7. tiles = {"nyancat_side.png", "nyancat_side.png", "nyancat_side.png",
  8. "nyancat_side.png", "nyancat_back.png", "nyancat_front.png"},
  9. paramtype2 = "facedir",
  10. groups = utility.dig_groups("nyan"),
  11. is_ground_content = false,
  12. legacy_facedir_simple = true,
  13. light_source = 14,
  14. sounds = default.node_sound_defaults(),
  15. })
  16. minetest.register_node("nyancat:nyancat_rainbow", {
  17. description = "Nyan Cat Rainbow",
  18. tiles = {
  19. "nyancat_rainbow.png^[transformR90",
  20. "nyancat_rainbow.png^[transformR90",
  21. "nyancat_rainbow.png"
  22. },
  23. paramtype2 = "facedir",
  24. groups = utility.dig_groups("nyan"),
  25. is_ground_content = false,
  26. light_source = 14,
  27. sounds = default.node_sound_defaults(),
  28. })
  29. minetest.register_craft({
  30. type = "fuel",
  31. recipe = "nyancat:nyancat",
  32. burntime = 1,
  33. })
  34. minetest.register_craft({
  35. type = "fuel",
  36. recipe = "nyancat:nyancat_rainbow",
  37. burntime = 1,
  38. })
  39. nyancat = {}
  40. function nyancat.place(pos, facedir, length)
  41. if facedir > 3 then
  42. facedir = 0
  43. end
  44. local tailvec = minetest.facedir_to_dir(facedir)
  45. local p = {x = pos.x, y = pos.y, z = pos.z}
  46. minetest.set_node(p, {name = "nyancat:nyancat", param2 = facedir})
  47. for i = 1, length do
  48. p.x = p.x + tailvec.x
  49. p.z = p.z + tailvec.z
  50. minetest.set_node(p, {name = "nyancat:nyancat_rainbow", param2 = facedir})
  51. end
  52. end
  53. function nyancat.generate(minp, maxp, seed)
  54. local height_min = -25000 -- Don't generate nyan cats in the nether.
  55. local height_max = -32
  56. if maxp.y < height_min or minp.y > height_max then
  57. return
  58. end
  59. local y_min = math_max(minp.y, height_min)
  60. local y_max = math_min(maxp.y, height_max)
  61. local volume = (maxp.x - minp.x + 1) * (y_max - y_min + 1) * (maxp.z - minp.z + 1)
  62. local pr = PseudoRandom(seed + 9324342)
  63. local max_num_nyancats = math_floor(volume / (16 * 16 * 16))
  64. for i = 1, max_num_nyancats do
  65. if pr:next(0, 1000) == 0 then
  66. local x0 = pr:next(minp.x, maxp.x)
  67. local y0 = pr:next(minp.y, maxp.y)
  68. local z0 = pr:next(minp.z, maxp.z)
  69. local p0 = {x = x0, y = y0, z = z0}
  70. nyancat.place(p0, pr:next(0, 3), pr:next(3, 15))
  71. end
  72. end
  73. end
  74. minetest.register_on_generated(function(minp, maxp, seed)
  75. nyancat.generate(minp, maxp, seed)
  76. end)
  77. -- Legacy
  78. minetest.register_alias("default:nyancat", "nyancat:nyancat")
  79. minetest.register_alias("default:nyancat_rainbow", "nyancat:nyancat_rainbow")
  80. minetest.register_alias("nyancat", "nyancat:nyancat")
  81. minetest.register_alias("nyancat_rainbow", "nyancat:nyancat_rainbow")
  82. default.make_nyancat = nyancat.place
  83. default.generate_nyancats = nyancat.generate