Use voxelmanip for stability scanning. New design tree grown by voxelmanip

master
Mat 2014-07-13 06:43:34 +01:00
parent afac21fb6b
commit d7e546bae9
4 changed files with 83 additions and 49 deletions

View File

@ -1,5 +1,5 @@
moonrealm 0.8.0 by paramat
For Minetest 0.4.9 dev with custom skybox commit
moonrealm 0.8.1 by paramat
For Minetest 0.4.10
Depends default
Licenses: code WTFPL, textures CC BY-SA

View File

@ -4,38 +4,69 @@ function moonrealm_appletree(pos)
local x = pos.x
local y = pos.y
local z = pos.z
for j = -2, -1 do
local nodename = minetest.get_node({x=x,y=y+j,z=z}).name
if nodename ~= "moonrealm:soil" then
local top = 3 + math.random(2)
local c_tree = minetest.get_content_id("default:tree")
local c_apple = minetest.get_content_id("default:apple")
local c_appleleaf = minetest.get_content_id("moonrealm:appleleaf")
local c_soil = minetest.get_content_id("moonrealm:soil")
local c_lsair = minetest.get_content_id("moonrealm:air")
local vm = minetest.get_voxel_manip()
local pos1 = {x=x-2, y=y-2, z=z-2}
local pos2 = {x=x+2, y=y+5, z=z+2}
local emin, emax = vm:read_from_map(pos1, pos2)
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
local data = vm:get_data()
for j = -2, -1 do -- check for soil
local vi = area:index(x, y + j, z)
if data[vi] ~= c_soil then
return
end
end
for j = 1, 5 do
local nodename = minetest.get_node({x=x,y=y+j,z=z}).name
if nodename ~= "moonrealm:air" then
for j = 1, 5 do -- check for life support air
for i = -2, 2 do
for k = -2, 2 do
local vi = area:index(x + i, y + j, z + k)
if data[vi] ~= c_lsair then
return
end
end
for j = -2, 4 do
if j >= 1 then
end
end
for j = -2, top do -- spawn appletree
if j == top - 1 or j == top then
for i = -2, 2 do
for k = -2, 2 do
local nodename = minetest.get_node({x=x+i,y=y+j+1,z=z+k}).name
if math.random() > (math.abs(i) + math.abs(k)) / 16 then
if math.random(13) == 2 then
minetest.add_node({x=pos.x+i,y=pos.y+j+1,z=pos.z+k},{name="default:apple"})
else
minetest.add_node({x=pos.x+i,y=pos.y+j+1,z=pos.z+k},{name="moonrealm:leaves"})
local vi = area:index(x + i, y + j, z + k)
if math.random(5) ~= 2 then
data[vi] = c_appleleaf
if j == top and math.random() < 0.04 then -- apples hang from leaves
local viu = area:index(x + i, y + j - 1, z + k)
data[viu] = c_apple
end
else
minetest.add_node({x=x+i,y=y+j+1,z=z+k},{name="moonrealm:air"})
minetest.get_meta({x=x+i,y=y+j+1,z=z+k}):set_int("spread", 16)
end
end
end
elseif j == top - 2 then
for i = -1, 1 do
for k = -1, 1 do
if math.abs(i) + math.abs(k) == 2 then
local vi = area:index(x + i, y + j, z + k)
data[vi] = c_tree
end
end
end
else
local vi = area:index(x, y + j, z)
data[vi] = c_tree
end
minetest.add_node({x=pos.x,y=pos.y+j,z=pos.z},{name="default:tree"})
end
vm:set_data(data)
vm:write_to_map()
vm:update_map()
print ("[moonrealm] Appletree sapling grows")
end
@ -164,8 +195,8 @@ minetest.register_abm({
minetest.register_abm({
nodenames = {"moonrealm:sapling"},
interval = 57,
chance = 3,
interval = 31,
chance = 5,
action = function(pos, node, active_object_count, active_object_count_wider)
moonrealm_appletree(pos)
end,
@ -173,7 +204,7 @@ minetest.register_abm({
-- Singlenode option
local SINGLENODE = false
local SINGLENODE = true
if SINGLENODE then
minetest.register_on_mapgen_init(function(mgparams)

View File

@ -1,34 +1,35 @@
-- moonrealm 0.8.0 by paramat
-- For Minetest 0.4.9 dev with custom skybox commit
-- moonrealm 0.8.1 by paramat
-- For Minetest 0.4.10
-- Depends default
-- Licenses: code WTFPL, textures CC BY-SA
-- auto-set skybox and 'override day/night ratio' in singlenode and stacked realm modes
-- constant fissure width
-- speed increase by using voxelmanip for scanning chunk below / initialising stability table
-- LVM appletree, new design, spawn with LVM
-- TODO
-- on-dignode, air, hydroponics, soil drying by LVM too
-- Parameters
local XMIN = -8000 -- -- Approx horizontal limits. 1/4 of normal realm size.
local XMIN = -8000 -- Approx horizontal limits. 1/4 of normal realm size.
local XMAX = 8000
local ZMIN = -8000
local ZMAX = 8000
-- Change the 3 parameters below when changing between singlenode and stacked modes
local YMIN = -8000 -- Approx lower limit
local GRADCEN = 1 -- Gradient centre / terrain centre average level
local YMAX = 8000 -- Approx upper limit
local YMIN = 8000 -- -- Approx lower limit
local GRADCEN = 16000 -- -- Gradient centre / terrain centre average level
local YMAX = 24000 -- -- Approx upper limit
local FOOT = true -- -- Footprints in dust
local CENAMP = 64 -- -- Grad centre amplitude, terrain centre is varied by this
local HIGRAD = 128 -- -- Surface generating noise gradient above gradcen, controls depth of upper terrain
local LOGRAD = 128 -- -- Surface generating noise gradient below gradcen, controls depth of lower terrain
local HEXP = 0.5 -- -- Noise offset exponent above gradcen, 1 = normal 3D perlin terrain
local LEXP = 2 -- -- Noise offset exponent below gradcen
local STOT = 0.04 -- -- Stone density threshold, depth of dust
local ICECHA = 1 / (13*13*13) -- -- Ice chance per dust node at terrain centre, decreases with altitude
local ICEGRAD = 128 -- -- Ice gradient, vertical distance for no ice
local ORECHA = 7*7*7 -- -- Ore 1/x chance per stone node
local TFIS = 0.01 -- -- Fissure threshold. Controls size of fissures
local FOOT = true -- Footprints in dust
local CENAMP = 64 -- Grad centre amplitude, terrain centre is varied by this
local HIGRAD = 128 -- Surface generating noise gradient above gradcen, controls depth of upper terrain
local LOGRAD = 128 -- Surface generating noise gradient below gradcen, controls depth of lower terrain
local HEXP = 0.5 -- Noise offset exponent above gradcen, 1 = normal 3D perlin terrain
local LEXP = 2 -- Noise offset exponent below gradcen
local STOT = 0.04 -- Stone density threshold, depth of dust
local ICECHA = 1 / (13*13*13) -- Ice chance per dust node at terrain centre, decreases with altitude
local ICEGRAD = 128 -- Ice gradient, vertical distance for no ice
local ORECHA = 7*7*7 -- Ore 1/x chance per stone node
local TFIS = 0.01 -- Fissure threshold. Controls size of fissures
-- 3D noise for terrain
@ -237,14 +238,16 @@ minetest.register_on_generated(function(minp, maxp, seed)
local nid = 1 -- 2D noise index
local stable = {}
for z = z0, z1 do
local viu = area:index(x0, y0-1, z)
for x = x0, x1 do
local si = x - x0 + 1
local nodename = minetest.get_node({x=x,y=y0-1,z=z}).name
if nodename == "moonrealm:vacuum" then
local nodid = data[viu]
if nodid == c_vacuum then
stable[si] = false
else -- solid nodes and ignore in ungenerated chunks
stable[si] = true
end
viu = viu + 1
end
for y = y0, y1 do
local vi = area:index(x0, y, z) -- LVM index for first node in x row

View File

@ -235,8 +235,8 @@ minetest.register_node("moonrealm:sapling", {
sounds = default.node_sound_defaults(),
})
minetest.register_node("moonrealm:leaves", {
description = "MR Leaves",
minetest.register_node("moonrealm:appleleaf", {
description = "Appletree leaves",
drawtype = "allfaces_optional",
visual_scale = 1.3,
tiles = {"default_leaves.png"},
@ -247,7 +247,7 @@ minetest.register_node("moonrealm:leaves", {
max_items = 1,
items = {
{items = {"moonrealm:sapling"},rarity = 20,},
{items = {"moonrealm:leaves"},}
{items = {"moonrealm:appleleaf"},}
}
},
sounds = default.node_sound_leaves_defaults(),