I did a new pine type

Could this be added to the default?

Yes
6
67%
No
3
33%
 
Total votes : 9

User avatar
LNJ
Member
 
Posts: 200
Joined: Tue Sep 23, 2014 16:02
GitHub: LNJ2
IRC: LNJ2GO
In-game: LNJ

I did a new pine type

by LNJ » Sun Jul 05, 2015 15:16

I did a new pine (I want both, the already existing and my new).
Here are some screenshots!
Image
Image
Image
Image
I edited the trees.lua (in the default)
That is the code (My part is at the end).
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Pinetree from mg mapgen mod, design by sfan5, pointy top added by paramat

local function add_pine_needles(data, vi, c_air, c_ignore, c_snow, c_pine_needles)
   if data[vi] == c_air or data[vi] == c_ignore or data[vi] == c_snow then
      data[vi] = c_pine_needles
   end
end

local function add_snow(data, vi, c_air, c_ignore, c_snow)
   if data[vi] == c_air or data[vi] == c_ignore then
      data[vi] = c_snow
   end
end

function default.grow_pine_tree(pos)
   local treetype = random(1, 3)
   
   if treetype <= 2 then
      default.grow_pine_tree_a(pos)
   else
      default.grow_pine_tree_b(pos)
   end
end
   
function default.grow_pine_tree_a(pos)
   local x, y, z = pos.x, pos.y, pos.z
   local maxy = y + random(9, 13) -- Trunk top

   local c_air = minetest.get_content_id("air")
   local c_ignore = minetest.get_content_id("ignore")
   local c_pinetree = minetest.get_content_id("default:pinetree")
   local c_pine_needles  = minetest.get_content_id("default:pine_needles")
   local c_snow = minetest.get_content_id("default:snow")
   local c_snowblock = minetest.get_content_id("default:snowblock")
   local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")

   local vm = minetest.get_voxel_manip()
   local minp, maxp = vm:read_from_map(
      {x = x - 3, y = y - 1, z = z - 3},
      {x = x + 3, y = maxy + 3, z = z + 3}
   )
   local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
   local data = vm:get_data()

   -- Scan for snow nodes near sapling
   local snow = false
   for yy = y - 1, y + 1 do
   for zz = z - 1, z + 1 do
      local vi  = a:index(x - 1, yy, zz)
      for xx = x - 1, x + 1 do
         local nodid = data[vi]
         if nodid == c_snow
         or nodid == c_snowblock
         or nodid == c_dirtsnow then
            snow = true
         end
         vi  = vi + 1
      end
   end
   end

   -- Upper branches layer
   local dev = 3
   for yy = maxy - 1, maxy + 1 do
      for zz = z - dev, z + dev do
         local vi = a:index(x - dev, yy, zz)
         local via = a:index(x - dev, yy + 1, zz)
         for xx = x - dev, x + dev do
            if random() < 0.95 - dev * 0.05 then
               add_pine_needles(data, vi, c_air, c_ignore, c_snow,
                     c_pine_needles)
               if snow then
                  add_snow(data, via, c_air, c_ignore, c_snow)
               end
            end
            vi  = vi + 1
            via = via + 1
         end
      end
      dev = dev - 1
   end

   -- Centre top nodes
   add_pine_needles(data, a:index(x, maxy + 1, z), c_air, c_ignore, c_snow,
         c_pine_needles)
   add_pine_needles(data, a:index(x, maxy + 2, z), c_air, c_ignore, c_snow,
         c_pine_needles) -- Paramat added a pointy top node
   if snow then
      add_snow(data, a:index(x, maxy + 3, z), c_air, c_ignore, c_snow)
   end

   -- Lower branches layer
   local my = 0
   for i = 1, 20 do -- Random 2x2 squares of needles
      local xi = x + random(-3, 2)
      local yy = maxy + random(-6, -5)
      local zi = z + random(-3, 2)
      if yy > my then
         my = yy
      end
      for zz = zi, zi+1 do
         local vi = a:index(xi, yy, zz)
         local via = a:index(xi, yy + 1, zz)
         for xx = xi, xi + 1 do
            add_pine_needles(data, vi, c_air, c_ignore, c_snow,
                  c_pine_needles)
            if snow then
               add_snow(data, via, c_air, c_ignore, c_snow)
            end
            vi  = vi + 1
            via = via + 1
         end
      end
   end

   local dev = 2
   for yy = my + 1, my + 2 do
      for zz = z - dev, z + dev do
         local vi = a:index(x - dev, yy, zz)
         local via = a:index(x - dev, yy + 1, zz)
         for xx = x - dev, x + dev do
            if random() < 0.95 - dev * 0.05 then
               add_pine_needles(data, vi, c_air, c_ignore, c_snow,
                     c_pine_needles)
               if snow then
                  add_snow(data, via, c_air, c_ignore, c_snow)
               end
            end
            vi  = vi + 1
            via = via + 1
         end
      end
      dev = dev - 1
   end

   -- Trunk
   for yy = y, maxy do
      local vi = a:index(x, yy, z)
      data[vi] = c_pinetree
   end

   vm:set_data(data)
   vm:write_to_map()
   vm:update_map()
end

function default.grow_pine_tree_b(pos)
   local x, y, z = pos.x, pos.y, pos.z
   local height = random(7, 13)
   local c_pinetree = minetest.get_content_id("default:pinetree")
   local c_pine_needles = minetest.get_content_id("default:pine_needles")
   local c_pine_sapling = minetest.get_content_id("default:pine_sapling")
   local c_snow = minetest.get_content_id("default:snow")
   local c_snowblock = minetest.get_content_id("default:snowblock")
   local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")
   local c_air = minetest.get_content_id("air")
   local c_ignore = minetest.get_content_id("ignore")

   local vm = minetest.get_voxel_manip()
   local minp, maxp = vm:read_from_map(
      {x = pos.x - 2, y = pos.y, z = pos.z - 2},
      {x = pos.x + 2, y = pos.y + height + 1, z = pos.z + 2}
   )
   local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
   local data = vm:get_data()
   
   -- Scan for snow nodes near sapling
   local snow = false
   for yy = y - 1, y + 1 do
   for zz = z - 1, z + 1 do
      local vi  = a:index(x - 1, yy, zz)
      for xx = x - 1, x + 1 do
         local nodid = data[vi]
         if nodid == c_snow
         or nodid == c_snowblock
         or nodid == c_dirtsnow then
            snow = true
         end
         vi  = vi + 1
      end
   end
   end
   
   -- Trunk
   for yy = y, y + height do
      local vi = a:index(x, yy, z)
      if data[vi] == c_air or data[vi] == c_pine_sapling or data[vi] == c_ignore then
         data[vi] = c_pinetree
      end
   end
   
   -- Add the basic needles
   add_pine_needles(data, a:index(x, y + height + 2, z), c_air, c_ignore, c_snow, c_pine_needles)
   
   add_pine_needles(data, a:index(x, y + height + 1, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x - 1, y + height + 1, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x + 1, y + height + 1, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x, y + height + 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x, y + height + 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
   
   add_pine_needles(data, a:index(x - 1, y + height, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x + 1, y + height, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x, y + height, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x, y + height, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
   
   -- Add the basic snow
   if snow then
      add_snow(data, a:index(x, y + height + 3, z), c_air, c_ignore, c_snow)
      
      add_snow(data, a:index(x - 1, y + height + 2, z), c_air, c_ignore, c_snow)
      add_snow(data, a:index(x + 1, y + height + 2, z), c_air, c_ignore, c_snow)
      add_snow(data, a:index(x, y + height + 2, z - 1), c_air, c_ignore, c_snow)
      add_snow(data, a:index(x, y + height + 2, z + 1), c_air, c_ignore, c_snow)
   end
   
   -- Add more needles
   add_pine_needles(data, a:index(x - 1, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x, y + height - 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x, y + height - 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x + 1, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
   
   if random(1, 2) == 1 then
      -- Add more needles
      add_pine_needles(data, a:index(x - 1, y + height, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x - 1, y + height, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 1, y + height, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 1, y + height, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      
      add_pine_needles(data, a:index(x - 2, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x - 1, y + height - 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x - 1, y + height - 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x, y + height - 1, z + 2), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x, y + height - 1, z - 2), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 1, y + height - 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 1, y + height - 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 2, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
      
      if random(1, 2) == 1 then
         add_pine_needles(data, a:index(x - 1, y + height - 2, z), c_air, c_ignore, c_snow, c_pine_needles)
      end
      if random(1, 2) == 1 then
         add_pine_needles(data, a:index(x, y + height - 2, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      end
      if random(1, 2) == 1 then
         add_pine_needles(data, a:index(x, y + height - 2, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      end
      if random(1, 2) == 1 then
         add_pine_needles(data, a:index(x + 1, y + height - 2, z), c_air, c_ignore, c_snow, c_pine_needles)
      end
      
      if snow then
         add_snow(data, a:index(x - 1, y + height + 1, z + 1), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x - 1, y + height + 1, z - 1), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x + 1, y + height + 1, z + 1), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x + 1, y + height + 1, z - 1), c_air, c_ignore, c_snow)
         
         add_snow(data, a:index(x - 2, y + height, z), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x, y + height, z - 2), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x, y + height, z + 2), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x + 2, y + height, z), c_air, c_ignore, c_snow)
      end
   end
   
   vm:set_data(data)
   vm:write_to_map()
   vm:update_map()
end


EDIT: IN THIS VERSION IS THE TREE MIN. 7 BLOCKS TALL AND MAX. 13
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
    -- Pinetree from mg mapgen mod, design by sfan5, pointy top added by paramat

    local function add_pine_needles(data, vi, c_air, c_ignore, c_snow, c_pine_needles)
       if data[vi] == c_air or data[vi] == c_ignore or data[vi] == c_snow then
          data[vi] = c_pine_needles
       end
    end

    local function add_snow(data, vi, c_air, c_ignore, c_snow)
       if data[vi] == c_air or data[vi] == c_ignore then
          data[vi] = c_snow
       end
    end

    function default.grow_pine_tree(pos)
       local treetype = random(1, 3)
       
       if treetype <= 2 then
          default.grow_pine_tree_a(pos)
       else
          default.grow_pine_tree_b(pos)
       end
    end
       
    function default.grow_pine_tree_a(pos)
       local x, y, z = pos.x, pos.y, pos.z
       local maxy = y + random(9, 13) -- Trunk top

       local c_air = minetest.get_content_id("air")
       local c_ignore = minetest.get_content_id("ignore")
       local c_pinetree = minetest.get_content_id("default:pinetree")
       local c_pine_needles  = minetest.get_content_id("default:pine_needles")
       local c_snow = minetest.get_content_id("default:snow")
       local c_snowblock = minetest.get_content_id("default:snowblock")
       local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")

       local vm = minetest.get_voxel_manip()
       local minp, maxp = vm:read_from_map(
          {x = x - 3, y = y - 1, z = z - 3},
          {x = x + 3, y = maxy + 3, z = z + 3}
       )
       local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
       local data = vm:get_data()

       -- Scan for snow nodes near sapling
       local snow = false
       for yy = y - 1, y + 1 do
       for zz = z - 1, z + 1 do
          local vi  = a:index(x - 1, yy, zz)
          for xx = x - 1, x + 1 do
             local nodid = data[vi]
             if nodid == c_snow
             or nodid == c_snowblock
             or nodid == c_dirtsnow then
                snow = true
             end
             vi  = vi + 1
          end
       end
       end

       -- Upper branches layer
       local dev = 3
       for yy = maxy - 1, maxy + 1 do
          for zz = z - dev, z + dev do
             local vi = a:index(x - dev, yy, zz)
             local via = a:index(x - dev, yy + 1, zz)
             for xx = x - dev, x + dev do
                if random() < 0.95 - dev * 0.05 then
                   add_pine_needles(data, vi, c_air, c_ignore, c_snow,
                         c_pine_needles)
                   if snow then
                      add_snow(data, via, c_air, c_ignore, c_snow)
                   end
                end
                vi  = vi + 1
                via = via + 1
             end
          end
          dev = dev - 1
       end

       -- Centre top nodes
       add_pine_needles(data, a:index(x, maxy + 1, z), c_air, c_ignore, c_snow,
             c_pine_needles)
       add_pine_needles(data, a:index(x, maxy + 2, z), c_air, c_ignore, c_snow,
             c_pine_needles) -- Paramat added a pointy top node
       if snow then
          add_snow(data, a:index(x, maxy + 3, z), c_air, c_ignore, c_snow)
       end

       -- Lower branches layer
       local my = 0
       for i = 1, 20 do -- Random 2x2 squares of needles
          local xi = x + random(-3, 2)
          local yy = maxy + random(-6, -5)
          local zi = z + random(-3, 2)
          if yy > my then
             my = yy
          end
          for zz = zi, zi+1 do
             local vi = a:index(xi, yy, zz)
             local via = a:index(xi, yy + 1, zz)
             for xx = xi, xi + 1 do
                add_pine_needles(data, vi, c_air, c_ignore, c_snow,
                      c_pine_needles)
                if snow then
                   add_snow(data, via, c_air, c_ignore, c_snow)
                end
                vi  = vi + 1
                via = via + 1
             end
          end
       end

       local dev = 2
       for yy = my + 1, my + 2 do
          for zz = z - dev, z + dev do
             local vi = a:index(x - dev, yy, zz)
             local via = a:index(x - dev, yy + 1, zz)
             for xx = x - dev, x + dev do
                if random() < 0.95 - dev * 0.05 then
                   add_pine_needles(data, vi, c_air, c_ignore, c_snow,
                         c_pine_needles)
                   if snow then
                      add_snow(data, via, c_air, c_ignore, c_snow)
                   end
                end
                vi  = vi + 1
                via = via + 1
             end
          end
          dev = dev - 1
       end

       -- Trunk
       for yy = y, maxy do
          local vi = a:index(x, yy, z)
          data[vi] = c_pinetree
       end

       vm:set_data(data)
       vm:write_to_map()
       vm:update_map()
    end

    function default.grow_pine_tree_b(pos)
       local x, y, z = pos.x, pos.y, pos.z
       local height = random(5, 13)
       local c_pinetree = minetest.get_content_id("default:pinetree")
       local c_pine_needles = minetest.get_content_id("default:pine_needles")
       local c_pine_sapling = minetest.get_content_id("default:pine_sapling")
       local c_snow = minetest.get_content_id("default:snow")
       local c_snowblock = minetest.get_content_id("default:snowblock")
       local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")
       local c_air = minetest.get_content_id("air")
       local c_ignore = minetest.get_content_id("ignore")

       local vm = minetest.get_voxel_manip()
       local minp, maxp = vm:read_from_map(
          {x = pos.x - 2, y = pos.y, z = pos.z - 2},
          {x = pos.x + 2, y = pos.y + height + 1, z = pos.z + 2}
       )
       local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
       local data = vm:get_data()
       
       -- Scan for snow nodes near sapling
       local snow = false
       for yy = y - 1, y + 1 do
       for zz = z - 1, z + 1 do
          local vi  = a:index(x - 1, yy, zz)
          for xx = x - 1, x + 1 do
             local nodid = data[vi]
             if nodid == c_snow
             or nodid == c_snowblock
             or nodid == c_dirtsnow then
                snow = true
             end
             vi  = vi + 1
          end
       end
       end
       
       -- Trunk
       for yy = y, y + height do
          local vi = a:index(x, yy, z)
          if data[vi] == c_air or data[vi] == c_pine_sapling or data[vi] == c_ignore then
             data[vi] = c_pinetree
          end
       end
       
       -- Add the basic needles
       add_pine_needles(data, a:index(x, y + height + 2, z), c_air, c_ignore, c_snow, c_pine_needles)
       
       add_pine_needles(data, a:index(x, y + height + 1, z), c_air, c_ignore, c_snow, c_pine_needles)
       add_pine_needles(data, a:index(x - 1, y + height + 1, z), c_air, c_ignore, c_snow, c_pine_needles)
       add_pine_needles(data, a:index(x + 1, y + height + 1, z), c_air, c_ignore, c_snow, c_pine_needles)
       add_pine_needles(data, a:index(x, y + height + 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
       add_pine_needles(data, a:index(x, y + height + 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
       
       add_pine_needles(data, a:index(x - 1, y + height, z), c_air, c_ignore, c_snow, c_pine_needles)
       add_pine_needles(data, a:index(x + 1, y + height, z), c_air, c_ignore, c_snow, c_pine_needles)
       add_pine_needles(data, a:index(x, y + height, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
       add_pine_needles(data, a:index(x, y + height, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
       
       -- Add the basic snow
       if snow then
          add_snow(data, a:index(x, y + height + 3, z), c_air, c_ignore, c_snow)
         
          add_snow(data, a:index(x - 1, y + height + 2, z), c_air, c_ignore, c_snow)
          add_snow(data, a:index(x + 1, y + height + 2, z), c_air, c_ignore, c_snow)
          add_snow(data, a:index(x, y + height + 2, z - 1), c_air, c_ignore, c_snow)
          add_snow(data, a:index(x, y + height + 2, z + 1), c_air, c_ignore, c_snow)
       end
       
       
       if height > 6 then
          -- Add more needles for trees that are heigher than 6 blocks
          add_pine_needles(data, a:index(x - 1, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x, y + height - 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x, y + height - 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x + 1, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
       end
       
       if height > 6 and random(1, 2) == 1 then
          -- Add more needles and more snow for trees that are heigher than 8 blocks
          add_pine_needles(data, a:index(x - 1, y + height, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x - 1, y + height, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x + 1, y + height, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x + 1, y + height, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
         
          add_pine_needles(data, a:index(x - 2, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x - 1, y + height - 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x - 1, y + height - 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x, y + height - 1, z + 2), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x, y + height - 1, z - 2), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x + 1, y + height - 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x + 1, y + height - 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
          add_pine_needles(data, a:index(x + 2, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
         
          if random(1, 2) == 1 then
             add_pine_needles(data, a:index(x - 1, y + height - 2, z), c_air, c_ignore, c_snow, c_pine_needles)
          end
          if random(1, 2) == 1 then
             add_pine_needles(data, a:index(x, y + height - 2, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
          end
          if random(1, 2) == 1 then
             add_pine_needles(data, a:index(x, y + height - 2, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
          end
          if random(1, 2) == 1 then
             add_pine_needles(data, a:index(x + 1, y + height - 2, z), c_air, c_ignore, c_snow, c_pine_needles)
          end
         
          if snow then
             add_snow(data, a:index(x - 1, y + height + 1, z + 1), c_air, c_ignore, c_snow)
             add_snow(data, a:index(x - 1, y + height + 1, z - 1), c_air, c_ignore, c_snow)
             add_snow(data, a:index(x + 1, y + height + 1, z + 1), c_air, c_ignore, c_snow)
             add_snow(data, a:index(x + 1, y + height + 1, z - 1), c_air, c_ignore, c_snow)
             
             add_snow(data, a:index(x - 2, y + height, z), c_air, c_ignore, c_snow)
             add_snow(data, a:index(x, y + height, z - 2), c_air, c_ignore, c_snow)
             add_snow(data, a:index(x, y + height, z + 2), c_air, c_ignore, c_snow)
             add_snow(data, a:index(x + 2, y + height, z), c_air, c_ignore, c_snow)
          end
       end
       
       vm:set_data(data)
       vm:write_to_map()
       vm:update_map()
    end


My part of the code is WTFPL, if this is needed.
This is all of the pine things (not the sapling).
The function default.grow_pine_tree_a is the old pine tree.
My code isn't very short - Has somebody a idea to make it easier?

I think that this is good. - Could this come into the default?
What do you think about it?
Attachments
trees.zip
This is the first version (tree size 5-13)
(2.48 KiB) Downloaded 73 times
Last edited by LNJ on Sun Jul 12, 2015 13:01, edited 2 times in total.
My Minetest Modding Tutorials (German) | Minetest TNG - My survival subgame! (OUTDATED... :() | #ComeToTheDuckSide - we have privacy! | diaspora* - The free and decentralized alternative to facebook and twitter!
 

ABJ
Member
 
Posts: 2344
Joined: Sun Jan 18, 2015 13:02
GitHub: ABJ-MV
In-game: ABJ

Re: I did a new pine type

by ABJ » Sun Jul 05, 2015 17:30

Nice.
;)
 

User avatar
LNJ
Member
 
Posts: 200
Joined: Tue Sep 23, 2014 16:02
GitHub: LNJ2
IRC: LNJ2GO
In-game: LNJ

Re: I did a new pine type

by LNJ » Sun Jul 05, 2015 18:13

ABJ wrote:Nice.
;)

Thanks!
What do you think could this be added to the default?
My Minetest Modding Tutorials (German) | Minetest TNG - My survival subgame! (OUTDATED... :() | #ComeToTheDuckSide - we have privacy! | diaspora* - The free and decentralized alternative to facebook and twitter!
 

Dragonop
Member
 
Posts: 1178
Joined: Tue Oct 23, 2012 12:59
GitHub: Dragonop
IRC: Dragonop
In-game: Dragonop

Re: I did a new pine type

by Dragonop » Mon Jul 06, 2015 00:39

What's the problem with the actual pine trees?
But, it could be nice to have some tall trees.
Also, if you want tall trees, you can enable jungle generation.
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: I did a new pine type

by rubenwardy » Mon Jul 06, 2015 08:43

Is there a reason why you didn't use L systems?
 

User avatar
LNJ
Member
 
Posts: 200
Joined: Tue Sep 23, 2014 16:02
GitHub: LNJ2
IRC: LNJ2GO
In-game: LNJ

Re: I did a new pine type

by LNJ » Mon Jul 06, 2015 11:10

rubenwardy wrote:Is there a reason why you didn't use L systems?

I dont understand it!
I saw this way and used it. Okay it's not the best way.
My Minetest Modding Tutorials (German) | Minetest TNG - My survival subgame! (OUTDATED... :() | #ComeToTheDuckSide - we have privacy! | diaspora* - The free and decentralized alternative to facebook and twitter!
 

User avatar
LNJ
Member
 
Posts: 200
Joined: Tue Sep 23, 2014 16:02
GitHub: LNJ2
IRC: LNJ2GO
In-game: LNJ

Re: I did a new pine type

by LNJ » Mon Jul 06, 2015 11:14

Dragonop wrote:What's the problem with the actual pine trees?
But, it could be nice to have some tall trees.
Also, if you want tall trees, you can enable jungle generation.

I WANT BOTH!!
So not every tree looks like the other.

Jungle generation is enabled by default again. :)
My Minetest Modding Tutorials (German) | Minetest TNG - My survival subgame! (OUTDATED... :() | #ComeToTheDuckSide - we have privacy! | diaspora* - The free and decentralized alternative to facebook and twitter!
 

User avatar
LNJ
Member
 
Posts: 200
Joined: Tue Sep 23, 2014 16:02
GitHub: LNJ2
IRC: LNJ2GO
In-game: LNJ

Re: I did a new pine type

by LNJ » Mon Jul 06, 2015 15:11

rubenwardy wrote:Is there a reason why you didn't use L systems?

Okay, now I looked in the dev-wiki and found this: http://dev.minetest.net/treegen, http://dev.minetest.net/minetest.spawn_tree
My Minetest Modding Tutorials (German) | Minetest TNG - My survival subgame! (OUTDATED... :() | #ComeToTheDuckSide - we have privacy! | diaspora* - The free and decentralized alternative to facebook and twitter!
 

Dragonop
Member
 
Posts: 1178
Joined: Tue Oct 23, 2012 12:59
GitHub: Dragonop
IRC: Dragonop
In-game: Dragonop

Re: I did a new pine type

by Dragonop » Tue Jul 07, 2015 00:18

Hm, could be a good idea, or maybe not. With that quantity of leaves there will be a very high chance where you don't get sapplings, and if you get, you only get one.
 

ABJ
Member
 
Posts: 2344
Joined: Sun Jan 18, 2015 13:02
GitHub: ABJ-MV
In-game: ABJ

Re: I did a new pine type

by ABJ » Sat Jul 11, 2015 19:27

Yeah that would be annoying. But it can happen anywhere, on any tree. And he said he wanted BOTH, so we don't necessarily have to have a pine sapling famine. AND I really think this tree looks too elegant to ditch. AND ALSO, 100% of all the votes cast in the poll are with him anyway.

P.S. I forgot one thing. Please make the tree taller.
 

User avatar
LNJ
Member
 
Posts: 200
Joined: Tue Sep 23, 2014 16:02
GitHub: LNJ2
IRC: LNJ2GO
In-game: LNJ

Re: I did a new pine type

by LNJ » Sun Jul 12, 2015 12:55

ABJ wrote:P.S. I forgot one thing. Please make the tree taller.

Okay that is easy. :)

EDIT:
Is the new version okay?
Last edited by LNJ on Sun Jul 12, 2015 13:02, edited 1 time in total.
My Minetest Modding Tutorials (German) | Minetest TNG - My survival subgame! (OUTDATED... :() | #ComeToTheDuckSide - we have privacy! | diaspora* - The free and decentralized alternative to facebook and twitter!
 

milkymaidy
Member
 
Posts: 32
Joined: Sun Jul 12, 2015 06:27
In-game: Dave

Re: I did a new pine type

by milkymaidy » Sun Jul 12, 2015 12:59

[quote=quote"]I did a new pine (I want both, the already existing and my quote]
Here are some screenshots!
Image
Image
Image
Image
I edited the trees.lua (in the default)
That is the code (My part is at the end).
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Pinetree from mg mapgen mod, design by sfan5, pointy top added by paramat

local function add_pine_needles(data, vi, c_air, c_ignore, c_snow, c_pine_needles)
   if data[vi] == c_air or data[vi] == c_ignore or data[vi] == c_snow then
      data[vi] = c_pine_needles
   end
end

local function add_snow(data, vi, c_air, c_ignore, c_snow)
   if data[vi] == c_air or data[vi] == c_ignore then
      data[vi] = c_snow
   end
end

function default.grow_pine_tree(pos)
   local treetype = random(1, 3)
   
   if treetype <= 2 then
      default.grow_pine_tree_a(pos)
   else
      default.grow_pine_tree_b(pos)
   end
end
   
function default.grow_pine_tree_a(pos)
   local x, y, z = pos.x, pos.y, pos.z
   local maxy = y + random(9, 13) -- Trunk top

   local c_air = minetest.get_content_id("air")
   local c_ignore = minetest.get_content_id("ignore")
   local c_pinetree = minetest.get_content_id("default:pinetree")
   local c_pine_needles  = minetest.get_content_id("default:pine_needles")
   local c_snow = minetest.get_content_id("default:snow")
   local c_snowblock = minetest.get_content_id("default:snowblock")
   local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")

   local vm = minetest.get_voxel_manip()
   local minp, maxp = vm:read_from_map(
      {x = x - 3, y = y - 1, z = z - 3},
      {x = x + 3, y = maxy + 3, z = z + 3}
   )
   local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
   local data = vm:get_data()

   -- Scan for snow nodes near sapling
   local snow = false
   for yy = y - 1, y + 1 do
   for zz = z - 1, z + 1 do
      local vi  = a:index(x - 1, yy, zz)
      for xx = x - 1, x + 1 do
         local nodid = data[vi]
         if nodid == c_snow
         or nodid == c_snowblock
         or nodid == c_dirtsnow then
            snow = true
         end
         vi  = vi + 1
      end
   end
   end

   -- Upper branches layer
   local dev = 3
   for yy = maxy - 1, maxy + 1 do
      for zz = z - dev, z + dev do
         local vi = a:index(x - dev, yy, zz)
         local via = a:index(x - dev, yy + 1, zz)
         for xx = x - dev, x + dev do
            if random() < 0.95 - dev * 0.05 then
               add_pine_needles(data, vi, c_air, c_ignore, c_snow,
                     c_pine_needles)
               if snow then
                  add_snow(data, via, c_air, c_ignore, c_snow)
               end
            end
            vi  = vi + 1
            via = via + 1
         end
      end
      dev = dev - 1
   end

   -- Centre top nodes
   add_pine_needles(data, a:index(x, maxy + 1, z), c_air, c_ignore, c_snow,
         c_pine_needles)
   add_pine_needles(data, a:index(x, maxy + 2, z), c_air, c_ignore, c_snow,
         c_pine_needles) -- Paramat added a pointy top node
   if snow then
      add_snow(data, a:index(x, maxy + 3, z), c_air, c_ignore, c_snow)
   end

   -- Lower branches layer
   local my = 0
   for i = 1, 20 do -- Random 2x2 squares of needles
      local xi = x + random(-3, 2)
      local yy = maxy + random(-6, -5)
      local zi = z + random(-3, 2)
      if yy > my then
         my = yy
      end
      for zz = zi, zi+1 do
         local vi = a:index(xi, yy, zz)
         local via = a:index(xi, yy + 1, zz)
         for xx = xi, xi + 1 do
            add_pine_needles(data, vi, c_air, c_ignore, c_snow,
                  c_pine_needles)
            if snow then
               add_snow(data, via, c_air, c_ignore, c_snow)
            end
            vi  = vi + 1
            via = via + 1
         end
      end
   end

   local dev = 2
   for yy = my + 1, my + 2 do
      for zz = z - dev, z + dev do
         local vi = a:index(x - dev, yy, zz)
         local via = a:index(x - dev, yy + 1, zz)
         for xx = x - dev, x + dev do
            if random() < 0.95 - dev * 0.05 then
               add_pine_needles(data, vi, c_air, c_ignore, c_snow,
                     c_pine_needles)
               if snow then
                  add_snow(data, via, c_air, c_ignore, c_snow)
               end
            end
            vi  = vi + 1
            via = via + 1
         end
      end
      dev = dev - 1
   end

   -- Trunk
   for yy = y, maxy do
      local vi = a:index(x, yy, z)
      data[vi] = c_pinetree
   end

   vm:set_data(data)
   vm:write_to_map()
   vm:update_map()
end

function default.grow_pine_tree_b(pos)
   local x, y, z = pos.x, pos.y, pos.z
   local height = random(5, 13)
   local c_pinetree = minetest.get_content_id("default:pinetree")
   local c_pine_needles = minetest.get_content_id("default:pine_needles")
   local c_pine_sapling = minetest.get_content_id("default:pine_sapling")
   local c_snow = minetest.get_content_id("default:snow")
   local c_snowblock = minetest.get_content_id("default:snowblock")
   local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")
   local c_air = minetest.get_content_id("air")
   local c_ignore = minetest.get_content_id("ignore")

   local vm = minetest.get_voxel_manip()
   local minp, maxp = vm:read_from_map(
      {x = pos.x - 2, y = pos.y, z = pos.z - 2},
      {x = pos.x + 2, y = pos.y + height + 1, z = pos.z + 2}
   )
   local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
   local data = vm:get_data()
   
   -- Scan for snow nodes near sapling
   local snow = false
   for yy = y - 1, y + 1 do
   for zz = z - 1, z + 1 do
      local vi  = a:index(x - 1, yy, zz)
      for xx = x - 1, x + 1 do
         local nodid = data[vi]
         if nodid == c_snow
         or nodid == c_snowblock
         or nodid == c_dirtsnow then
            snow = true
         end
         vi  = vi + 1
      end
   end
   end
   
   -- Trunk
   for yy = y, y + height do
      local vi = a:index(x, yy, z)
      if data[vi] == c_air or data[vi] == c_pine_sapling or data[vi] == c_ignore then
         data[vi] = c_pinetree
      end
   end
   
   -- Add the basic needles
   add_pine_needles(data, a:index(x, y + height + 2, z), c_air, c_ignore, c_snow, c_pine_needles)
   
   add_pine_needles(data, a:index(x, y + height + 1, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x - 1, y + height + 1, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x + 1, y + height + 1, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x, y + height + 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x, y + height + 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
   
   add_pine_needles(data, a:index(x - 1, y + height, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x + 1, y + height, z), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x, y + height, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
   add_pine_needles(data, a:index(x, y + height, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
   
   -- Add the basic snow
   if snow then
      add_snow(data, a:index(x, y + height + 3, z), c_air, c_ignore, c_snow)
      
      add_snow(data, a:index(x - 1, y + height + 2, z), c_air, c_ignore, c_snow)
      add_snow(data, a:index(x + 1, y + height + 2, z), c_air, c_ignore, c_snow)
      add_snow(data, a:index(x, y + height + 2, z - 1), c_air, c_ignore, c_snow)
      add_snow(data, a:index(x, y + height + 2, z + 1), c_air, c_ignore, c_snow)
   end
   
   
   if height > 6 then
      -- Add more needles for trees that are heigher than 6 blocks
      add_pine_needles(data, a:index(x - 1, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x, y + height - 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x, y + height - 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 1, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
   end
   
   if height > 6 and random(1, 2) == 1 then
      -- Add more needles and more snow for trees that are heigher than 8 blocks
      add_pine_needles(data, a:index(x - 1, y + height, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x - 1, y + height, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 1, y + height, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 1, y + height, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      
      add_pine_needles(data, a:index(x - 2, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x - 1, y + height - 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x - 1, y + height - 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x, y + height - 1, z + 2), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x, y + height - 1, z - 2), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 1, y + height - 1, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 1, y + height - 1, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      add_pine_needles(data, a:index(x + 2, y + height - 1, z), c_air, c_ignore, c_snow, c_pine_needles)
      
      if random(1, 2) == 1 then
         add_pine_needles(data, a:index(x - 1, y + height - 2, z), c_air, c_ignore, c_snow, c_pine_needles)
      end
      if random(1, 2) == 1 then
         add_pine_needles(data, a:index(x, y + height - 2, z - 1), c_air, c_ignore, c_snow, c_pine_needles)
      end
      if random(1, 2) == 1 then
         add_pine_needles(data, a:index(x, y + height - 2, z + 1), c_air, c_ignore, c_snow, c_pine_needles)
      end
      if random(1, 2) == 1 then
         add_pine_needles(data, a:index(x + 1, y + height - 2, z), c_air, c_ignore, c_snow, c_pine_needles)
      end
      
      if snow then
         add_snow(data, a:index(x - 1, y + height + 1, z + 1), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x - 1, y + height + 1, z - 1), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x + 1, y + height + 1, z + 1), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x + 1, y + height + 1, z - 1), c_air, c_ignore, c_snow)
         
         add_snow(data, a:index(x - 2, y + height, z), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x, y + height, z - 2), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x, y + height, z + 2), c_air, c_ignore, c_snow)
         add_snow(data, a:index(x + 2, y + height, z), c_air, c_ignore, c_snow)
      end
   end
   
   vtm:set_data(data)
   vtm:write_to_map()
   vtm:update_map()
end

My part of the code is WTFPL, if this is needed.
This is all of the pine things (not the sapling).
The function default.grow_pine_tree_a is the old pine tree.
My code isn't very short - Has somebody a idea to make it easier?

I think that this is good. - Could this come into the default?
What do you think about it?[/quote]

Made it a mod now, and now posted.
 


Return to Minetest Features

Who is online

Users browsing this forum: No registered users and 2 guests

cron