init.lua 2.5 KB

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