1
0
mirror of https://github.com/Splizard/minetest-mod-snow.git synced 2024-12-29 16:00:16 +01:00

allow configuring the mapgen size, rarity and smooth without rejoining, which is actually a bad idea because of chunk corners

This commit is contained in:
HybridDog 2015-11-22 01:21:21 +01:00
parent 346a263761
commit afc578cb16
7 changed files with 164 additions and 47 deletions

View File

@ -52,7 +52,6 @@ local modpath = minetest.get_modpath("snow")
dofile(modpath.."/src/abms.lua") dofile(modpath.."/src/abms.lua")
dofile(modpath.."/src/aliases.lua") dofile(modpath.."/src/aliases.lua")
dofile(modpath.."/src/crafting.lua") dofile(modpath.."/src/crafting.lua")
dofile(modpath.."/src/snowball.lua")
-- The formspec menu didn't work when util.lua was the very first "dofile" so I moved -- The formspec menu didn't work when util.lua was the very first "dofile" so I moved
@ -60,6 +59,7 @@ dofile(modpath.."/src/snowball.lua")
-- Minetest would crash if the mapgen was called upon before the rest of other snow lua files so -- Minetest would crash if the mapgen was called upon before the rest of other snow lua files so
-- I put it lower on the list and that seems to do the trick. ~ LazyJ -- I put it lower on the list and that seems to do the trick. ~ LazyJ
dofile(modpath.."/src/util.lua") dofile(modpath.."/src/util.lua")
dofile(modpath.."/src/snowball.lua")
-- To get Xmas tree saplings, the "christmas_content", true or false, in "util.lua" has to be determined first. -- To get Xmas tree saplings, the "christmas_content", true or false, in "util.lua" has to be determined first.
-- That means "nodes.lua", where the saplings are controlled, has to come after "util.lua". ~ LazyJ -- That means "nodes.lua", where the saplings are controlled, has to come after "util.lua". ~ LazyJ
dofile(modpath.."/src/nodes.lua") dofile(modpath.."/src/nodes.lua")
@ -79,6 +79,7 @@ and minetest.get_modpath("moreblocks") then
end end
local is_uneven
--This function places snow checking at the same time for snow level and increasing as needed. --This function places snow checking at the same time for snow level and increasing as needed.
--This also takes into account sourrounding snow and makes snow even. --This also takes into account sourrounding snow and makes snow even.
function snow.place(pos) function snow.place(pos)
@ -94,7 +95,7 @@ function snow.place(pos)
local level = minetest.get_node_level(pos) local level = minetest.get_node_level(pos)
if level < 63 then if level < 63 then
if minetest.get_item_group(minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name, "leafdecay") == 0 if minetest.get_item_group(minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name, "leafdecay") == 0
and not snow.is_uneven(pos) then and not is_uneven(pos) then
minetest.sound_play("default_snow_footstep", {pos=pos}) minetest.sound_play("default_snow_footstep", {pos=pos})
minetest.add_node_level(pos, 7) minetest.add_node_level(pos, 7)
end end
@ -136,7 +137,7 @@ end
-- Checks if the snow level is even at any given pos. -- Checks if the snow level is even at any given pos.
-- Smooth Snow -- Smooth Snow
local function is_uneven(pos) local function uneven(pos)
local num = minetest.get_node_level(pos) local num = minetest.get_node_level(pos)
local get_node = minetest.get_node local get_node = minetest.get_node
local add_node = minetest.add_node local add_node = minetest.add_node
@ -181,8 +182,18 @@ local function is_uneven(pos)
end end
end end
function snow.is_uneven(pos)
if snow.smooth_snow then if snow.smooth_snow then
return is_uneven(pos) is_uneven = uneven
else
is_uneven = function() end
end
snow.register_on_configuring(function(name, v)
if name == "smooth_snow" then
if v then
is_uneven = uneven
else
is_uneven = function() end
end end
end end
end)

View File

@ -188,6 +188,7 @@ local function snow_fall(pos, player, animate)
end end
-- Snow -- Snow
local lighter_snowfall = snow.lighter_snowfall
local function calc_snowfall() local function calc_snowfall()
for _, player in pairs(minetest.get_connected_players()) do for _, player in pairs(minetest.get_connected_players()) do
local ppos = player:getpos() local ppos = player:getpos()
@ -196,7 +197,7 @@ local function calc_snowfall()
if get_snow(ppos) if get_snow(ppos)
and minetest.get_node_light(ppos, 0.5) == 15 then and minetest.get_node_light(ppos, 0.5) == 15 then
local animate local animate
if not snow.lighter_snowfall then if not lighter_snowfall then
local vel = {x=0, y=-1, z=-1} local vel = {x=0, y=-1, z=-1}
local acc = {x=0, y=0, z=0} local acc = {x=0, y=0, z=0}
minetest.add_particlespawner(get_snow_particledef({ minetest.add_particlespawner(get_snow_particledef({
@ -239,8 +240,25 @@ local function calc_snowfall()
end end
end end
minetest.register_globalstep(function(dtime) local step_func
minetest.register_globalstep(function()
step_func()
end)
if snow.enable_snowfall then if snow.enable_snowfall then
calc_snowfall() step_func = calc_snowfall
else
step_func = function() end
end
snow.register_on_configuring(function(name, v)
if name == "enable_snowfall" then
if v then
step_func = calc_snowfall
else
step_func = function() end
end
elseif name == "lighter_snowfall" then
lighter_snowfall = v
end end
end) end)

View File

@ -23,12 +23,14 @@ end
local rarity = snow.mapgen_rarity local rarity = snow.mapgen_rarity
local size = snow.mapgen_size local size = snow.mapgen_size
local smooth = snow.smooth_biomes
local nosmooth_rarity = 1-rarity/50 local nosmooth_rarity, perlin_scale
local perlin_scale = size*100/rarity local function calc_values()
nosmooth_rarity = 1-rarity/50
perlin_scale = size*100/rarity
mg.perlin_scale = perlin_scale mg.perlin_scale = perlin_scale
local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif
local smooth = snow.smooth_biomes
if smooth then if smooth then
local smooth_trans_size = 4 --snow.smooth_trans_size local smooth_trans_size = 4 --snow.smooth_trans_size
mg.smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale) mg.smooth_rarity_max = upper_rarity(nosmooth_rarity+smooth_trans_size*2/perlin_scale)
@ -37,6 +39,22 @@ if smooth then
end end
nosmooth_rarity = upper_rarity(nosmooth_rarity) nosmooth_rarity = upper_rarity(nosmooth_rarity)
mg.nosmooth_rarity = nosmooth_rarity mg.nosmooth_rarity = nosmooth_rarity
end
calc_values()
snow.register_on_configuring(function(name, v)
if name == "mapgen_rarity" then
rarity = v
elseif name == "mapgen_size" then
size = v
elseif name == "smooth_biomes" then
smooth = v
else
return
end
-- TODO: if e.g. size and rarity get changed at once, don't calculate the values more times
calc_values()
end)
--Identify the mapgen. --Identify the mapgen.

View File

@ -37,18 +37,6 @@ local np_ice = {
} }
-- Debugging function
local biome_strings = {
{"snowy", "plain", "alpine", "normal", "normal"},
{"cool", "icebergs", "icesheet", "icecave", "icehole"}
}
local function biome_to_string(num,num2)
local biome = biome_strings[1][num] or "unknown "..num
return biome
end
local function do_ws_func(a, x) local function do_ws_func(a, x)
local n = x/(16000) local n = x/(16000)
local y = 0 local y = 0
@ -120,7 +108,7 @@ local function is_snowable(id)
end end
local c, replacements local c, replacements, mg_debug, biome_to_string
local function define_contents() local function define_contents()
c = { c = {
dirt_with_grass = minetest.get_content_id("default:dirt_with_grass"), dirt_with_grass = minetest.get_content_id("default:dirt_with_grass"),
@ -145,6 +133,8 @@ local function define_contents()
desert_sand = minetest.get_content_id("default:desert_sand"), desert_sand = minetest.get_content_id("default:desert_sand"),
} }
replacements = snow.known_plants or {} replacements = snow.known_plants or {}
mg_debug = snow.debug
end end
local smooth = snow.smooth_biomes local smooth = snow.smooth_biomes
@ -153,6 +143,31 @@ local smooth_rarity_min = mg.smooth_rarity_min
local smooth_rarity_dif = mg.smooth_rarity_dif local smooth_rarity_dif = mg.smooth_rarity_dif
local nosmooth_rarity = mg.nosmooth_rarity local nosmooth_rarity = mg.nosmooth_rarity
snow.register_on_configuring(function(name, v)
if name == "debug" then
mg_debug = v
elseif name == "mapgen_rarity"
or name == "mapgen_size"
or name == "smooth_biomes" then
minetest.after(0, function()
smooth = snow.smooth_biomes
smooth_rarity_max = mg.smooth_rarity_max
smooth_rarity_min = mg.smooth_rarity_min
smooth_rarity_dif = mg.smooth_rarity_dif
nosmooth_rarity = mg.nosmooth_rarity
local scale = mg.perlin_scale
np_cold = {
offset = 0,
scale = 1,
spread = {x=scale, y=scale, z=scale},
seed = 112,
octaves = 3,
persist = 0.5
}
end)
end
end)
minetest.register_on_generated(function(minp, maxp, seed) minetest.register_on_generated(function(minp, maxp, seed)
local t1 = os.clock() local t1 = os.clock()
@ -509,9 +524,21 @@ minetest.register_on_generated(function(minp, maxp, seed)
vm:write_to_map() vm:write_to_map()
if write_to_map if write_to_map
and snow.debug then -- print if any column of mapchunk was snow biome and mg_debug then -- print if any column of mapchunk was snow biome
local biome_string = biome_to_string(biome) local biome_string = biome_to_string(biome)
local chugent = math.ceil((os.clock() - t1) * 1000) local chugent = math.ceil((os.clock() - t1) * 1000)
print("[snow] "..biome_string.." x "..minp.x.." z "..minp.z.." time "..chugent.." ms") print("[snow] "..biome_string.." x "..minp.x.." z "..minp.z.." time "..chugent.." ms")
end end
end) end)
-- Debugging function
local biome_strings = {
{"snowy", "plain", "alpine", "normal", "normal"},
{"cool", "icebergs", "icesheet", "icecave", "icehole"}
}
function biome_to_string(num,num2)
local biome = biome_strings[1][num] or "unknown "..num
return biome
end

View File

@ -36,14 +36,27 @@ The Xmas tree needles are registred and defined a farther down in this nodes.lua
if snow.christmas_content then if snow.christmas_content then
table.insert(nodedef.drop.items, 1, { table.insert(nodedef.drop.items, 1, {
-- player will get xmas tree with 1/120 chance -- player will get xmas tree with 1/120 chance
items = {'snow:xmas_tree'}, items = {"snow:xmas_tree"},
rarity = 120, rarity = 120,
}) })
end end
minetest.register_node("snow:needles", table.copy(nodedef)) minetest.register_node("snow:needles", table.copy(nodedef))
snow.register_on_configuring(function(name, v)
if name == "christmas_content" then
local drop = minetest.registered_nodes["snow:needles"].drop
if v then
table.insert(drop.items, 1, {
items = {"snow:xmas_tree"},
rarity = 120,
})
else
table.remove(drop.items, 1)
end
minetest.override_item("snow:needles", {drop = drop})
end
end)

View File

@ -113,9 +113,8 @@ local function leave_sled(self, player)
player:get_inventory():add_item("main", "snow:sled") player:get_inventory():add_item("main", "snow:sled")
end end
function sled:on_rightclick(player) local function sled_rightclick(player)
if self.driver if self.driver then
or not snow.sleds then
return return
end end
join_sled(self, player) join_sled(self, player)
@ -136,6 +135,27 @@ function sled:on_rightclick(player)
-- End part 1 -- End part 1
end end
local on_sled_click
if snow.sleds then
on_sled_click = sled_rightclick
else
on_sled_click = function() end
end
snow.register_on_configuring(function(name, v)
if name == "sleds" then
if v then
on_sled_click = sled_rightclick
else
on_sled_click = function() end
end
end
end)
function sled:on_rightclick(player)
on_sled_click(player)
end
function sled:on_activate(staticdata, dtime_s) function sled:on_activate(staticdata, dtime_s)
self.object:set_armor_groups({immortal=1}) self.object:set_armor_groups({immortal=1})
self.object:setacceleration({x=0, y=-10, z=0}) self.object:setacceleration({x=0, y=-10, z=0})

View File

@ -8,9 +8,19 @@
local creative_mode = minetest.setting_getbool("creative_mode") local creative_mode = minetest.setting_getbool("creative_mode")
local snowball_velocity = snow.snowball_velocity
local snowball_gravity = snow.snowball_gravity
snow.register_on_configuring(function(name, v)
if name == "snowball_velocity" then
snowball_velocity = v
elseif name == "snowball_gravity" then
snowball_gravity = v
end
end)
local function get_gravity() local function get_gravity()
local grav = tonumber(minetest.setting_get("movement_gravity")) or 9.81 local grav = tonumber(minetest.setting_get("movement_gravity")) or 9.81
return grav*snow.snowball_gravity return grav*snowball_gravity
end end
local someone_throwing local someone_throwing
@ -25,7 +35,7 @@ local function snow_shoot_snowball(item, player)
addp.z = -dir.x/dif -- + (math.random()-0.5)/5 addp.z = -dir.x/dif -- + (math.random()-0.5)/5
local pos = vector.add(player:getpos(), addp) local pos = vector.add(player:getpos(), addp)
local obj = minetest.add_entity(pos, "snow:snowball_entity") local obj = minetest.add_entity(pos, "snow:snowball_entity")
obj:setvelocity(vector.multiply(dir, snow.snowball_velocity)) obj:setvelocity(vector.multiply(dir, snowball_velocity))
obj:setacceleration({x=dir.x*-3, y=-get_gravity(), z=dir.z*-3}) obj:setacceleration({x=dir.x*-3, y=-get_gravity(), z=dir.z*-3})
if creative_mode then if creative_mode then
if not someone_throwing then if not someone_throwing then