Advertisement
Guest User

paragen-020-lvm

a guest
Sep 27th, 2013
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.50 KB | None | 0 0
  1. -- paragen 0.2.0 by paramat
  2. -- For latest stable Minetest and back to 0.4.7, requires default snow nodes
  3. -- Depends default
  4. -- Licenses: Code WTFPL. Textures: CC BY-SA
  5.  
  6. -- Variables
  7.  
  8. local ONGEN = true -- (true / false) Enable / disable generation.
  9.  
  10. local XMIN = -16000 -- Approx West edge. -- These 6 parameters will be rounded down or up to chunk edges.
  11. local XMAX = 16000 -- Approx East edge.
  12. local ZMIN = -16000 -- Approx South edge.
  13. local ZMAX = 16000 -- Approx North edge.
  14. local YMIN = 12000 -- Approx bottom. -- Terrain is automatically centered between YMIN and YMAX.
  15. local YMAX = 14000 -- Approx top.
  16.  
  17. local WATY = 13000 -- Water surface y.
  18. local GRADC = 13040 -- Temperature and humidity gradient centre y.
  19. local CLOUDY = 13080 -- Cloud y.
  20. local SANY = 13002 -- Sandline average y of beach top.
  21. local SANA = 6 -- 6 -- Sandline amplitude.
  22. local SANR = 2 -- 2 -- Sandline randomness.
  23.  
  24. local VSCALE = 160 -- Vertical scale of terrain.
  25. local PERSAV = 0.5 -- 0.5 -- Persistence average. Terrain roughness.
  26. local PERSAMP = 0.1 -- 0.1 -- Persistence amplitude. Roughness variation.
  27. local STAV = 0.05 -- 0.04 -- Stone threshold average. Fine material depth.
  28. local STAMP = 0.02 -- 0.02 -- Stone threshold amplitude. Depth variation.
  29.  
  30. local FISTS = 0.01 -- 0.01 -- Fissure noise threshold surface. Fissure size at surface.
  31. local CAVTS = 8.0 --  2.0 -- Cave noise threshold surface. Cave size at surface.
  32. local FISTU = 0.03 -- 0.03 -- Fissure threshold underground. Fissure size underground.
  33. local CAVTU = 0.5 -- 0.5 -- Cave threshold underground. Cave size underground.
  34.  
  35. local HITET = 0.35 --  -- Desert / savanna / rainforest temperature noise threshold.
  36. local LOTET = -0.45 --  -- Tundra / taiga temperature noise threshold.
  37. local HIWET = 0.35 --  -- Wet grassland / rainforest wetness noise threshold.
  38. local LOWET = -0.45 --  -- Tundra / dry grassland / desert wetness noise threshold.
  39.  
  40. local TGRAD = 160 -- 160 -- Vertical temperature gradient. -- All 3 fall with altitude.
  41. local HGRAD = 160 -- 160 -- Vertical humidity gradient.
  42. local STGRAD = 1600 -- 160 -- Stone threshold gradient.
  43.  
  44. local CHUT = 0.0 --  -- Cloud humidity threshold.
  45. local CHUTH = 0.8 --  -- Cloud humidity threshold high, for dark clouds.
  46.  
  47. local TUNGRACHA = 145 -- 145 -- Dry shrub 1/x chance per full node in tundra.
  48. local TAIPINCHA = 49 -- 49 -- Pine 1/x chance per full node in taiga.
  49. local DRYGRACHA = 2 -- 2 -- Dry shrub 1/x chance per full node in dry grasslands.
  50. local DECAPPCHA = 85 -- 85 -- Appletree sapling 1/x chance per full node in deciduous forest.
  51. local WETGRACHA = 2 -- 2 -- Junglegrass 1/x chance per full node in wet grasslands.
  52. local DESCACCHA = 421 -- 421 -- Cactus 1/x chance per full node in desert.
  53. local DESGRACHA = 265 -- 265 -- Dry shrub 1/x chance per full node in desert.
  54. local SAVGRACHA = 3 -- 3 -- Dry shrub 1/x chance per full node in savanna.
  55. local SAVTRECHA = 361 -- 361 -- Savanna tree 1/x chance per full node in savanna.
  56. local RAIJUNCHA = 25 -- 25 -- Jungletree 1/x chance per full node in rainforest.
  57. local DUNGRACHA = 9 --  -- Dry shrub 1/x chance per full node in dunes.
  58.  
  59. local PININT = 67 -- 67 -- Pine from sapling abm interval in seconds.
  60. local PINCHA = 11 -- 11 -- 1/x chance per node.
  61.  
  62. local JUNINT = 71 -- 71 -- Jungletree from sapling abm interval in seconds.
  63. local JUNCHA = 11 -- 11 -- 1/x chance per node.
  64.  
  65. local SAVINT = 73 -- 73 -- Jungletree from sapling abm interval in seconds.
  66. local SAVCHA = 11 -- 11 -- 1/x chance per node.
  67.  
  68. -- 3D Perlin1 for terrain
  69. local perl1 = {
  70.     SEED1 = 5829058,
  71.     OCTA1 = 7, --
  72.     SCAL1 = 512, --
  73. }
  74.  
  75. -- 2D Perlin2 for alt terrain
  76. local perl2 = {
  77.     SEED2 = 76906,
  78.     OCTA2 = 7, --
  79.     SCAL2 = 414, --
  80. }
  81.  
  82. -- 3D Perlin3 for terrain select
  83. local perl3 = {
  84.     SEED3 = 848,
  85.     OCTA3 = 5, --
  86.     PERS3 = 0.5, --
  87.     SCAL3 = 256, --
  88. }
  89.  
  90. -- 3D Perlin4 for fissures and caves
  91. local perl4 = {
  92.     SEED4 = 98275470284,
  93.     OCTA4 = 6, --
  94.     PERS4 = 0.5, --
  95.     SCAL4 = 207, --
  96. }
  97.  
  98. -- 3D Perlin5 for perlin1 perlin2 persistence, stone depth, sandline
  99. local perl5 = {
  100.     SEED5 = 7028411255342,
  101.     OCTA5 = 4, --
  102.     PERS5 = 0.5, --
  103.     SCAL5 = 414, --
  104. }
  105.  
  106. -- 3D Perlin6 for temperature
  107. local perl6 = {
  108.     SEED6 = 7,
  109.     OCTA6 = 2, --
  110.     PERS6 = 0.5, --
  111.     SCAL6 = 512, --
  112. }
  113.  
  114. -- 3D Perlin7 for humidity
  115. local perl7 = {
  116.     SEED7 = 900011676,
  117.     OCTA7 = 2, --
  118.     PERS7 = 0.5, --
  119.     SCAL7 = 512, --
  120. }
  121.  
  122. -- Nodes
  123.  
  124. minetest.register_node("paragen:redstone", {
  125.     description = "PG Redstone",
  126.     tiles = {"paragen_redstone.png"},
  127.     groups = {cracky=3},
  128.     sounds = default.node_sound_stone_defaults(),
  129. })
  130.  
  131.  
  132. minetest.register_node("paragen:stone", {
  133.     description = "PG Stone",
  134.     tiles = {"default_stone.png"},
  135.     groups = {cracky=3},
  136.     sounds = default.node_sound_stone_defaults(),
  137. })
  138.  
  139.  
  140. minetest.register_node("paragen:permafrost", {
  141.     description = "PG Permafrost",
  142.     tiles = {"paragen_permafrost.png"},
  143.     groups = {crumbly=1},
  144.     drop = "default:dirt",
  145.     sounds = default.node_sound_dirt_defaults(),
  146. })
  147.  
  148. minetest.register_node("paragen:drygrass", {
  149.     description = "PG Dirt With Dry Grass",
  150.     tiles = {"paragen_drygrass.png", "default_dirt.png", "paragen_drygrass.png"},
  151.     groups = {crumbly=3,soil=1},
  152.     drop = "default:dirt",
  153.     sounds = default.node_sound_dirt_defaults({
  154.         footstep = {name="default_grass_footstep", gain=0.4},
  155.     }),
  156. })
  157.  
  158. minetest.register_node("paragen:cloud", {
  159.     drawtype = "glasslike",
  160.     tiles = {"paragen_cloud.png"},
  161.     paramtype = "light",
  162.     sunlight_propagates = true,
  163.     walkable = false,
  164.     pointable = false,
  165.     diggable = false,
  166.     buildable_to = true,
  167.     post_effect_color = {a=127, r=255, g=255, b=255},
  168.     groups = {not_in_creative_inventory=1},
  169. })
  170.  
  171. minetest.register_node("paragen:darkcloud", {
  172.     drawtype = "glasslike",
  173.     tiles = {"paragen_darkcloud.png"},
  174.     paramtype = "light",
  175.     sunlight_propagates = true,
  176.     walkable = false,
  177.     pointable = false,
  178.     diggable = false,
  179.     buildable_to = true,
  180.     post_effect_color = {a=127, r=255, g=255, b=255},
  181.     groups = {not_in_creative_inventory=1},
  182. })
  183.  
  184. minetest.register_node("paragen:pleaf", {
  185.     description = "PG Pine Needles",
  186.     visual_scale = 1.3,
  187.     tiles = {"paragen_pleaf.png"},
  188.     paramtype = "light",
  189.     groups = {snappy=3, flammable=2},
  190.     drop = {
  191.         max_items = 1,
  192.         items = {
  193.             {items = {"paragen:psapling"}, rarity = 20},
  194.             {items = {"paragen:pleaf"}}
  195.         }
  196.     },
  197.     sounds = default.node_sound_leaves_defaults(),
  198. })
  199.  
  200. minetest.register_node("paragen:psapling", {
  201.     description = "PG Pine Sapling",
  202.     drawtype = "plantlike",
  203.     visual_scale = 1.0,
  204.     tiles = {"paragen_psapling.png"},
  205.     inventory_image = "paragen_psapling.png",
  206.     wield_image = "paragen_psapling.png",
  207.     paramtype = "light",
  208.     walkable = false,
  209.     groups = {snappy=2,dig_immediate=3,flammable=2},
  210.     sounds = default.node_sound_defaults(),
  211. })
  212.  
  213. minetest.register_node("paragen:sleaf", {
  214.     description = "PG Savanna Tree Leaves",
  215.     visual_scale = 1.3,
  216.     tiles = {"paragen_sleaf.png"},
  217.     paramtype = "light",
  218.     groups = {snappy=3, flammable=2},
  219.     drop = {
  220.         max_items = 1,
  221.         items = {
  222.             {items = {"paragen:ssapling"}, rarity = 20},
  223.             {items = {"paragen:sleaf"}}
  224.         }
  225.     },
  226.     sounds = default.node_sound_leaves_defaults(),
  227. })
  228.  
  229. minetest.register_node("paragen:ssapling", {
  230.     description = "PG Savanna Tree Sapling",
  231.     drawtype = "plantlike",
  232.     visual_scale = 1.0,
  233.     tiles = {"paragen_ssapling.png"},
  234.     inventory_image = "paragen_ssapling.png",
  235.     wield_image = "paragen_ssapling.png",
  236.     paramtype = "light",
  237.     walkable = false,
  238.     groups = {snappy=2,dig_immediate=3,flammable=2},
  239.     sounds = default.node_sound_defaults(),
  240. })
  241.  
  242. -- Stuff
  243.  
  244. paragen = {}
  245.  
  246. local xminq = (80 * math.floor((XMIN + 32) / 80)) - 32
  247. local yminq = (80 * math.floor((YMIN + 32) / 80)) - 32
  248. local zminq = (80 * math.floor((ZMIN + 32) / 80)) - 32
  249.  
  250. local xmaxq = (80 * math.floor((XMAX + 32) / 80)) + 47
  251. local ymaxq = (80 * math.floor((YMAX + 32) / 80)) + 47
  252. local zmaxq = (80 * math.floor((ZMAX + 32) / 80)) + 47
  253.  
  254. local gradcen = math.floor((ymaxq + yminq) / 2)
  255. local cloudyq = (80 * math.floor((CLOUDY + 32) / 80)) - 32
  256.  
  257. -- On generated function
  258.  
  259. if ONGEN then
  260.     minetest.register_on_generated(function(minp, maxp, seed)
  261.         if minp.y >= yminq and maxp.y <= ymaxq then
  262.             local env = minetest.env
  263.             local perlin3 = env:get_perlin(perl3.SEED3, perl3.OCTA3, perl3.PERS3, perl3.SCAL3)
  264.             local perlin4 = env:get_perlin(perl4.SEED4, perl4.OCTA4, perl4.PERS4, perl4.SCAL4)
  265.             local perlin5 = env:get_perlin(perl5.SEED5, perl5.OCTA5, perl5.PERS5, perl5.SCAL5)
  266.             local perlin6 = env:get_perlin(perl6.SEED6, perl6.OCTA6, perl6.PERS6, perl6.SCAL6)
  267.             local perlin7 = env:get_perlin(perl7.SEED7, perl7.OCTA7, perl7.PERS7, perl7.SCAL7)
  268.             local x1 = maxp.x
  269.             local y1 = maxp.y
  270.             local z1 = maxp.z
  271.             local x0 = minp.x
  272.             local y0 = minp.y
  273.             local z0 = minp.z
  274.  
  275.             local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
  276.             local a = VoxelArea:new{
  277.                 MinEdge={x=emin.x, y=emin.y, z=emin.z},
  278.                 MaxEdge={x=emax.x, y=emax.y, z=emax.z},
  279.             }
  280.             local data = vm:get_data()
  281.            
  282.             local nodeid = {}
  283.             nodeid.sand = minetest.get_content_id("default:sand")
  284.             nodeid.shrub = minetest.get_content_id("default:dry_shrub")
  285.             nodeid.snowblock = minetest.get_content_id("default:snowblock")
  286.             nodeid.snow = minetest.get_content_id("default:snow")
  287.             nodeid.desertsand = minetest.get_content_id("default:desert_sand")
  288.             nodeid.cactus = minetest.get_content_id("default:cactus")
  289.             nodeid.permafrost = minetest.get_content_id("paragen:permafrost")          
  290.             nodeid.drygrass = minetest.get_content_id("paragen:drygrass")
  291.             nodeid.dirt = minetest.get_content_id("default:dirt")
  292.             nodeid.dirtwgrass = minetest.get_content_id("default:dirt_with_grass")
  293.             nodeid.junglegrass = minetest.get_content_id("default:junglegrass")        
  294.             nodeid.sapling = minetest.get_content_id("default:sapling")
  295.             nodeid.redstone = minetest.get_content_id("paragen:redstone")                  
  296.             nodeid.stone = minetest.get_content_id("paragen:stone")                            
  297.             nodeid.sandstone = minetest.get_content_id("default:sandstone")
  298.             nodeid.ice = minetest.get_content_id("default:ice")        
  299.             nodeid.water = minetest.get_content_id("default:water_source")         
  300.             nodeid.cloud = minetest.get_content_id("paragen:cloud")                            
  301.             nodeid.darkcloud = minetest.get_content_id("paragen:darkcloud")                                        
  302.                    
  303.             for x = x0, x1 do -- for each plane do
  304.                 print ("[paragen] "..(x - x0 + 1).." ("..minp.x.." "..minp.y.." "..minp.z..")")
  305.                 for z = z0, z1 do -- for each column do
  306.                     local sol = false -- node is solid
  307.                     local des = false -- desert biome
  308.                     local sav = false -- savanna biome
  309.                     local rai = false -- rainforest biome
  310.                     local wet = false -- wet grassland biome
  311.                     local dry = false -- dry grassland biome
  312.                     local dec = false -- deciduous forest biome
  313.                     local tun = false -- tundra biome
  314.                     local tai = false -- taiga forest biome
  315.                     local noise5c = perlin5:get2d({x=x-777,y=z-777}) -- beach top
  316.                     local sandy = SANY + noise5c * SANA + math.random(SANR)
  317.                     for y = y1, y0, -1 do -- working downwards through column for each node do
  318.                    
  319.                         local vi = a:index(x, y, z) -- LVM index for node                  
  320.                    
  321.                         local noise5 = perlin5:get3d({x=x,y=y,z=z}) -- persistence
  322.                         local pepers = PERSAV + noise5 * PERSAMP
  323.                         local noise5b = perlin5:get2d({x=x+777,y=z+777}) -- stone threshold
  324.                         local stothr = STAV + noise5b * STAMP - (y - WATY) / STGRAD
  325.                         local noise3 = perlin3:get3d({x=x,y=y/2,z=z}) -- terrain select
  326.                         if noise3 > 0 then
  327.                             local perlin1 = env:get_perlin(perl1.SEED1, perl1.OCTA1, pepers, perl1.SCAL1)
  328.                             noise = perlin1:get3d({x=x,y=y,z=z})
  329.                         else
  330.                             local perlin2 = env:get_perlin(perl2.SEED2, perl2.OCTA2, pepers, perl2.SCAL2)
  331.                             noise = perlin2:get3d({x=x,y=y,z=z})
  332.                         end
  333.                         local grad = (gradcen - y) / VSCALE
  334.                         local density = noise + grad
  335.                         if density >= 0 or y == WATY then -- if terrain or at sea level then
  336.                             if density < 1 then
  337.                                 fist = FISTS + density * (FISTU - FISTS)
  338.                                 cavt = CAVTS + density * (CAVTU - CAVTS)
  339.                             else
  340.                                 fist = FISTU
  341.                                 cavt = CAVTU
  342.                             end
  343.                             local noise4 = perlin4:get3d({x=x,y=y,z=z}) -- fissures
  344.                             local noise4b = perlin4:get3d({x=x*2,y=y*2,z=z*2}) -- caves
  345.                             if math.abs(noise4) > fist and math.abs(noise4b) < cavt then -- if no fissures and no cave then
  346.                                 if not sol then -- when solid node found under air decide or reset biome
  347.                                     local noise6 = perlin6:get2d({x=x,y=z})
  348.                                     local noise7 = perlin7:get2d({x=x,y=z})
  349.                                     local temp = noise6 - (y - GRADC) / TGRAD
  350.                                     local hum = noise7 - (y - GRADC) / HGRAD
  351.                                     if temp > HITET + math.random() / 10 then
  352.                                         if hum > HIWET + math.random() / 10 then
  353.                                             rai = true
  354.                                         elseif hum < LOWET + math.random() / 10 then
  355.                                             des = true
  356.                                         else
  357.                                             sav = true
  358.                                         end
  359.                                     elseif temp < LOTET + math.random() / 10 then
  360.                                         if hum < LOWET + math.random() / 10 then
  361.                                             tun = true
  362.                                         else
  363.                                             tai = true
  364.                                         end
  365.                                     elseif hum > HIWET + math.random() / 10 then
  366.                                         wet = true
  367.                                     elseif hum < LOWET + math.random() / 10 then
  368.                                         dry = true
  369.                                     else
  370.                                         dec = true
  371.                                     end
  372.                                 end
  373.                                 if density >= 0 and density < stothr then -- if fine material then
  374.                                     if y <= sandy then -- if beach or dunes
  375.                                         data[vi] = nodeid.sand
  376.                                         if not sol then
  377.                                             if y >= WATY + 4 and math.random(DUNGRACHA) == 2 then
  378.                                                 data[vi] = nodeid.shrub
  379.                                             elseif tai then
  380.                                                 data[vi] = nodeid.snowblock
  381.                                             elseif tun then
  382.                                                 data[vi] = nodeid.snow
  383.                                             end
  384.                                         end
  385.                                     elseif des then -- if desert
  386.                                         data[vi] = nodeid.desertsand
  387.                                         if not sol then
  388.                                             if math.random(DESGRACHA) == 2 then
  389.                                                 data[vi] = nodeid.shrub
  390.                                             elseif math.random(DESCACCHA) == 2 then
  391.                                                 for c = 1, math.random(1,6) do
  392.                                                     data[vi] = nodeid.cactus
  393.                                                 end
  394.                                             end
  395.                                         end
  396.                                     elseif tun then -- if tundra
  397.                                         data[vi] = nodeid.permafrost
  398.                                         if not sol then
  399.                                             if math.random(TUNGRACHA) == 2 then
  400.                                                 data[vi] = nodeid.shrub
  401.                                             else
  402.                                                 data[vi] = nodeid.snow
  403.                                             end
  404.                                         end
  405.                                     elseif dry or sav then -- dry grassland or savanna
  406.                                         data[vi] = nodeid.drygrass
  407.                                         if not sol then -- if surface node then
  408.                                             data[vi] = nodeid.drygrass
  409.                                             if dry and math.random(DRYGRACHA) == 2 then
  410.                                                 data[vi] = nodeid.shrub
  411.                                             elseif sav and math.random(SAVGRACHA) == 2 then
  412.                                                 data[vi] = nodeid.shrub
  413.                                             elseif sav and math.random(SAVTRECHA) == 2 then
  414.                                                 paragen_stree({x=x,y=y+1,z=z})
  415.                                             end
  416.                                         else -- underground node
  417.                                             data[vi] = nodeid.dirt
  418.                                         end
  419.                                     else -- wet grasslands, taiga, deciduous forest, rainforest
  420.                                         if not sol then
  421.                                             data[vi] = nodeid.dirtwgrass
  422.                                             if wet and math.random(WETGRACHA) == 2 then
  423.                                                 data[vi] = nodeid.junglegrass
  424.                                             elseif dec and y > sandy and math.random(DECAPPCHA) == 2 then
  425.                                                 data[vi] = nodeid.sapling
  426.                                             elseif tai then
  427.                                                 if math.random(TAIPINCHA) == 2 then
  428.                                                     paragen_pine({x=x,y=y+1,z=z})
  429.                                                 else
  430.                                                     data[vi] = nodeid.snowblock
  431.                                                 end
  432.                                             elseif rai and math.random(RAIJUNCHA) == 2 then
  433.                                                 paragen_jtree({x=x,y=y+1,z=z})
  434.                                             end
  435.                                         else
  436.                                             data[vi] = nodeid.dirt
  437.                                         end
  438.                                     end
  439.                                 elseif density >= stothr then
  440.                                     if (density >= stothr and density < 0.13) -- if normal rock strata
  441.                                     or (density >= 0.19 and density < 0.23)
  442.                                     or (density >= 0.32 and density < 0.37)
  443.                                     or (density >= 0.47 and density < 0.60)
  444.                                     or (density >= 0.69 and density < 0.73)
  445.                                     or density >= 0.97 then
  446.                                         if (des or sav) and density < 1.29 then
  447.                                             data[vi] = nodeid.redstone
  448.                                         else
  449.                                             data[vi] = nodeid.stone
  450.                                         end
  451.                                     else -- sandstone strata
  452.                                         data[vi] = nodeid.sandstone
  453.                                     end
  454.                                 elseif y == WATY then -- if at sea surface
  455.                                     if tun or tai then
  456.                                         data[vi] = nodeid.ice
  457.                                         if tai then
  458.                                             data[vi] = nodeid.snow
  459.                                         end
  460.                                     else
  461.                                         data[vi] = nodeid.water
  462.                                     end
  463.                                 end
  464.                                 if density >= stothr and (tun or tai) and not sol then -- snow on high rocky alpine biome
  465.                                     if tai then
  466.                                         data[vi] = nodeid.snowblock
  467.                                     else
  468.                                         data[vi] = nodeid.snow
  469.                                     end
  470.                                 end
  471.                                 sol = true -- node was solid
  472.                             end
  473.                         elseif y < WATY then -- underwater
  474.                             data[vi] = nodeid.water
  475.                         else
  476.                             sol = false -- node was not solid
  477.                         end
  478.                     end
  479.                 end
  480.             end
  481.             if y0 == cloudyq then -- CLouds
  482.                 print ("[paragen] Clouds ("..minp.x.." "..minp.y.." "..minp.z..")")
  483.                 for i = 0, (x1 - x0), 16 do
  484.                 for k = 0, (z1 - z0), 16 do
  485.                     local noise7 = perlin7:get2d({x=x0+i,y=z0+k})
  486.                     local hum = noise7
  487.                     if (hum - CHUT) > math.random() then
  488.                         for a = 0, 15 do
  489.                         for b = 0, 15 do
  490.                             local x = x0 + i + a
  491.                             local z = z0 + k + b
  492.                             if env:get_node({x=x,y=CLOUDY,z=z}).name == "air" then
  493.                                 if hum > CHUTH then
  494.                                     data[vi] = nodeid.darkcloud
  495.                                 else   
  496.                                     data[vi] = nodeid.cloud
  497.                                 end
  498.                             end
  499.                         end
  500.                         end
  501.                     end
  502.                 end
  503.                 end
  504.             end
  505.             vm:set_data(data)
  506.             vm:calc_lighting(
  507.                 {x=minp.x-16, y=minp.y, z=minp.z-16},
  508.                 {x=maxp.x+16, y=maxp.y, z=maxp.z+16}
  509.             )
  510.             vm:write_to_map(data)          
  511.         end
  512.     end)
  513. end
  514.  
  515. -- ABMs
  516.  
  517. -- Pine sapling abm
  518.  
  519. minetest.register_abm({
  520.     nodenames = {"paragen:psapling"},
  521.     interval = PININT,
  522.     chance = PINCHA,
  523.     action = function(pos, node, active_object_count, active_object_count_wider)
  524.         paragen_pine(pos)
  525.         if DEBUG then
  526.             print ("[paragen] Pine sapling grows")
  527.         end
  528.     end,
  529. })
  530.  
  531. -- Jungletree sapling abm
  532.  
  533. minetest.register_abm({
  534.     nodenames = {"paragen:jsapling"},
  535.     interval = JUNINT,
  536.     chance = JUNCHA,
  537.     action = function(pos, node, active_object_count, active_object_count_wider)
  538.         paragen_jtree(pos)
  539.         if DEBUG then
  540.             print ("[paragen] Jungletree sapling grows")
  541.         end
  542.     end,
  543. })
  544.  
  545. -- Savanna tree sapling abm
  546.  
  547. minetest.register_abm({
  548.     nodenames = {"paragen:ssapling"},
  549.     interval = SAVINT,
  550.     chance = SAVCHA,
  551.     action = function(pos, node, active_object_count, active_object_count_wider)
  552.         paragen_stree(pos)
  553.         if DEBUG then
  554.             print ("[paragen] Savanna tree sapling grows")
  555.         end
  556.     end,
  557. })
  558.  
  559. -- Functions
  560.  
  561. -- Jungletree function
  562.  
  563. function paragen_jtree(pos)
  564.     local env = minetest.env
  565.     local t = 12 + math.random(5) -- trunk height
  566.     for j = -3, t do
  567.         if j == math.floor(t * 0.7) or j == t then
  568.             for i = -2, 2 do
  569.             for k = -2, 2 do
  570.                 local absi = math.abs(i)
  571.                 local absk = math.abs(k)
  572.                 if math.random() > (absi + absk) / 16 then
  573.                     env:add_node({x=pos.x+i,y=pos.y+j+math.random(0, 1),z=pos.z+k},{name="default:jungleleaves"})
  574.                 end
  575.             end
  576.             end
  577.         end
  578.         env:add_node({x=pos.x,y=pos.y+j,z=pos.z},{name="default:jungletree"})
  579.     end
  580. end
  581.  
  582. -- Savanna tree function
  583.  
  584. function paragen_stree(pos)
  585.     local env = minetest.env
  586.     local t = 4 + math.random(2) -- trunk height
  587.     for j = -2, t do
  588.         if j == t then
  589.             for i = -3, 3 do
  590.             for k = -3, 3 do
  591.                 local absi = math.abs(i)
  592.                 local absk = math.abs(k)
  593.                 if math.random() > (absi + absk) / 24 then
  594.                     env:add_node({x=pos.x+i,y=pos.y+j+math.random(0, 1),z=pos.z+k},{name="paragen:sleaf"})
  595.                 end
  596.             end
  597.             end
  598.         end
  599.         env:add_node({x=pos.x,y=pos.y+j,z=pos.z},{name="default:tree"})
  600.     end
  601. end
  602.  
  603. -- Pine tree function
  604.  
  605. function paragen_pine(pos)
  606.     local env = minetest.env
  607.     local t = 10 + math.random(3) -- trunk height
  608.     for i = -2, 2 do
  609.     for k = -2, 2 do
  610.         local absi = math.abs(i)
  611.         local absk = math.abs(k)
  612.         if absi >= absk then
  613.             j = t - absi
  614.         else
  615.             j = t - absk
  616.         end
  617.         if math.random() > (absi + absk) / 16 then
  618.             env:add_node({x=pos.x+i,y=pos.y+j+2,z=pos.z+k},{name="default:snow"})
  619.             env:add_node({x=pos.x+i,y=pos.y+j+1,z=pos.z+k},{name="paragen:pleaf"})
  620.             env:add_node({x=pos.x+i,y=pos.y+j-1,z=pos.z+k},{name="default:snow"})
  621.             env:add_node({x=pos.x+i,y=pos.y+j-2,z=pos.z+k},{name="paragen:pleaf"})
  622.             env:add_node({x=pos.x+i,y=pos.y+j-4,z=pos.z+k},{name="default:snow"})
  623.             env:add_node({x=pos.x+i,y=pos.y+j-5,z=pos.z+k},{name="paragen:pleaf"})
  624.         end
  625.     end
  626.     end
  627.     for j = -3, t do
  628.         env:add_node({x=pos.x,y=pos.y+j,z=pos.z},{name="default:tree"})
  629.     end
  630. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement