mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2024-12-27 15:10:20 +01:00
Drop legacy support, use defaults snow.
This commit is contained in:
parent
bc276b44cf
commit
ad063c0b66
111
falling_snow.lua
111
falling_snow.lua
@ -1,69 +1,16 @@
|
||||
|
||||
if snow.enable_snowfall then
|
||||
|
||||
--Weather for legacy versions of minetest.
|
||||
local save_weather_legacy = function ()
|
||||
local file = io.open(minetest.get_worldpath().."/weather_v6", "w+")
|
||||
file:write(tostring(weather_legacy))
|
||||
file:close()
|
||||
end
|
||||
|
||||
local read_weather_legacy = function ()
|
||||
local file = io.open(minetest.get_worldpath().."/weather_v6", "r")
|
||||
if not file then return end
|
||||
local readweather = file:read()
|
||||
file:close()
|
||||
return readweather
|
||||
end
|
||||
|
||||
local weather_legacy = read_weather_legacy()
|
||||
|
||||
if snow.legacy then
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if weather_legacy == "snow" then
|
||||
if math.random(1, 10000) == 1 then
|
||||
weather_legacy = "none"
|
||||
save_weather_legacy()
|
||||
end
|
||||
else
|
||||
if math.random(1, 50000) == 2 then
|
||||
weather_legacy = "snow"
|
||||
save_weather_legacy()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
--Get snow at position.
|
||||
local get_snow = function(pos)
|
||||
if snow.legacy then
|
||||
--Legacy support.
|
||||
if weather_legacy == "snow" then
|
||||
local perlin1 = minetest.env:get_perlin(112,3, 0.5, 150)
|
||||
if perlin1:get2d( {x=pos.x, y=pos.z} ) > 0.53 then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
if minetest.get_heat(pos) <= 0 and minetest.get_humidity(pos) > 65 then
|
||||
return true
|
||||
else
|
||||
if minetest.get_heat(pos) <= 0 and minetest.get_humidity(pos) > 65 then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local addvectors = vector and vector.add
|
||||
|
||||
if snow.legacy then
|
||||
addvectors = function (v1, v2)
|
||||
return {x=v1.x+v2.x, y=v1.y+v2.y, z=v1.z+v2.z}
|
||||
end
|
||||
end
|
||||
|
||||
--Returns a random position between minp and maxp.
|
||||
local randpos = function (minp, maxp)
|
||||
@ -100,8 +47,8 @@ if snow.enable_snowfall then
|
||||
if animate then
|
||||
local minp = addvectors(spos, {x=-9, y=3, z=-9})
|
||||
local maxp = addvectors(spos, {x= 9, y=5, z= 9})
|
||||
local vel = {x=0, y= -0.5, z=0}
|
||||
local acc = {x=0, y= -0.5, z=0}
|
||||
local vel = {x=0, y= -1, z=-1}
|
||||
local acc = {x=0, y= 0, z=0}
|
||||
minetest.add_particlespawner(3, 0.5,
|
||||
minp, maxp,
|
||||
vel, vel,
|
||||
@ -131,28 +78,36 @@ if snow.enable_snowfall then
|
||||
local minp_deep = addvectors(ppos, {x=-5, y=3.2, z=-5})
|
||||
local maxp_deep = addvectors(ppos, {x= 5, y=1.6, z= 5})
|
||||
|
||||
local vel = {x=0, y= -0.5, z=0}
|
||||
local acc = {x=0, y= -0.5, z=0}
|
||||
local vel = {x=0, y= -1, z=-1}
|
||||
local acc = {x=0, y= 0, z=0}
|
||||
|
||||
if not snow.lighter_snowfall then
|
||||
minetest.add_particlespawner(5, 0.5,
|
||||
minp, maxp,
|
||||
vel, vel,
|
||||
acc, acc,
|
||||
5, 5,
|
||||
25, 25,
|
||||
false, "weather_snow.png", player:get_player_name())
|
||||
|
||||
minetest.add_particlespawner(5, 0.5,
|
||||
minp, maxp,
|
||||
vel, vel,
|
||||
acc, acc,
|
||||
5, 5,
|
||||
25, 25,
|
||||
false, "weather_snow.png", player:get_player_name())
|
||||
|
||||
minetest.add_particlespawner(4, 0.5,
|
||||
minp_deep, maxp_deep,
|
||||
vel, vel,
|
||||
acc, acc,
|
||||
4, 4,
|
||||
25, 25,
|
||||
false, "weather_snow.png", player:get_player_name())
|
||||
|
||||
if math.random(1,5) == 4 then
|
||||
snow_fall(randpos(sminp, smaxp), player)
|
||||
minetest.add_particlespawner(4, 0.5,
|
||||
minp_deep, maxp_deep,
|
||||
vel, vel,
|
||||
acc, acc,
|
||||
4, 4,
|
||||
25, 25,
|
||||
false, "weather_snow.png", player:get_player_name())
|
||||
|
||||
if math.random(1,5) == 4 then
|
||||
snow_fall(randpos(sminp, smaxp), player)
|
||||
end
|
||||
else
|
||||
if math.random(1,5) == 4 then
|
||||
snow_fall(randpos(sminp, smaxp), player, true)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
|
||||
if math.random(1,5) == 4 then
|
||||
|
237
init.lua
237
init.lua
@ -26,6 +26,7 @@ local needles = {
|
||||
drawtype = "allfaces_optional",
|
||||
visual_scale = 1.3,
|
||||
tiles = {"snow_needles.png"},
|
||||
waving = 1,
|
||||
paramtype = "light",
|
||||
groups = {snappy=3, leafdecay=3, flammable=2},
|
||||
drop = {
|
||||
@ -111,6 +112,7 @@ minetest.register_node("snow:sapling_pine", {
|
||||
walkable = false,
|
||||
groups = {snappy=2,dig_immediate=3,flammable=2},
|
||||
sounds = default.node_sound_defaults(),
|
||||
|
||||
})
|
||||
|
||||
minetest.register_node("snow:star", {
|
||||
@ -201,149 +203,101 @@ minetest.register_craftitem("snow:snowball", {
|
||||
on_use = snow_shoot_snowball,
|
||||
})
|
||||
|
||||
for i=1,8 do
|
||||
local snow_box =
|
||||
{
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5 + i/9., 0.5}
|
||||
}
|
||||
minetest.register_node("snow:snow"..(tostring(i) ~= "1" and tostring(i) or ""), {
|
||||
description = "Snow",
|
||||
tiles = {"snow_snow.png"},
|
||||
drawtype = "nodebox",
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 == "leveled",
|
||||
groups = {crumbly=3,melts=3,falling_node=1,not_in_creative_inventory=1},
|
||||
buildable_to = true,
|
||||
drop = {
|
||||
max_items = 2,
|
||||
items = {
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'snow:moss'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'snow:snowball'},
|
||||
}
|
||||
}
|
||||
},
|
||||
leveled = 7*i,
|
||||
drawtype = "nodebox",
|
||||
node_box = snow_box,
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.45},
|
||||
}),
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
||||
minetest.add_node(pos, {name="snow:dirt_with_snow"})
|
||||
end
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "snow:dirt_with_snow" then
|
||||
minetest.add_node(pos, {name="default:dirt_with_grass"})
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if not snow.legacy then
|
||||
--Snow.
|
||||
minetest.register_node("snow:snow", {
|
||||
description = "Snow",
|
||||
tiles = {"snow_snow.png"},
|
||||
drawtype = "nodebox",
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 == "leveled",
|
||||
groups = {crumbly=3,melts=3,falling_node=1,not_in_creative_inventory=1},
|
||||
buildable_to = true,
|
||||
drop = {
|
||||
max_items = 2,
|
||||
items = {
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'snow:moss'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'snow:snowball'},
|
||||
}
|
||||
}
|
||||
},
|
||||
leveled = 7,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "leveled",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.5, 0.5, -0.5+2/16, 0.5},
|
||||
--Backwards Compatability.
|
||||
minetest.register_abm({
|
||||
nodenames = {"snow:snow1","snow:snow2","snow:snow3","gsnow4","snow:snow5","snow:snow6","snow:snow7","snow:snow8"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local level = 7*(tonumber(node.name:sub(-1)))
|
||||
minetest.add_node(pos,{name="default:snow"})
|
||||
minetest.set_node_level(pos, level)
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_alias("snow:snow", "default:snow")
|
||||
minetest.register_alias("snow:ice", "default:ice")
|
||||
minetest.register_alias("snow:dirt_with_snow", "default:dirt_with_snow")
|
||||
minetest.register_alias("snow:snow_block", "default:snowblock")
|
||||
minetest.register_alias("snow:ice", "default:ice")
|
||||
|
||||
|
||||
--Snow.
|
||||
minetest.register_node(":default:snow", {
|
||||
description = "Snow",
|
||||
tiles = {"default_snow.png"},
|
||||
drawtype = "nodebox",
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 == "leveled",
|
||||
groups = {crumbly=3,melts=3,falling_node=1,not_in_creative_inventory=1},
|
||||
buildable_to = true,
|
||||
freezemelt = "default:water_flowing",
|
||||
drop = {
|
||||
max_items = 2,
|
||||
items = {
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'snow:moss'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'snow:snowball'},
|
||||
}
|
||||
}
|
||||
},
|
||||
leveled = 7,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "leveled",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.5, 0.5, -0.5+2/16, 0.5},
|
||||
},
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.45},
|
||||
}),
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
||||
minetest.add_node(pos, {name="snow:dirt_with_snow"})
|
||||
end
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "snow:dirt_with_snow" then
|
||||
minetest.add_node(pos, {name="default:dirt_with_grass"})
|
||||
end
|
||||
end,
|
||||
})
|
||||
else
|
||||
minetest.add_node_level = function(pos, amount)
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == "snow:snow" then
|
||||
minetest.add_node(pos,{name="snow:snow2"})
|
||||
elseif node.name:find("snow:snow") and node.name:sub(-1)~="8" then
|
||||
minetest.add_node(pos,{name="snow:snow"..tonumber(node.name:sub(-1))+1})
|
||||
},
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.45},
|
||||
}),
|
||||
on_construct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
||||
minetest.add_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
minetest.get_node_level = function(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == "snow:snow" then
|
||||
return 7
|
||||
elseif node.name:find("snow:snow") and node.name:sub(-1) then
|
||||
return 7*(tonumber(node.name:sub(-1)))
|
||||
end,
|
||||
after_destruct = function(pos)
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_snow" then
|
||||
minetest.add_node(pos, {name="default:dirt_with_grass"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
function snow.place(pos)
|
||||
local node = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
|
||||
local node = minetest.get_node(pos)
|
||||
local drawtype = minetest.registered_nodes[node.name].drawtype
|
||||
|
||||
local bnode = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
|
||||
if node.name:find("snow:snow") and minetest.get_node_level(pos) < 63 then
|
||||
if node.name == "default:snow" and minetest.get_node_level(pos) < 63 then
|
||||
if minetest.get_item_group(bnode.name, "leafdecay") == 0 and snow.is_uneven(pos) ~= true then
|
||||
minetest.add_node_level(pos, 7)
|
||||
end
|
||||
elseif node.name:find("snow:snow") and minetest.get_node_level(pos) == 63 then
|
||||
elseif node.name == "default:snow" and minetest.get_node_level(pos) == 63 then
|
||||
local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass")
|
||||
if p and minetest.get_node_light(p, 0.5) == 15 then
|
||||
minetest.add_node(p,{name="snow:snow"})
|
||||
minetest.add_node(p,{name="default:snow"})
|
||||
else
|
||||
minetest.add_node(pos,{name="snow:snowblock"})
|
||||
minetest.add_node(pos,{name="default:snowblock"})
|
||||
end
|
||||
elseif node.name ~= "snow:ice" and node.name ~= "air" then
|
||||
elseif node.name ~= "default:ice" and bnode.name ~= "air" then
|
||||
if drawtype == "normal" or drawtype == "allfaces_optional" then
|
||||
minetest.add_node({x=pos.x,y=pos.y+1,z=pos.z}, {name="snow:snow"})
|
||||
minetest.add_node({x=pos.x,y=pos.y+1,z=pos.z}, {name="default:snow"})
|
||||
elseif drawtype == "plantlike" then
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
||||
minetest.add_node(pos, {name="snow:dirt_with_snow"})
|
||||
minetest.add_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -368,18 +322,18 @@ snow.is_uneven = function(pos)
|
||||
|
||||
if drawtype == "plantlike" then
|
||||
if bnode.name == "default:dirt_with_grass" then
|
||||
add_node({x=pos.x+x,y=pos.y-1,z=pos.z+z}, {name="snow:dirt_with_snow"})
|
||||
add_node({x=pos.x+x,y=pos.y-1,z=pos.z+z}, {name="default:dirt_with_snow"})
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if (not(x == 0 and y == 0)) and node.name == "snow:snow" and minetest.get_node_level({x=pos.x+x,y=pos.y,z=pos.z+z}) < num then
|
||||
if (not(x == 0 and y == 0)) and node.name == "default:snow" and minetest.get_node_level({x=pos.x+x,y=pos.y,z=pos.z+z}) < num then
|
||||
found = true
|
||||
foundx = x
|
||||
foundz=z
|
||||
elseif node.name == "air" and bnode.name ~= "air" then
|
||||
if not (bnode.name:find("snow:snow")) then
|
||||
snow.place({x=pos.x+x,y=pos.y,z=pos.z+z})
|
||||
if not (bnode.name == "default:snow") then
|
||||
snow.place({x=pos.x+x,y=pos.y-1,z=pos.z+z})
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -396,9 +350,9 @@ snow.is_uneven = function(pos)
|
||||
end
|
||||
|
||||
--Snow with dirt.
|
||||
minetest.register_node("snow:dirt_with_snow", {
|
||||
minetest.register_node(":default:dirt_with_snow", {
|
||||
description = "Dirt with Snow",
|
||||
tiles = {"snow_snow.png", "default_dirt.png", "default_dirt.png^snow_snow_side.png"},
|
||||
tiles = {"default_snow.png", "default_dirt.png", "default_dirt.png^snow_snow_side.png"},
|
||||
is_ground_content = true,
|
||||
groups = {crumbly=3},
|
||||
drop = 'default:dirt',
|
||||
@ -408,12 +362,13 @@ minetest.register_node("snow:dirt_with_snow", {
|
||||
})
|
||||
|
||||
--Snow block.
|
||||
minetest.register_node("snow:snow_block", {
|
||||
minetest.register_node(":default:snowblock", {
|
||||
description = "Snow",
|
||||
tiles = {"snow_snow.png"},
|
||||
tiles = {"default_snow.png"},
|
||||
freezemelt = "default:water_source",
|
||||
is_ground_content = true,
|
||||
groups = {crumbly=3,melts=2,falling_node=1},
|
||||
drop = 'snow:snow_block',
|
||||
drop = 'default:snowblock',
|
||||
sounds = default.node_sound_dirt_defaults({
|
||||
footstep = {name="default_snow_footstep", gain=0.4},
|
||||
}),
|
||||
@ -431,20 +386,6 @@ minetest.register_node("snow:snow_brick", {
|
||||
}),
|
||||
})
|
||||
|
||||
--Ice.
|
||||
minetest.register_node("snow:ice", {
|
||||
description = "Ice",
|
||||
tiles = {"snow_ice.png"},
|
||||
is_ground_content = true,
|
||||
groups = {snappy=2,cracky=3,melts=1},
|
||||
drop = 'snow:ice',
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
sounds = default.node_sound_glass_defaults({
|
||||
footstep = {name="default_stone_footstep", gain=0.4},
|
||||
}),
|
||||
})
|
||||
|
||||
--Moss.
|
||||
minetest.register_node("snow:moss", {
|
||||
description = "Moss",
|
||||
@ -471,8 +412,8 @@ minetest.register_craft({
|
||||
minetest.register_craft({
|
||||
output = 'snow:snow_brick',
|
||||
recipe = {
|
||||
{'snow:snow_block', 'snow:snow_block'},
|
||||
{'snow:snow_block', 'snow:snow_block'},
|
||||
{'default:snowblock', 'default:snowblock'},
|
||||
{'default:snowblock', 'default:snowblock'},
|
||||
},
|
||||
})
|
||||
|
||||
@ -513,11 +454,11 @@ minetest.register_abm({
|
||||
--Water freezes when in contact with snow.
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:water_source"},
|
||||
neighbors = {"snow:snow", "snow:snow_block"},
|
||||
neighbors = {"default:snow", "default:snowblock"},
|
||||
interval = 20,
|
||||
chance = 4,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
minetest.add_node(pos,{name="snow:ice"})
|
||||
minetest.add_node(pos,{name="default:ice"})
|
||||
end,
|
||||
})
|
||||
|
||||
|
81
mapgen.lua
81
mapgen.lua
@ -1,25 +1,20 @@
|
||||
local mgname = ""
|
||||
|
||||
--Identify the mapgen.
|
||||
if minetest.register_on_mapgen_init then
|
||||
minetest.register_on_mapgen_init(function(MapgenParams)
|
||||
if MapgenParams.mgname then
|
||||
mgname = MapgenParams.mgname
|
||||
else
|
||||
io.write("[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!\n")
|
||||
end
|
||||
if mgname == "v7" then
|
||||
--Load mapgen_v7 compatibility.
|
||||
dofile(minetest.get_modpath("snow").."/mapgen_v7.lua")
|
||||
else
|
||||
--Load mapgen_v6 compatibility.
|
||||
dofile(minetest.get_modpath("snow").."/mapgen_v6.lua")
|
||||
end
|
||||
end)
|
||||
else
|
||||
--Fall back to mapgen_v6.
|
||||
dofile(minetest.get_modpath("snow").."/mapgen_v6.lua")
|
||||
end
|
||||
minetest.register_on_mapgen_init(function(MapgenParams)
|
||||
if MapgenParams.mgname then
|
||||
mgname = MapgenParams.mgname
|
||||
else
|
||||
io.write("[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!\n")
|
||||
end
|
||||
if mgname == "v7" then
|
||||
--Load mapgen_v7 compatibility.
|
||||
dofile(minetest.get_modpath("snow").."/mapgen_v7.lua")
|
||||
else
|
||||
--Load mapgen_v6 compatibility.
|
||||
dofile(minetest.get_modpath("snow").."/mapgen_v6.lua")
|
||||
end
|
||||
end)
|
||||
|
||||
local pine_tree = {
|
||||
axiom="TABff",
|
||||
@ -46,55 +41,9 @@ local xmas_tree = {
|
||||
thin_branches=true,
|
||||
}
|
||||
|
||||
--Makes pine tree
|
||||
function snow.make_pine(pos,snow,xmas)
|
||||
local env = minetest.env
|
||||
local perlin1 = env:get_perlin(112,3, 0.5, 150)
|
||||
local try_node = function(pos, node)
|
||||
local n = env:get_node(pos).name
|
||||
if n == "air" or n == "ignore" then
|
||||
env:add_node(pos,node)
|
||||
end
|
||||
end
|
||||
--Clear ground.
|
||||
for x=-1,1 do
|
||||
for z=-1,1 do
|
||||
if env:get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "snow:snow" then
|
||||
env:remove_node({x=pos.x+x,y=pos.y,z=pos.z+z})
|
||||
end
|
||||
if env:get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "snow:snow_block" then
|
||||
env:remove_node({x=pos.x+x,y=pos.y,z=pos.z+z})
|
||||
end
|
||||
end
|
||||
end
|
||||
if xmas then
|
||||
env:remove_node(pos)
|
||||
minetest.env:spawn_tree(pos, xmas_tree)
|
||||
else
|
||||
minetest.env:spawn_tree(pos, pine_tree)
|
||||
end
|
||||
if snow then
|
||||
local x,z = pos.x,pos.z
|
||||
try_node({x=x+1,y=pos.y+3,z=z+1},{name="snow:snow"})
|
||||
try_node({x=x-1,y=pos.y+3,z=z-1},{name="snow:snow"})
|
||||
try_node({x=x-1,y=pos.y+3,z=z+1},{name="snow:snow"})
|
||||
try_node({x=x+1,y=pos.y+3,z=z-1},{name="snow:snow"})
|
||||
|
||||
try_node({x=x+1,y=pos.y+5,z=z},{name="snow:snow"})
|
||||
try_node({x=x-1,y=pos.y+5,z=z},{name="snow:snow"})
|
||||
try_node({x=x,y=pos.y+5,z=z+1},{name="snow:snow"})
|
||||
try_node({x=x,y=pos.y+5,z=z-1},{name="snow:snow"})
|
||||
end
|
||||
if xmas then
|
||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star"})
|
||||
elseif snow and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:snow"})
|
||||
end
|
||||
end
|
||||
|
||||
--Makes pine tree
|
||||
function snow.voxelmanip_pine(pos,a,data)
|
||||
local c_snow = minetest.get_content_id("snow:snow")
|
||||
local c_snow = minetest.get_content_id("default:snow")
|
||||
local c_pine_needles = minetest.get_content_id("snow:needles")
|
||||
local c_tree = minetest.get_content_id("default:tree")
|
||||
local c_air = minetest.get_content_id("air")
|
||||
|
743
mapgen_v6.lua
743
mapgen_v6.lua
@ -1,520 +1,279 @@
|
||||
if snow.legacy then
|
||||
--Snow biomes are found at 0.53 and greater perlin noise.
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
if maxp.y >= -10 and maxp.y > snow.min_height then
|
||||
local debug = snow.debug
|
||||
local min_height = snow.min_height
|
||||
|
||||
--Should make things a bit faster.
|
||||
local env = minetest.env
|
||||
--Identify content ID's of nodes
|
||||
local c_dirt_with_grass = minetest.get_content_id("default:dirt_with_grass")
|
||||
local c_snow = minetest.get_content_id("default:snow")
|
||||
local c_snow_block = minetest.get_content_id("default:snowblock")
|
||||
local c_dirt_with_snow = 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 c_stone = minetest.get_content_id("default:stone")
|
||||
local c_dry_shrub = minetest.get_content_id("default:dry_shrub")
|
||||
local c_leaves = minetest.get_content_id("default:leaves")
|
||||
local c_jungleleaves = minetest.get_content_id("default:jungleleaves")
|
||||
local c_junglegrass = minetest.get_content_id("default:junglegrass")
|
||||
local c_ice = minetest.get_content_id("default:ice")
|
||||
local c_water = minetest.get_content_id("default:water_source")
|
||||
local c_papyrus = minetest.get_content_id("default:papyrus")
|
||||
local c_sand = minetest.get_content_id("default:sand")
|
||||
|
||||
--Get map specific perlin
|
||||
local perlin1 = env:get_perlin(112,3, 0.5, 150)
|
||||
--Snow biomes are found at 0.53 and greater perlin noise.
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
--if maxp.y >= -10 and maxp.y > snow.min_height then
|
||||
|
||||
--Start timer
|
||||
local t1 = os.clock()
|
||||
local in_biome = false
|
||||
|
||||
--Load Voxel Manipulator
|
||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||
local a = VoxelArea:new{
|
||||
MinEdge={x=emin.x, y=emin.y, z=emin.z},
|
||||
MaxEdge={x=emax.x, y=emax.y, z=emax.z},
|
||||
}
|
||||
local data = vm:get_data()
|
||||
|
||||
local debug = snow.debug
|
||||
local min_height = snow.min_height
|
||||
|
||||
-- Assume X and Z lengths are equal
|
||||
local divlen = 16
|
||||
local divs = (maxp.x-minp.x);
|
||||
local x0 = minp.x
|
||||
local z0 = minp.z
|
||||
local x1 = maxp.x
|
||||
local z1 = maxp.z
|
||||
--Should make things a bit faster.
|
||||
local env = minetest.env
|
||||
|
||||
|
||||
-- Assume X and Z lengths are equal
|
||||
local divlen = 16
|
||||
local divs = (maxp.x-minp.x)+1;
|
||||
local x0 = minp.x
|
||||
local z0 = minp.z
|
||||
local x1 = maxp.x
|
||||
local z1 = maxp.z
|
||||
|
||||
--Speed hack: checks the corners and middle of the chunk for "snow biome".
|
||||
if not ( perlin1:get2d( {x=x0, y=z0} ) > 0.53 ) --top left
|
||||
and not ( perlin1:get2d( { x = x0 + ( (x1-x0)/2), y=z0 } ) > 0.53 )--top middle
|
||||
and not (perlin1:get2d({x=x1, y=z1}) > 0.53) --bottom right
|
||||
and not (perlin1:get2d({x=x1, y=z0+((z1-z0)/2)}) > 0.53) --right middle
|
||||
and not (perlin1:get2d({x=x0, y=z1}) > 0.53) --bottom left
|
||||
and not (perlin1:get2d({x=x1, y=z0}) > 0.53) --top right
|
||||
and not (perlin1:get2d({x=x0+((x1-x0)/2), y=z1}) > 0.53) --left middle
|
||||
and not (perlin1:get2d({x=(x1-x0)/2, y=(z1-z0)/2}) > 0.53) --middle
|
||||
and not (perlin1:get2d({x=x0, y=z1+((z1-z0)/2)}) > 0.53) then --bottom middle
|
||||
return
|
||||
|
||||
--Get map specific perlin noise.
|
||||
local perlin1 = env:get_perlin(112,3, 0.5, 150)
|
||||
|
||||
--Speed hack: checks the corners and middle of the chunk for "snow biome".
|
||||
--[[if not ( perlin1:get2d( {x=x0, y=z0} ) > 0.53 ) --top left
|
||||
and not ( perlin1:get2d( { x = x0 + ( (x1-x0)/2), y=z0 } ) > 0.53 )--top middle
|
||||
and not (perlin1:get2d({x=x1, y=z1}) > 0.53) --bottom right
|
||||
and not (perlin1:get2d({x=x1, y=z0+((z1-z0)/2)}) > 0.53) --right middle
|
||||
and not (perlin1:get2d({x=x0, y=z1}) > 0.53) --bottom left
|
||||
and not (perlin1:get2d({x=x1, y=z0}) > 0.53) --top right
|
||||
and not (perlin1:get2d({x=x0+((x1-x0)/2), y=z1}) > 0.53) --left middle
|
||||
and not (perlin1:get2d({x=(x1-x0)/2, y=(z1-z0)/2}) > 0.53) --middle
|
||||
and not (perlin1:get2d({x=x0, y=z1+((z1-z0)/2)}) > 0.53) then --bottom middle
|
||||
return
|
||||
end]]
|
||||
|
||||
--Choose a biome types.
|
||||
local pr = PseudoRandom(seed+57)
|
||||
local biome
|
||||
|
||||
--Land biomes
|
||||
biome = pr:next(1, 5)
|
||||
local snowy = biome == 1 --spawns alot of snow
|
||||
local plain = biome == 2 --spawns not much
|
||||
local alpine = biome == 3 --rocky terrain
|
||||
-- biome == 4 or biome == 5 -- normal biome
|
||||
|
||||
--Water biomes
|
||||
biome2 = pr:next(1, 5)
|
||||
local cool = biome == 1 --only spawns ice on edge of water
|
||||
local icebergs = biome == 2
|
||||
local icesheet = biome == 3
|
||||
local icecave = biome == 4
|
||||
local icehole = biome == 5 --icesheet with holes
|
||||
|
||||
--Misc biome settings.
|
||||
local icy = pr:next(1, 2) == 2 --If enabled spawns ice in sand instead of snow blocks.
|
||||
local mossy = pr:next(1,2) == 1 --Spawns moss in snow.
|
||||
local shrubs = pr:next(1,2) == 1 --Spawns dry shrubs in snow.
|
||||
local pines = pr:next(1,2) == 1 --spawns pines.
|
||||
|
||||
--Debugging function
|
||||
local biomeToString = function(num,num2)
|
||||
local biome, biome2
|
||||
if num == 1 then biome = "snowy"
|
||||
elseif num == 2 then biome = "plain"
|
||||
elseif num == 3 then biome = "alpine"
|
||||
elseif num == 4 or num == 5 then biome = "normal"
|
||||
else biome = "unknown "..num end
|
||||
|
||||
if num2 == 1 then biome2 = "cool"
|
||||
elseif num2 == 2 then biome2 = "icebergs"
|
||||
elseif num2 == 3 then biome2 = "icesheet"
|
||||
elseif num2 == 4 then biome2 = "icecave"
|
||||
elseif num2 == 5 then biome2 = "icehole"
|
||||
else biome2 = "unknown "..num end
|
||||
|
||||
return biome, biome2
|
||||
end
|
||||
|
||||
local spawn_pine = snow.voxelmanip_pine
|
||||
local smooth = snow.smooth_biomes
|
||||
local legacy = snow.legacy
|
||||
|
||||
--Reseed random.
|
||||
pr = PseudoRandom(seed+68)
|
||||
|
||||
--[[if alpine then
|
||||
local trees = env:find_nodes_in_area(minp, maxp, {"default:leaves","default:tree"})
|
||||
for i,v in pairs(trees) do
|
||||
env:remove_node(v)
|
||||
end
|
||||
end]]
|
||||
|
||||
--Loop through chunk.
|
||||
for x = minp.x, maxp.x do
|
||||
for z = minp.z, maxp.z do
|
||||
|
||||
--Choose a biome types.
|
||||
local pr = PseudoRandom(seed+57)
|
||||
local biome
|
||||
--Check if we are in a "Snow biome"
|
||||
local in_biome = false
|
||||
local test = perlin1:get2d({x=x, y=z})
|
||||
if smooth and (not snowy) and (test > 0.73 or (test > 0.43 and pr:next(0,29) > (0.73 - test) * 100 )) then
|
||||
in_biome = true
|
||||
elseif (not smooth or snowy) and test > 0.53 then
|
||||
in_biome = true
|
||||
end
|
||||
|
||||
--Land biomes
|
||||
biome = pr:next(1, 5)
|
||||
local snowy = biome == 1 --spawns alot of snow
|
||||
local plain = biome == 2 --spawns not much
|
||||
local alpine = biome == 3 --rocky terrain
|
||||
-- biome == 4 or biome == 5 -- normal biome
|
||||
|
||||
--Water biomes
|
||||
biome2 = pr:next(1, 5)
|
||||
local cool = biome == 1 --only spawns ice on edge of water
|
||||
local icebergs = biome == 2
|
||||
local icesheet = biome == 3
|
||||
local icecave = biome == 4
|
||||
local icehole = biome == 5 --icesheet with holes
|
||||
if in_biome then
|
||||
|
||||
local perlin2 = env:get_perlin(322345,3, 0.5, 80)
|
||||
local icetype = perlin2:get2d({x=x, y=z})
|
||||
local cool = icetype > 0 --only spawns ice on edge of water
|
||||
local icebergs = icetype > -0.2 and icetype <= 0
|
||||
local icehole = icetype > -0.4 and icetype <= -0.2
|
||||
local icesheet = icetype > -0.6 and icetype <= -0.4
|
||||
local icecave = icetype <= -0.6
|
||||
|
||||
--Misc biome settings.
|
||||
local icy = pr:next(1, 2) == 2 --If enabled spawns ice in sand instead of snow blocks.
|
||||
local mossy = pr:next(1,2) == 1 --Spawns moss in snow.
|
||||
local shrubs = pr:next(1,2) == 1 --Spawns dry shrubs in snow.
|
||||
local pines = pr:next(1,2) == 1 --spawns pines.
|
||||
--if not plain or pr:next(1,12) == 1 then
|
||||
|
||||
--Debugging function
|
||||
local biomeToString = function(num,num2)
|
||||
local biome, biome2
|
||||
if num == 1 then biome = "snowy"
|
||||
elseif num == 2 then biome = "plain"
|
||||
elseif num == 3 then biome = "alpine"
|
||||
elseif num == 4 or num == 5 then biome = "normal"
|
||||
else biome = "unknown "..num end
|
||||
|
||||
if num2 == 1 then biome2 = "cool"
|
||||
elseif num2 == 2 then biome2 = "icebergs"
|
||||
elseif num2 == 3 then biome2 = "icesheet"
|
||||
elseif num2 == 4 then biome2 = "icecave"
|
||||
elseif num2 == 5 then biome2 = "icehole"
|
||||
else biome2 = "unknown "..num end
|
||||
|
||||
return biome, biome2
|
||||
end
|
||||
|
||||
local make_pine = snow.make_pine
|
||||
local smooth = snow.smooth_biomes
|
||||
local legacy = snow.legacy
|
||||
|
||||
--Reseed random.
|
||||
pr = PseudoRandom(seed+68)
|
||||
|
||||
if alpine then
|
||||
local trees = env:find_nodes_in_area(minp, maxp, {"default:leaves","default:tree", "default:apple"})
|
||||
for i,v in pairs(trees) do
|
||||
env:remove_node(v)
|
||||
end
|
||||
end
|
||||
|
||||
--Loop through chunk.
|
||||
for j=0,divs do
|
||||
for i=0,divs do
|
||||
|
||||
local x = x0+i
|
||||
local z = z0+j
|
||||
|
||||
--Check if we are in a "Snow biome"
|
||||
local in_biome = false
|
||||
local test = perlin1:get2d({x=x+150, y=z+50})
|
||||
if smooth and (not snowy) and (test < -0.73 or (test < -0.43 and pr:next(0,29) < (-0.73 + test) * 100 )) then
|
||||
in_biome = true
|
||||
elseif (not smooth or snowy) and test < -0.53 then
|
||||
in_biome = true
|
||||
end
|
||||
|
||||
if in_biome then
|
||||
|
||||
if not plain or pr:next(1,12) == 1 then
|
||||
|
||||
-- Find ground level (0...15)
|
||||
local ground_y = nil
|
||||
for y=maxp.y,minp.y+1,-1 do
|
||||
if env:get_node({x=x,y=y,z=z}).name ~= "air" then
|
||||
ground_y = y
|
||||
break
|
||||
end
|
||||
-- Find ground level (0...15)
|
||||
local ground_y = nil
|
||||
for y=maxp.y,minp.y,-1 do
|
||||
local n = data[a:index(x, y, z)]
|
||||
if n ~= c_air and n ~= c_ignore then
|
||||
ground_y = y
|
||||
break
|
||||
end
|
||||
|
||||
if ground_y and ground_y > min_height then
|
||||
end
|
||||
|
||||
if ground_y then --and ground_y > min_height then
|
||||
|
||||
-- Snowy biome stuff
|
||||
local node = env:get_node({x=x,y=ground_y,z=z})
|
||||
-- Snowy biome stuff
|
||||
local node = a:index(x, ground_y, z)
|
||||
local abovenode = a:index(x, ground_y+1, z)
|
||||
local belownode = a:index(x, ground_y+2, z)
|
||||
|
||||
if ground_y and (node.name == "default:dirt_with_grass" or node.name == "default:junglegrass") then
|
||||
local veg
|
||||
if legacy and mossy and pr:next(1,10) == 1 then veg = 1 end
|
||||
if alpine then
|
||||
--Gets rid of dirt
|
||||
env:add_node({x=x,y=ground_y+1,z=z}, {name="snow:snow", param2=veg})
|
||||
for y=ground_y,-6,-1 do
|
||||
if env:get_node({x=x,y=y,z=z}) and env:get_node({x=x,y=y,z=z}).name == "default:stone" then
|
||||
break
|
||||
else
|
||||
env:add_node({x=x,y=y,z=z},{name="default:stone"})
|
||||
end
|
||||
end
|
||||
elseif (shrubs and pr:next(1,28) == 1) or node.name == "default:junglegrass" then
|
||||
--Spawns dry shrubs.
|
||||
env:add_node({x=x,y=ground_y,z=z}, {name="snow:dirt_with_snow"})
|
||||
if snowy then
|
||||
env:add_node({x=x,y=ground_y+1,z=z}, {name="snow:snow_block"})
|
||||
if ground_y and data[node] == c_dirt_with_grass then
|
||||
--local veg
|
||||
--if legacy and mossy and pr:next(1,10) == 1 then veg = 1 end
|
||||
if alpine then
|
||||
--Gets rid of dirt
|
||||
data[abovenode] = c_snow
|
||||
for y=ground_y,-6,-1 do
|
||||
local stone = a:index(x, y, z)
|
||||
if data[stone] == "default:stone" then
|
||||
break
|
||||
else
|
||||
env:add_node({x=x,y=ground_y+1,z=z}, {name="default:dry_shrub"})
|
||||
data[stone] = c_stone
|
||||
end
|
||||
elseif pines and pr:next(1,36) == 1 then
|
||||
--Spawns pines.
|
||||
env:add_node({x=x,y=ground_y,z=z}, {name="default:dirt_with_grass"})
|
||||
make_pine({x=x,y=ground_y+1,z=z},true)
|
||||
elseif snowy then
|
||||
--Spawns snow blocks.
|
||||
env:add_node({x=x,y=ground_y+1,z=z}, {name="snow:snow_block"})
|
||||
env:add_node({x=x,y=ground_y+2,z=z}, {name="snow:snow", param2=veg})
|
||||
else
|
||||
--Spawns snow.
|
||||
env:add_node({x=x,y=ground_y,z=z}, {name="snow:dirt_with_snow"})
|
||||
env:add_node({x=x,y=ground_y+1,z=z}, {name="snow:snow", param2=veg})
|
||||
end
|
||||
elseif ground_y and node.name == "default:sand" then
|
||||
--Spawns ice in sand if icy, otherwise spawns snow on top.
|
||||
if not icy then
|
||||
env:add_node({x=x,y=ground_y+1,z=z}, {name="snow:snow"})
|
||||
env:add_node({x=x,y=ground_y,z=z}, {name="snow:snow_block"})
|
||||
elseif (shrubs and pr:next(1,28) == 1) then
|
||||
--Spawns dry shrubs.
|
||||
data[node] = c_dirt_with_snow
|
||||
data[abovenode] = c_dry_shrub
|
||||
elseif pines and pr:next(1,36) == 1 then
|
||||
--Spawns pines.
|
||||
data[node] = c_dirt_with_snow
|
||||
spawn_pine({x=x, y=ground_y+1, z=z},a,data)
|
||||
--elseif snowy then
|
||||
--Spawns snow blocks.
|
||||
--env:add_node({x=x,y=ground_y+1,z=z}, {name="snow:snow_block"})
|
||||
--data[aanode] = c_snow
|
||||
else
|
||||
env:add_node({x=x,y=ground_y,z=z}, {name="snow:ice"})
|
||||
--Spawns snow.
|
||||
data[node] = c_dirt_with_snow
|
||||
data[abovenode] = c_snow
|
||||
end
|
||||
elseif ground_y and env:get_node({x=x,y=ground_y,z=z}).name == "default:leaves" then
|
||||
env:add_node({x=x,y=ground_y+1,z=z}, {name="snow:snow"})
|
||||
elseif ground_y and env:get_node({x=x,y=ground_y,z=z}).name == "default:papyrus" then
|
||||
for i=ground_y, ground_y-4, -1 do
|
||||
if env:get_node({x=x,y=i,z=z}).name == "default:papyrus" then
|
||||
env:add_node({x=x,y=ground_y+1,z=z}, {name="snow:snow"})
|
||||
env:add_node({x=x,y=i,z=z}, {name="snow:snow_block", param2=2})
|
||||
end
|
||||
elseif ground_y and data[belownode] == c_sand then
|
||||
--Spawns ice in sand if icy, otherwise spawns snow on top.
|
||||
if not icy then
|
||||
data[node] = c_snow
|
||||
else
|
||||
data[belownode] = c_ice
|
||||
end
|
||||
elseif ground_y and data[node] == c_leaves or data[node] == c_jungleleaves then
|
||||
data[abovenode] = c_snow
|
||||
elseif ground_y and data[node] == c_junglegrass then
|
||||
data[node] = c_dry_shrub
|
||||
elseif ground_y and data[node] == c_papyrus then
|
||||
for i=ground_y, ground_y-4, -1 do
|
||||
local papyrus = a:index(x, y, z)
|
||||
if data[papyrus] == c_papyrus then
|
||||
local papyrusabove = a:index(x, ground_y, z)
|
||||
data[papyrusabove] = c_snow
|
||||
data[papyrus] = c_snow_block
|
||||
end
|
||||
elseif ground_y and node.name == "default:water_source" then
|
||||
if not icesheet and not icecave and not icehole then
|
||||
--Coastal ice.
|
||||
local x1 = env:get_node({x=x+1,y=ground_y,z=z}).name
|
||||
local z1 = env:get_node({x=x,y=ground_y,z=z+1}).name
|
||||
local xz1 = env:get_node({x=x+1,y=ground_y,z=z+1}).name
|
||||
local xz2 = env:get_node({x=x-1,y=ground_y,z=z-1}).name
|
||||
local x2 = env:get_node({x=x-1,y=ground_y,z=z}).name
|
||||
local z2 = env:get_node({x=x,y=ground_y,z=z-1}).name
|
||||
local y = env:get_node({x=x,y=ground_y-1,z=z}).name
|
||||
local rand = pr:next(1,4) == 1
|
||||
if
|
||||
((x1 and x1 ~= "default:water_source" and x1 ~= "snow:ice" and x1 ~= "air" and x1 ~= "ignore") or ((cool or icebergs) and x1 == "snow:ice" and rand)) or
|
||||
((z1 and z1 ~= "default:water_source" and z1 ~= "snow:ice" and z1 ~= "air" and z1 ~= "ignore") or ((cool or icebergs) and z1 == "snow:ice" and rand)) or
|
||||
((xz1 and xz1 ~= "default:water_source" and xz1 ~= "snow:ice" and xz1 ~= "air"and xz1 ~= "ignore") or ((cool or icebergs) and xz1 == "snow:ice" and rand)) or
|
||||
((xz2 and xz2 ~= "default:water_source" and xz2 ~= "snow:ice" and xz2 ~= "air"and xz2 ~= "ignore") or ((cool or icebergs) and xz2 == "snow:ice" and rand)) or
|
||||
((x2 and x2 ~= "default:water_source" and x2 ~= "snow:ice" and x2 ~= "air" and x2 ~= "ignore") or ((cool or icebergs) and x2 == "snow:ice" and rand)) or
|
||||
((z2 and z2 ~= "default:water_source" and z2 ~= "snow:ice" and z2 ~= "air" and z2 ~= "ignore") or ((cool or icebergs) and z2 == "snow:ice" and rand)) or
|
||||
(y ~= "default:water_source" and y ~= "snow:ice" and y ~= "air") or (pr:next(1,6) == 1 and icebergs) then
|
||||
env:add_node({x=x,y=ground_y,z=z}, {name="snow:ice"})
|
||||
end
|
||||
else
|
||||
--Icesheets, Broken icesheet, Icecaves
|
||||
if (icehole and pr:next(1,10) > 1) or icecave or icesheet then
|
||||
env:add_node({x=x,y=ground_y,z=z}, {name="snow:ice"})
|
||||
end
|
||||
if icecave then
|
||||
--Gets rid of water underneath ice
|
||||
for y=ground_y-1,-60,-1 do
|
||||
if env:get_node({x=x,y=y,z=z}) and env:get_node({x=x,y=y,z=z}).name ~= "default:water_source" then
|
||||
break
|
||||
else
|
||||
env:remove_node({x=x,y=y,z=z})
|
||||
end
|
||||
end
|
||||
elseif ground_y and data[node] == c_water then
|
||||
if not icesheet and not icecave and not icehole then
|
||||
--Coastal ice.
|
||||
local x1 = data[a:index(x+1,ground_y,z)]
|
||||
local z1 = data[a:index(x,ground_y,z+1)]
|
||||
local xz1 = data[a:index(x+1,ground_y,z+1)]
|
||||
local xz2 = data[a:index(x-1,ground_y,z-1)]
|
||||
local x2 = data[a:index(x-1,ground_y,z)]
|
||||
local z2 = data[a:index(x,ground_y,z-1)]
|
||||
local y = data[a:index(x,ground_y-1,z)]
|
||||
local rand = pr:next(1,4) == 1
|
||||
if
|
||||
((x1 and x1 ~= c_water and x1 ~= c_ice and x1 ~= c_air and x1 ~= c_ignore) or ((cool or icebergs) and x1 == c_ice and rand)) or
|
||||
((z1 and z1 ~= c_water and z1 ~= c_ice and z1 ~= c_air and z1 ~= c_ignore) or ((cool or icebergs) and z1 == c_ice and rand)) or
|
||||
((xz1 and xz1 ~= c_water and xz1 ~= c_ice and xz1 ~= c_air and xz1 ~= c_ignore) or ((cool or icebergs) and xz1 == c_ice and rand)) or
|
||||
((xz2 and xz2 ~= c_water and xz2 ~= c_ice and xz2 ~= c_air and xz2 ~= c_ignore) or ((cool or icebergs) and xz2 == c_ice and rand)) or
|
||||
((x2 and x2 ~= c_water and x2 ~= c_ice and x2 ~= c_air and x2 ~= c_ignore) or ((cool or icebergs) and x2 == c_ice and rand)) or
|
||||
((z2 and z2 ~= c_water and z2 ~= c_ice and z2 ~= c_air and z2 ~= c_ignore) or ((cool or icebergs) and z2 == c_ice and rand)) or
|
||||
(y ~= c_water and y ~= c_ice and y ~= "air") or (pr:next(1,6) == 1 and icebergs) then
|
||||
data[node] = c_ice
|
||||
end
|
||||
else
|
||||
--Icesheets, Broken icesheet, Icecaves
|
||||
if (icehole and pr:next(1,10) > 1) or icecave or icesheet then
|
||||
data[node] = c_ice
|
||||
end
|
||||
if icecave then
|
||||
--Gets rid of water underneath ice
|
||||
for y=ground_y-1,-60,-1 do
|
||||
local water = a:index(x, y, z)
|
||||
if data[water] ~= c_water then
|
||||
break
|
||||
else
|
||||
data[water] = c_air
|
||||
end
|
||||
end
|
||||
end
|
||||
--~ elseif ground_y and node.name == "snow:snow" and node.name ~= "snow:ice" then
|
||||
--~ --Abort genaration.
|
||||
--~ local name = env:get_node({x=x,y=ground_y-1,z=z}).name
|
||||
--~ if name ~= "default:leaves" and name ~= "snow:needles" then
|
||||
--~ if debug then
|
||||
--~ print(biomeToString(biome)..": snow found ABORTED!")
|
||||
--~ end
|
||||
--~ return
|
||||
--~ end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if debug then
|
||||
biome_string,biome2_string = biomeToString(biome,biome2)
|
||||
print(biome_string.." and "..biome2_string..": Snow Biome Genarated near x"..minp.x.." z"..minp.z)
|
||||
--end
|
||||
end
|
||||
end
|
||||
end)
|
||||
else
|
||||
|
||||
--Identify content ID's of nodes
|
||||
local c_dirt_with_grass = minetest.get_content_id("default:dirt_with_grass")
|
||||
local c_snow = minetest.get_content_id("snow:snow")
|
||||
local c_snow_block = minetest.get_content_id("snow:snow_block")
|
||||
local c_dirt_with_snow = minetest.get_content_id("snow:dirt_with_snow")
|
||||
local c_air = minetest.get_content_id("air")
|
||||
local c_ignore = minetest.get_content_id("ignore")
|
||||
local c_stone = minetest.get_content_id("default:stone")
|
||||
local c_dry_shrub = minetest.get_content_id("default:dry_shrub")
|
||||
local c_leaves = minetest.get_content_id("default:leaves")
|
||||
local c_ice = minetest.get_content_id("snow:ice")
|
||||
local c_water = minetest.get_content_id("default:water_source")
|
||||
local c_papyrus = minetest.get_content_id("default:papyrus")
|
||||
local c_sand = minetest.get_content_id("default:sand")
|
||||
end
|
||||
|
||||
vm:set_data(data)
|
||||
|
||||
vm:calc_lighting(
|
||||
{x=minp.x-16, y=minp.y, z=minp.z-16},
|
||||
{x=maxp.x+16, y=maxp.y, z=maxp.z+16}
|
||||
)
|
||||
|
||||
vm:write_to_map(data)
|
||||
|
||||
--Snow biomes are found at 0.53 and greater perlin noise.
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
--if maxp.y >= -10 and maxp.y > snow.min_height then
|
||||
|
||||
--Start timer
|
||||
local t1 = os.clock()
|
||||
local in_biome = false
|
||||
|
||||
--Load Voxel Manipulator
|
||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||
local a = VoxelArea:new{
|
||||
MinEdge={x=emin.x, y=emin.y, z=emin.z},
|
||||
MaxEdge={x=emax.x, y=emax.y, z=emax.z},
|
||||
}
|
||||
local data = vm:get_data()
|
||||
|
||||
local debug = snow.debug
|
||||
local min_height = snow.min_height
|
||||
|
||||
--Should make things a bit faster.
|
||||
local env = minetest.env
|
||||
|
||||
|
||||
-- Assume X and Z lengths are equal
|
||||
local divlen = 16
|
||||
local divs = (maxp.x-minp.x)+1;
|
||||
local x0 = minp.x
|
||||
local z0 = minp.z
|
||||
local x1 = maxp.x
|
||||
local z1 = maxp.z
|
||||
|
||||
|
||||
--Get map specific perlin noise.
|
||||
local perlin1 = env:get_perlin(112,3, 0.5, 150)
|
||||
|
||||
--Speed hack: checks the corners and middle of the chunk for "snow biome".
|
||||
--[[if not ( perlin1:get2d( {x=x0, y=z0} ) > 0.53 ) --top left
|
||||
and not ( perlin1:get2d( { x = x0 + ( (x1-x0)/2), y=z0 } ) > 0.53 )--top middle
|
||||
and not (perlin1:get2d({x=x1, y=z1}) > 0.53) --bottom right
|
||||
and not (perlin1:get2d({x=x1, y=z0+((z1-z0)/2)}) > 0.53) --right middle
|
||||
and not (perlin1:get2d({x=x0, y=z1}) > 0.53) --bottom left
|
||||
and not (perlin1:get2d({x=x1, y=z0}) > 0.53) --top right
|
||||
and not (perlin1:get2d({x=x0+((x1-x0)/2), y=z1}) > 0.53) --left middle
|
||||
and not (perlin1:get2d({x=(x1-x0)/2, y=(z1-z0)/2}) > 0.53) --middle
|
||||
and not (perlin1:get2d({x=x0, y=z1+((z1-z0)/2)}) > 0.53) then --bottom middle
|
||||
return
|
||||
end]]
|
||||
|
||||
--Choose a biome types.
|
||||
local pr = PseudoRandom(seed+57)
|
||||
local biome
|
||||
|
||||
--Land biomes
|
||||
biome = pr:next(1, 5)
|
||||
local snowy = biome == 1 --spawns alot of snow
|
||||
local plain = biome == 2 --spawns not much
|
||||
local alpine = biome == 3 --rocky terrain
|
||||
-- biome == 4 or biome == 5 -- normal biome
|
||||
|
||||
--Water biomes
|
||||
biome2 = pr:next(1, 5)
|
||||
local cool = biome == 1 --only spawns ice on edge of water
|
||||
local icebergs = biome == 2
|
||||
local icesheet = biome == 3
|
||||
local icecave = biome == 4
|
||||
local icehole = biome == 5 --icesheet with holes
|
||||
|
||||
--Misc biome settings.
|
||||
local icy = pr:next(1, 2) == 2 --If enabled spawns ice in sand instead of snow blocks.
|
||||
local mossy = pr:next(1,2) == 1 --Spawns moss in snow.
|
||||
local shrubs = pr:next(1,2) == 1 --Spawns dry shrubs in snow.
|
||||
local pines = pr:next(1,2) == 1 --spawns pines.
|
||||
|
||||
--Debugging function
|
||||
local biomeToString = function(num,num2)
|
||||
local biome, biome2
|
||||
if num == 1 then biome = "snowy"
|
||||
elseif num == 2 then biome = "plain"
|
||||
elseif num == 3 then biome = "alpine"
|
||||
elseif num == 4 or num == 5 then biome = "normal"
|
||||
else biome = "unknown "..num end
|
||||
|
||||
if num2 == 1 then biome2 = "cool"
|
||||
elseif num2 == 2 then biome2 = "icebergs"
|
||||
elseif num2 == 3 then biome2 = "icesheet"
|
||||
elseif num2 == 4 then biome2 = "icecave"
|
||||
elseif num2 == 5 then biome2 = "icehole"
|
||||
else biome2 = "unknown "..num end
|
||||
|
||||
return biome, biome2
|
||||
end
|
||||
|
||||
local spawn_pine = snow.voxelmanip_pine
|
||||
local smooth = snow.smooth_biomes
|
||||
local legacy = snow.legacy
|
||||
|
||||
--Reseed random.
|
||||
pr = PseudoRandom(seed+68)
|
||||
|
||||
--[[if alpine then
|
||||
local trees = env:find_nodes_in_area(minp, maxp, {"default:leaves","default:tree"})
|
||||
for i,v in pairs(trees) do
|
||||
env:remove_node(v)
|
||||
end
|
||||
end]]
|
||||
|
||||
--Loop through chunk.
|
||||
for x = minp.x, maxp.x do
|
||||
for z = minp.z, maxp.z do
|
||||
|
||||
--Check if we are in a "Snow biome"
|
||||
local in_biome = false
|
||||
local test = perlin1:get2d({x=x, y=z})
|
||||
if smooth and (not snowy) and (test > 0.73 or (test > 0.43 and pr:next(0,29) > (0.73 - test) * 100 )) then
|
||||
in_biome = true
|
||||
elseif (not smooth or snowy) and test > 0.53 then
|
||||
in_biome = true
|
||||
end
|
||||
|
||||
|
||||
if in_biome then
|
||||
|
||||
local perlin2 = env:get_perlin(322345,3, 0.5, 80)
|
||||
local icetype = perlin2:get2d({x=x, y=z})
|
||||
local cool = icetype > 0 --only spawns ice on edge of water
|
||||
local icebergs = icetype > -0.2 and icetype <= 0
|
||||
local icehole = icetype > -0.4 and icetype <= -0.2
|
||||
local icesheet = icetype > -0.6 and icetype <= -0.4
|
||||
local icecave = icetype <= -0.6
|
||||
|
||||
--if not plain or pr:next(1,12) == 1 then
|
||||
|
||||
-- Find ground level (0...15)
|
||||
local ground_y = nil
|
||||
for y=maxp.y,minp.y,-1 do
|
||||
local n = data[a:index(x, y, z)]
|
||||
if n ~= c_air and n ~= c_ignore then
|
||||
ground_y = y
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if ground_y then --and ground_y > min_height then
|
||||
|
||||
-- Snowy biome stuff
|
||||
local node = a:index(x, ground_y, z)
|
||||
local abovenode = a:index(x, ground_y+1, z)
|
||||
local belownode = a:index(x, ground_y+2, z)
|
||||
|
||||
if ground_y and data[node] == c_dirt_with_grass then
|
||||
--local veg
|
||||
--if legacy and mossy and pr:next(1,10) == 1 then veg = 1 end
|
||||
if alpine then
|
||||
--Gets rid of dirt
|
||||
data[abovenode] = c_snow
|
||||
for y=ground_y,-6,-1 do
|
||||
local stone = a:index(x, y, z)
|
||||
if data[stone] == "default:stone" then
|
||||
break
|
||||
else
|
||||
data[stone] = c_stone
|
||||
end
|
||||
end
|
||||
elseif (shrubs and pr:next(1,28) == 1) then
|
||||
--Spawns dry shrubs.
|
||||
data[node] = c_dirt_with_snow
|
||||
data[abovenode] = c_dry_shrub
|
||||
elseif pines and pr:next(1,36) == 1 then
|
||||
--Spawns pines.
|
||||
data[node] = c_dirt_with_snow
|
||||
spawn_pine({x=x, y=ground_y+1, z=z},a,data)
|
||||
--elseif snowy then
|
||||
--Spawns snow blocks.
|
||||
--env:add_node({x=x,y=ground_y+1,z=z}, {name="snow:snow_block"})
|
||||
--data[aanode] = c_snow
|
||||
else
|
||||
--Spawns snow.
|
||||
data[node] = c_dirt_with_snow
|
||||
data[abovenode] = c_snow
|
||||
end
|
||||
elseif ground_y and data[belownode] == c_sand then
|
||||
--Spawns ice in sand if icy, otherwise spawns snow on top.
|
||||
if not icy then
|
||||
data[node] = c_snow
|
||||
else
|
||||
data[belownode] = c_ice
|
||||
end
|
||||
elseif ground_y and data[node] == c_leaves then
|
||||
data[abovenode] = c_snow
|
||||
elseif ground_y and data[node] == c_papyrus then
|
||||
for i=ground_y, ground_y-4, -1 do
|
||||
local papyrus = a:index(x, y, z)
|
||||
if data[papyrus] == c_papyrus then
|
||||
local papyrusabove = a:index(x, ground_y, z)
|
||||
data[papyrusabove] = c_snow
|
||||
data[papyrus] = c_snow_block
|
||||
end
|
||||
end
|
||||
elseif ground_y and data[node] == c_water then
|
||||
if not icesheet and not icecave and not icehole then
|
||||
--Coastal ice.
|
||||
local x1 = data[a:index(x+1,ground_y,z)]
|
||||
local z1 = data[a:index(x,ground_y,z+1)]
|
||||
local xz1 = data[a:index(x+1,ground_y,z+1)]
|
||||
local xz2 = data[a:index(x-1,ground_y,z-1)]
|
||||
local x2 = data[a:index(x-1,ground_y,z)]
|
||||
local z2 = data[a:index(x,ground_y,z-1)]
|
||||
local y = data[a:index(x,ground_y-1,z)]
|
||||
local rand = pr:next(1,4) == 1
|
||||
if
|
||||
((x1 and x1 ~= c_water and x1 ~= c_ice and x1 ~= c_air and x1 ~= c_ignore) or ((cool or icebergs) and x1 == c_ice and rand)) or
|
||||
((z1 and z1 ~= c_water and z1 ~= c_ice and z1 ~= c_air and z1 ~= c_ignore) or ((cool or icebergs) and z1 == c_ice and rand)) or
|
||||
((xz1 and xz1 ~= c_water and xz1 ~= c_ice and xz1 ~= c_air and xz1 ~= c_ignore) or ((cool or icebergs) and xz1 == c_ice and rand)) or
|
||||
((xz2 and xz2 ~= c_water and xz2 ~= c_ice and xz2 ~= c_air and xz2 ~= c_ignore) or ((cool or icebergs) and xz2 == c_ice and rand)) or
|
||||
((x2 and x2 ~= c_water and x2 ~= c_ice and x2 ~= c_air and x2 ~= c_ignore) or ((cool or icebergs) and x2 == c_ice and rand)) or
|
||||
((z2 and z2 ~= c_water and z2 ~= c_ice and z2 ~= c_air and z2 ~= c_ignore) or ((cool or icebergs) and z2 == c_ice and rand)) or
|
||||
(y ~= c_water and y ~= c_ice and y ~= "air") or (pr:next(1,6) == 1 and icebergs) then
|
||||
data[node] = c_ice
|
||||
end
|
||||
else
|
||||
--Icesheets, Broken icesheet, Icecaves
|
||||
if (icehole and pr:next(1,10) > 1) or icecave or icesheet then
|
||||
data[node] = c_ice
|
||||
end
|
||||
if icecave then
|
||||
--Gets rid of water underneath ice
|
||||
for y=ground_y-1,-60,-1 do
|
||||
local water = a:index(x, y, z)
|
||||
if data[water] ~= c_water then
|
||||
break
|
||||
else
|
||||
data[water] = c_air
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--~ elseif ground_y and node.name == "snow:snow" and node.name ~= "snow:ice" then
|
||||
--~ --Abort genaration.
|
||||
--~ local name = env:get_node({x=x,y=ground_y-1,z=z}).name
|
||||
--~ if name ~= "default:leaves" and name ~= "snow:needles" then
|
||||
--~ if debug then
|
||||
--~ print(biomeToString(biome)..": snow found ABORTED!")
|
||||
--~ end
|
||||
--~ return
|
||||
--~ end]]
|
||||
end
|
||||
end
|
||||
--end
|
||||
end
|
||||
end
|
||||
end
|
||||
if debug then
|
||||
biome_string,biome2_string = biomeToString(biome,biome2)
|
||||
print(biome_string.." and "..biome2_string..": Snow Biome Genarated near x"..minp.x.." z"..minp.z)
|
||||
end
|
||||
vm:set_data(data)
|
||||
|
||||
vm:calc_lighting(
|
||||
{x=minp.x-16, y=minp.y, z=minp.z-16},
|
||||
{x=maxp.x+16, y=maxp.y, z=maxp.z+16}
|
||||
)
|
||||
|
||||
vm:write_to_map(data)
|
||||
|
||||
print(string.format("elapsed time: %.2fms", (os.clock() - t1) * 1000))
|
||||
--end
|
||||
end)
|
||||
end
|
||||
if debug then
|
||||
biome_string,biome2_string = biomeToString(biome,biome2)
|
||||
print(biome_string.." and "..biome2_string..": Snow Biome Genarated near x"..minp.x.." z"..minp.z)
|
||||
print(string.format("elapsed time: %.2fms", (os.clock() - t1) * 1000))
|
||||
end
|
||||
--end
|
||||
end)
|
||||
|
@ -1,7 +1,7 @@
|
||||
minetest.register_biome({
|
||||
name = "snow_biome_default",
|
||||
|
||||
node_top = "snow:dirt_with_snow",
|
||||
node_top = "default:dirt_with_snow",
|
||||
depth_top = 1,
|
||||
node_filler = "default:dirt",
|
||||
depth_filler = 2,
|
||||
@ -15,7 +15,7 @@ minetest.register_biome({
|
||||
minetest.register_biome({
|
||||
name = "snow_biome_forest",
|
||||
|
||||
node_top = "snow:dirt_with_snow",
|
||||
node_top = "default:dirt_with_snow",
|
||||
depth_top = 1,
|
||||
node_filler = "default:dirt",
|
||||
depth_filler = 2,
|
||||
@ -29,7 +29,7 @@ minetest.register_biome({
|
||||
minetest.register_biome({
|
||||
name = "snow_biome_lush",
|
||||
|
||||
node_top = "snow:dirt_with_snow",
|
||||
node_top = "default:dirt_with_snow",
|
||||
depth_top = 1,
|
||||
node_filler = "default:dirt",
|
||||
depth_filler = 2,
|
||||
@ -80,7 +80,7 @@ minetest.register_biome({
|
||||
--Pine tree.
|
||||
minetest.register_decoration({
|
||||
deco_type = "schematic",
|
||||
place_on = "snow:dirt_with_snow",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 0.005,
|
||||
biomes = {"snow_biome_default"},
|
||||
@ -90,7 +90,7 @@ minetest.register_decoration({
|
||||
|
||||
minetest.register_decoration({
|
||||
deco_type = "schematic",
|
||||
place_on = "snow:dirt_with_snow",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 0.05,
|
||||
biomes = {"snow_biome_forest"},
|
||||
@ -100,7 +100,7 @@ minetest.register_decoration({
|
||||
|
||||
minetest.register_decoration({
|
||||
deco_type = "schematic",
|
||||
place_on = "snow:dirt_with_snow",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 0.1,
|
||||
biomes = {"snow_biome_lush"},
|
||||
@ -111,7 +111,7 @@ minetest.register_decoration({
|
||||
--Dry shrubs.
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
place_on = "snow:dirt_with_snow",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 0.005,
|
||||
biomes = {"snow_biome_default"},
|
||||
@ -120,7 +120,7 @@ minetest.register_decoration({
|
||||
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
place_on = "snow:dirt_with_snow",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 0.05,
|
||||
biomes = {"snow_biome_forest", "snow_biome_lush"},
|
||||
@ -130,11 +130,11 @@ minetest.register_decoration({
|
||||
--Snow.
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
place_on = "snow:dirt_with_snow",
|
||||
place_on = "default:dirt_with_snow",
|
||||
sidelen = 16,
|
||||
fill_ratio = 10,
|
||||
biomes = {"snow_biome_default", "snow_biome_forest", "snow_biome_lush"},
|
||||
decoration = "snow:snow",
|
||||
decoration = "default:snow",
|
||||
})
|
||||
|
||||
minetest.register_decoration({
|
||||
@ -143,6 +143,6 @@ minetest.register_decoration({
|
||||
sidelen = 16,
|
||||
fill_ratio = 10,
|
||||
biomes = {"snow_biome_alpine"},
|
||||
decoration = "snow:snow",
|
||||
decoration = "default:snow",
|
||||
})
|
||||
|
||||
|
2
util.lua
2
util.lua
@ -2,6 +2,7 @@
|
||||
snow = {
|
||||
legacy = true,
|
||||
enable_snowfall = true,
|
||||
lighter_snowfall = false,
|
||||
debug = false,
|
||||
smooth_biomes = true,
|
||||
christmas_content = true,
|
||||
@ -13,6 +14,7 @@ snow = {
|
||||
local doc = {
|
||||
legacy = "Whether you are running a legacy minetest version (auto-detected).",
|
||||
enable_snowfall = "Enables falling snow.",
|
||||
lighter_snowfall = "Reduces the amount of resources and fps used by snowfall.",
|
||||
debug = "Enables debug output.",
|
||||
smooth_biomes = "Enables smooth transition of biomes",
|
||||
christmas_content = "Disable this to remove christmas saplings from being found.",
|
||||
|
Loading…
Reference in New Issue
Block a user