mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2024-12-28 07:30:17 +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:
parent
346a263761
commit
afc578cb16
25
init.lua
25
init.lua
@ -52,7 +52,6 @@ local modpath = minetest.get_modpath("snow")
|
||||
dofile(modpath.."/src/abms.lua")
|
||||
dofile(modpath.."/src/aliases.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
|
||||
@ -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
|
||||
-- I put it lower on the list and that seems to do the trick. ~ LazyJ
|
||||
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.
|
||||
-- That means "nodes.lua", where the saplings are controlled, has to come after "util.lua". ~ LazyJ
|
||||
dofile(modpath.."/src/nodes.lua")
|
||||
@ -79,6 +79,7 @@ and minetest.get_modpath("moreblocks") then
|
||||
|
||||
end
|
||||
|
||||
local is_uneven
|
||||
--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.
|
||||
function snow.place(pos)
|
||||
@ -94,7 +95,7 @@ function snow.place(pos)
|
||||
local level = minetest.get_node_level(pos)
|
||||
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
|
||||
and not snow.is_uneven(pos) then
|
||||
and not is_uneven(pos) then
|
||||
minetest.sound_play("default_snow_footstep", {pos=pos})
|
||||
minetest.add_node_level(pos, 7)
|
||||
end
|
||||
@ -136,7 +137,7 @@ end
|
||||
|
||||
-- Checks if the snow level is even at any given pos.
|
||||
-- Smooth Snow
|
||||
local function is_uneven(pos)
|
||||
local function uneven(pos)
|
||||
local num = minetest.get_node_level(pos)
|
||||
local get_node = minetest.get_node
|
||||
local add_node = minetest.add_node
|
||||
@ -181,8 +182,18 @@ local function is_uneven(pos)
|
||||
end
|
||||
end
|
||||
|
||||
function snow.is_uneven(pos)
|
||||
if snow.smooth_snow then
|
||||
return is_uneven(pos)
|
||||
end
|
||||
if snow.smooth_snow then
|
||||
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)
|
||||
|
@ -188,6 +188,7 @@ local function snow_fall(pos, player, animate)
|
||||
end
|
||||
|
||||
-- Snow
|
||||
local lighter_snowfall = snow.lighter_snowfall
|
||||
local function calc_snowfall()
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local ppos = player:getpos()
|
||||
@ -196,7 +197,7 @@ local function calc_snowfall()
|
||||
if get_snow(ppos)
|
||||
and minetest.get_node_light(ppos, 0.5) == 15 then
|
||||
local animate
|
||||
if not snow.lighter_snowfall then
|
||||
if not lighter_snowfall then
|
||||
local vel = {x=0, y=-1, z=-1}
|
||||
local acc = {x=0, y=0, z=0}
|
||||
minetest.add_particlespawner(get_snow_particledef({
|
||||
@ -239,8 +240,25 @@ local function calc_snowfall()
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if snow.enable_snowfall then
|
||||
calc_snowfall()
|
||||
local step_func
|
||||
minetest.register_globalstep(function()
|
||||
step_func()
|
||||
end)
|
||||
|
||||
if snow.enable_snowfall then
|
||||
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)
|
||||
|
@ -23,20 +23,38 @@ end
|
||||
|
||||
local rarity = snow.mapgen_rarity
|
||||
local size = snow.mapgen_size
|
||||
|
||||
local nosmooth_rarity = 1-rarity/50
|
||||
local perlin_scale = size*100/rarity
|
||||
mg.perlin_scale = perlin_scale
|
||||
local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif
|
||||
local smooth = snow.smooth_biomes
|
||||
if smooth then
|
||||
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_min = upper_rarity(nosmooth_rarity-smooth_trans_size/perlin_scale)
|
||||
mg.smooth_rarity_dif = mg.smooth_rarity_max-mg.smooth_rarity_min
|
||||
|
||||
local nosmooth_rarity, perlin_scale
|
||||
local function calc_values()
|
||||
nosmooth_rarity = 1-rarity/50
|
||||
perlin_scale = size*100/rarity
|
||||
mg.perlin_scale = perlin_scale
|
||||
local smooth_rarity_max, smooth_rarity_min, smooth_rarity_dif
|
||||
if smooth then
|
||||
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_min = upper_rarity(nosmooth_rarity-smooth_trans_size/perlin_scale)
|
||||
mg.smooth_rarity_dif = mg.smooth_rarity_max-mg.smooth_rarity_min
|
||||
end
|
||||
nosmooth_rarity = upper_rarity(nosmooth_rarity)
|
||||
mg.nosmooth_rarity = nosmooth_rarity
|
||||
end
|
||||
nosmooth_rarity = upper_rarity(nosmooth_rarity)
|
||||
mg.nosmooth_rarity = nosmooth_rarity
|
||||
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.
|
||||
|
@ -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 n = x/(16000)
|
||||
local y = 0
|
||||
@ -120,7 +108,7 @@ local function is_snowable(id)
|
||||
end
|
||||
|
||||
|
||||
local c, replacements
|
||||
local c, replacements, mg_debug, biome_to_string
|
||||
local function define_contents()
|
||||
c = {
|
||||
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"),
|
||||
}
|
||||
replacements = snow.known_plants or {}
|
||||
|
||||
mg_debug = snow.debug
|
||||
end
|
||||
|
||||
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 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)
|
||||
local t1 = os.clock()
|
||||
|
||||
@ -509,9 +524,21 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
vm: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 chugent = math.ceil((os.clock() - t1) * 1000)
|
||||
print("[snow] "..biome_string.." x "..minp.x.." z "..minp.z.." time "..chugent.." ms")
|
||||
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
|
||||
|
@ -36,14 +36,27 @@ The Xmas tree needles are registred and defined a farther down in this nodes.lua
|
||||
if snow.christmas_content then
|
||||
table.insert(nodedef.drop.items, 1, {
|
||||
-- player will get xmas tree with 1/120 chance
|
||||
items = {'snow:xmas_tree'},
|
||||
items = {"snow:xmas_tree"},
|
||||
rarity = 120,
|
||||
})
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
32
src/sled.lua
32
src/sled.lua
@ -101,21 +101,20 @@ local function leave_sled(self, player)
|
||||
self.object:set_detach()
|
||||
default.player_attached[name] = false
|
||||
default.player_set_animation(player, "stand" , 30)
|
||||
|
||||
|
||||
player:set_physics_override({
|
||||
speed = 1,
|
||||
jump = 1,
|
||||
})
|
||||
player:hud_remove(self.HUD) -- And here is part 2. ~ LazyJ
|
||||
self.object:remove()
|
||||
|
||||
|
||||
--Give the sled back again
|
||||
player:get_inventory():add_item("main", "snow:sled")
|
||||
end
|
||||
|
||||
function sled:on_rightclick(player)
|
||||
if self.driver
|
||||
or not snow.sleds then
|
||||
local function sled_rightclick(player)
|
||||
if self.driver then
|
||||
return
|
||||
end
|
||||
join_sled(self, player)
|
||||
@ -136,6 +135,27 @@ function sled:on_rightclick(player)
|
||||
-- End part 1
|
||||
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)
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
self.object:setacceleration({x=0, y=-10, z=0})
|
||||
@ -205,7 +225,7 @@ minetest.register_craftitem("snow:sled", {
|
||||
local pos = placer:getpos()
|
||||
if accelerating_possible(vector.round(pos)) then
|
||||
pos.y = pos.y+0.5
|
||||
|
||||
|
||||
--Get on the sled and remove it from inventory.
|
||||
minetest.add_entity(pos, "snow:sled"):right_click(placer)
|
||||
itemstack:take_item(); return itemstack
|
||||
|
@ -8,9 +8,19 @@
|
||||
|
||||
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 grav = tonumber(minetest.setting_get("movement_gravity")) or 9.81
|
||||
return grav*snow.snowball_gravity
|
||||
return grav*snowball_gravity
|
||||
end
|
||||
|
||||
local someone_throwing
|
||||
@ -25,7 +35,7 @@ local function snow_shoot_snowball(item, player)
|
||||
addp.z = -dir.x/dif -- + (math.random()-0.5)/5
|
||||
local pos = vector.add(player:getpos(), addp)
|
||||
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})
|
||||
if creative_mode then
|
||||
if not someone_throwing then
|
||||
|
Loading…
Reference in New Issue
Block a user