Generate dry shrubs on deserts
authorPerttu Ahola <celeron55@gmail.com>
Sat, 7 Apr 2012 21:09:42 +0000 (00:09 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sat, 7 Apr 2012 21:09:49 +0000 (00:09 +0300)
mods/default/init.lua
mods/default/mapgen.lua
mods/default/textures/default_dry_shrub.png [new file with mode: 0644]

index 53a365c8e549b607054aaa4f4ef877d2d74b2010..01e84fd3712a21e9356faa73c8e0cfe225306024 100644 (file)
@@ -1224,6 +1224,23 @@ minetest.register_node("default:apple", {
        sounds = default.node_sound_defaults(),
 })
 
+minetest.register_node("default:dry_shrub", {
+       description = "Dry Shrub",
+       drawtype = "plantlike",
+       visual_scale = 1.0,
+       tile_images = {"default_dry_shrub.png"},
+       inventory_image = "default_dry_shrub.png",
+       wield_image = "default_dry_shrub.png",
+       paramtype = "light",
+       walkable = false,
+       groups = {snappy=3},
+       sounds = default.node_sound_leaves_defaults(),
+       selection_box = {
+               type = "fixed",
+               fixed = {-1/3, -1/2, -1/3, 1/3, 1/6, 1/3},
+       },
+})
+
 --
 -- Crafting items
 --
index e7663f2a2db39e7e61a6d80cab497d21e779f272..16150d0f58f3b39cc2ed9284447e8cf73c29c1be 100644 (file)
@@ -183,6 +183,39 @@ minetest.register_on_generated(function(minp, maxp, seed)
                        end
                end
                end
+               -- Generate dry shrubs
+               local perlin1 = minetest.env:get_perlin(329, 3, 0.6, 100)
+               -- Assume X and Z lengths are equal
+               local divlen = 16
+               local divs = (maxp.x-minp.x)/divlen+1;
+               for divx=0,divs-1 do
+               for divz=0,divs-1 do
+                       local x0 = minp.x + math.floor((divx+0)*divlen)
+                       local z0 = minp.z + math.floor((divz+0)*divlen)
+                       local x1 = minp.x + math.floor((divx+1)*divlen)
+                       local z1 = minp.z + math.floor((divz+1)*divlen)
+                       -- Determine cactus amount from perlin noise
+                       local cactus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 5 + 2)
+                       -- Find random positions for cactus based on this random
+                       local pr = PseudoRandom(seed+1)
+                       for i=0,cactus_amount do
+                               local x = pr:next(x0, x1)
+                               local z = pr:next(z0, z1)
+                               -- Find ground level (0...15)
+                               local ground_y = nil
+                               for y=30,0,-1 do
+                                       if minetest.env:get_node({x=x,y=y,z=z}).name ~= "air" then
+                                               ground_y = y
+                                               break
+                                       end
+                               end
+                               -- If desert sand, make cactus
+                               if ground_y and minetest.env:get_node({x=x,y=ground_y,z=z}).name == "default:desert_sand" then
+                                       minetest.env:set_node({x=x,y=ground_y+1,z=z}, {name="default:dry_shrub"})
+                               end
+                       end
+               end
+               end
        end
 end)
 
diff --git a/mods/default/textures/default_dry_shrub.png b/mods/default/textures/default_dry_shrub.png
new file mode 100644 (file)
index 0000000..450d5d9
Binary files /dev/null and b/mods/default/textures/default_dry_shrub.png differ