Bucket: Add optional 'force-renew' bool to registration
[oweals/minetest_game.git] / mods / nyancat / init.lua
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 = {cracky = 2},
7         is_ground_content = false,
8         legacy_facedir_simple = true,
9         sounds = default.node_sound_defaults(),
10 })
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 = {cracky = 2},
21         is_ground_content = false,
22         sounds = default.node_sound_defaults(),
23 })
24
25 minetest.register_craft({
26         type = "fuel",
27         recipe = "nyancat:nyancat",
28         burntime = 1,
29 })
30
31 minetest.register_craft({
32         type = "fuel",
33         recipe = "nyancat:nyancat_rainbow",
34         burntime = 1,
35 })
36
37 nyancat = {}
38
39 function nyancat.place(pos, facedir, length)
40         if facedir > 3 then
41                 facedir = 0
42         end
43         local tailvec = minetest.facedir_to_dir(facedir)
44         local p = {x = pos.x, y = pos.y, z = pos.z}
45         minetest.set_node(p, {name = "nyancat:nyancat", param2 = facedir})
46         for i = 1, length do
47                 p.x = p.x + tailvec.x
48                 p.z = p.z + tailvec.z
49                 minetest.set_node(p, {name = "nyancat:nyancat_rainbow", param2 = facedir})
50         end
51 end
52
53 function nyancat.generate(minp, maxp, seed)
54         local height_min = -31000
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
75 minetest.register_on_generated(function(minp, maxp, seed)
76         nyancat.generate(minp, maxp, seed)
77 end)
78
79 -- Legacy
80 minetest.register_alias("default:nyancat", "nyancat:nyancat")
81 minetest.register_alias("default:nyancat_rainbow", "nyancat:nyancat_rainbow")
82 minetest.register_alias("nyancat", "nyancat:nyancat")
83 minetest.register_alias("nyancat_rainbow", "nyancat:nyancat_rainbow")
84 default.make_nyancat = nyancat.place
85 default.generate_nyancats = nyancat.generate