mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-28 02:30:27 +01:00
[snow] Update
This commit is contained in:
parent
7f2f0088ef
commit
b769c03b62
@ -1,3 +0,0 @@
|
|||||||
minetest.register_alias("snow:needles", "default:pine_needles")
|
|
||||||
minetest.register_alias("snow:leaves", "default:pine_needles")
|
|
||||||
minetest.register_alias("snow:sapling_pine", "default:pine_sapling")
|
|
@ -39,45 +39,47 @@ http://github.com/Splizard/minetest-mod-snow/
|
|||||||
|
|
||||||
|
|
||||||
-- Original Lua Files
|
-- Original Lua Files
|
||||||
--dofile(minetest.get_modpath("snow").."/util.lua")
|
--dofile(modpath.."/util.lua")
|
||||||
--dofile(minetest.get_modpath("snow").."/mapgen.lua")
|
--dofile(modpath.."/mapgen.lua")
|
||||||
--dofile(minetest.get_modpath("snow").."/sled.lua")
|
--dofile(modpath.."/sled.lua")
|
||||||
-- "falling_snow.lua" disabled since weather functions minetest.get_heat(pos) and minetest.get_humidity(pos)
|
-- "falling_snow.lua" disabled since weather functions minetest.get_heat(pos) and minetest.get_humidity(pos)
|
||||||
-- have been removed from Minetest.
|
-- have been removed from Minetest.
|
||||||
-- Until something else can be figured out, use paramat's "Snowdrift" mod instead.
|
-- Until something else can be figured out, use paramat's "Snowdrift" mod instead.
|
||||||
-- dofile(minetest.get_modpath("snow").."/falling_snow.lua")
|
-- dofile(modpath.."/falling_snow.lua")
|
||||||
|
|
||||||
-- Original init.lua File Broken into Smaller Files
|
-- Original init.lua File Broken into Smaller Files
|
||||||
-- dofile(minetest.get_modpath("snow").."/src/abms.lua")
|
local modpath = minetest.get_modpath("snow")
|
||||||
dofile(minetest.get_modpath("snow").."/src/aliases.lua")
|
dofile(modpath.."/src/abms.lua")
|
||||||
dofile(minetest.get_modpath("snow").."/src/crafting.lua")
|
dofile(modpath.."/src/aliases.lua")
|
||||||
dofile(minetest.get_modpath("snow").."/src/snowball.lua")
|
dofile(modpath.."/src/crafting.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
|
||||||
-- it and all the other original "dofiles", in order, to the bottom of the list. ~ LazyJ
|
-- it and all the other original "dofiles", in order, to the bottom of the list. ~ LazyJ
|
||||||
-- 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(minetest.get_modpath("snow").."/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(minetest.get_modpath("snow").."/src/nodes.lua")
|
dofile(modpath.."/src/nodes.lua")
|
||||||
dofile(minetest.get_modpath("snow").."/aliases.lua")
|
dofile(modpath.."/src/basic_stairs_slabs.lua")
|
||||||
dofile(minetest.get_modpath("snow").."/src/basic_stairs_slabs.lua")
|
-- dofile(modpath.."/src/mapgen.lua")
|
||||||
-- dofile(minetest.get_modpath("snow").."/src/mapgen.lua")
|
dofile(modpath.."/src/sled.lua")
|
||||||
dofile(minetest.get_modpath("snow").."/src/sled.lua")
|
-- dofile(modpath.."/src/falling_snow.lua")
|
||||||
-- dofile(minetest.get_modpath("snow").."/src/falling_snow.lua")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Check for "MoreBlocks". If not found, skip this next "dofile".
|
-- Check for "MoreBlocks". If not found, skip this next "dofile".
|
||||||
|
|
||||||
if minetest.get_modpath("moreblocks") then
|
if rawget(_G, "stairsplus")
|
||||||
|
and minetest.get_modpath("moreblocks") then
|
||||||
|
|
||||||
dofile(minetest.get_modpath("snow").."/src/stairsplus.lua")
|
dofile(modpath.."/src/stairsplus.lua")
|
||||||
|
|
||||||
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)
|
||||||
@ -90,12 +92,11 @@ function snow.place(pos)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local bnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
|
||||||
if node.name == "default:snow" then
|
if node.name == "default:snow" then
|
||||||
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(bnode.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
|
||||||
@ -111,7 +112,7 @@ function snow.place(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif node.name ~= "default:ice"
|
elseif node.name ~= "default:ice"
|
||||||
and bnode.name ~= "air" then
|
and minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name ~= "air" then
|
||||||
local data = minetest.registered_nodes[node.name]
|
local data = minetest.registered_nodes[node.name]
|
||||||
local drawtype = data.drawtype
|
local drawtype = data.drawtype
|
||||||
if drawtype == "normal"
|
if drawtype == "normal"
|
||||||
@ -137,13 +138,11 @@ 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
|
||||||
local found
|
|
||||||
local foundx
|
local foundx
|
||||||
local foundy
|
|
||||||
local foundz
|
local foundz
|
||||||
for z = -1,1 do
|
for z = -1,1 do
|
||||||
for x = -1,1 do
|
for x = -1,1 do
|
||||||
@ -164,7 +163,6 @@ local function is_uneven(pos)
|
|||||||
if not (x == 0 and z == 0)
|
if not (x == 0 and z == 0)
|
||||||
and node.name == "default:snow"
|
and node.name == "default:snow"
|
||||||
and minetest.get_node_level(p) < num then
|
and minetest.get_node_level(p) < num then
|
||||||
found = true
|
|
||||||
foundx = x
|
foundx = x
|
||||||
foundz = z
|
foundz = z
|
||||||
elseif node.name == "air"
|
elseif node.name == "air"
|
||||||
@ -176,17 +174,27 @@ local function is_uneven(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if found then
|
if foundx then
|
||||||
local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz}
|
local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz}
|
||||||
if is_uneven(p) ~= true then
|
if not is_uneven(p) then
|
||||||
minetest.add_node_level(p, 7)
|
minetest.add_node_level(p, 7)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
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)
|
||||||
|
BIN
mods/snow/models/sled.png
Executable file → Normal file
BIN
mods/snow/models/sled.png
Executable file → Normal file
Binary file not shown.
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 4.1 KiB |
BIN
mods/snow/other_textures/snow_snow_cobble.png_01
Executable file → Normal file
BIN
mods/snow/other_textures/snow_snow_cobble.png_01
Executable file → Normal file
Binary file not shown.
Before Width: | Height: | Size: 570 B After Width: | Height: | Size: 788 B |
@ -108,7 +108,9 @@ minetest.register_abm({
|
|||||||
interval = 20,
|
interval = 20,
|
||||||
chance = 4,
|
chance = 4,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
if node.param2 > 0 then
|
if node.param2 == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
for l = 0,1 do
|
for l = 0,1 do
|
||||||
for i = -1,1,2 do
|
for i = -1,1,2 do
|
||||||
for _,p in pairs({
|
for _,p in pairs({
|
||||||
@ -127,8 +129,8 @@ minetest.register_abm({
|
|||||||
if math.random(8) == 8 then
|
if math.random(8) == 8 then
|
||||||
minetest.add_node(pos, {name="default:water_source"})
|
minetest.add_node(pos, {name="default:water_source"})
|
||||||
else
|
else
|
||||||
minetest.add_node(pos, {name="default:ice", param2 = 0})
|
node.param2 = 0
|
||||||
end
|
minetest.add_node(pos, node)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -141,6 +143,7 @@ minetest.register_abm({
|
|||||||
neighbors = {"snow:moss"},
|
neighbors = {"snow:moss"},
|
||||||
interval = 20,
|
interval = 20,
|
||||||
chance = 6,
|
chance = 6,
|
||||||
|
catch_up = false,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
node.name = "default:mossycobble"
|
node.name = "default:mossycobble"
|
||||||
minetest.add_node(pos, node)
|
minetest.add_node(pos, node)
|
||||||
@ -206,3 +209,17 @@ minetest.register_abm({
|
|||||||
--end
|
--end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--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)
|
||||||
|
minetest.add_node(pos, {name="default:snow"})
|
||||||
|
minetest.set_node_level(pos, 7*(tonumber(node.name:sub(-1))))
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
@ -26,7 +26,8 @@ minetest.register_alias("icysnow", "snow:snow_cobble")
|
|||||||
minetest.register_alias("snowcobble", "snow:snow_cobble")
|
minetest.register_alias("snowcobble", "snow:snow_cobble")
|
||||||
minetest.register_alias("snowycobble", "snow:snow_cobble")
|
minetest.register_alias("snowycobble", "snow:snow_cobble")
|
||||||
minetest.register_alias("cobblesnow", "snow:snow_cobble")
|
minetest.register_alias("cobblesnow", "snow:snow_cobble")
|
||||||
|
minetest.register_alias("snow:leaves", "default:pine_needles")
|
||||||
|
minetest.register_alias("snow:sapling_pine", "default:pine_sapling")
|
||||||
|
|
||||||
-- To clean up my first stairsplus attempt.
|
-- To clean up my first stairsplus attempt.
|
||||||
-- Stair
|
-- Stair
|
||||||
|
@ -31,6 +31,7 @@ near torches and lava.
|
|||||||
* Add code to prevent snowfall from depositing snow on
|
* Add code to prevent snowfall from depositing snow on
|
||||||
'walkable = false' defined nodes.
|
'walkable = false' defined nodes.
|
||||||
|
|
||||||
|
both are already fixed -- Hybrid Dog
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
|
||||||
@ -42,8 +43,9 @@ near torches and lava.
|
|||||||
|
|
||||||
local weather_legacy
|
local weather_legacy
|
||||||
|
|
||||||
|
local worldpath = minetest.get_worldpath()
|
||||||
local read_weather_legacy = function ()
|
local read_weather_legacy = function ()
|
||||||
local file = io.open(minetest.get_worldpath().."/weather_v6", "r")
|
local file = io.open(worldpath.."/weather_v6", "r")
|
||||||
if not file then return end
|
if not file then return end
|
||||||
local readweather = file:read()
|
local readweather = file:read()
|
||||||
file:close()
|
file:close()
|
||||||
@ -52,26 +54,30 @@ end
|
|||||||
|
|
||||||
--Weather for legacy versions of minetest.
|
--Weather for legacy versions of minetest.
|
||||||
local save_weather_legacy = function ()
|
local save_weather_legacy = function ()
|
||||||
local file = io.open(minetest.get_worldpath().."/weather_v6", "w+")
|
local file = io.open(worldpath.."/weather_v6", "w+")
|
||||||
file:write(weather_legacy)
|
file:write(weather_legacy)
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
weather_legacy = read_weather_legacy() or ""
|
weather_legacy = read_weather_legacy() or ""
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
local function leg_step()
|
||||||
if weather_legacy == "snow" then
|
if weather_legacy == "snow" then
|
||||||
if math.random(1, 10000) == 1 then
|
if math.random(1000) == 1 then
|
||||||
weather_legacy = "none"
|
weather_legacy = "none"
|
||||||
save_weather_legacy()
|
save_weather_legacy()
|
||||||
end
|
end
|
||||||
else
|
elseif math.random(5000) == 2 then
|
||||||
if math.random(1, 50000) == 2 then
|
|
||||||
weather_legacy = "snow"
|
weather_legacy = "snow"
|
||||||
save_weather_legacy()
|
save_weather_legacy()
|
||||||
end
|
end
|
||||||
|
minetest.after(2, leg_step)
|
||||||
|
end
|
||||||
|
minetest.after(4, leg_step)
|
||||||
|
|
||||||
|
local function infolog(msg)
|
||||||
|
minetest.log("info", "[snow] falling_snow: "..msg)
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
|
|
||||||
-- copied from meru mod
|
-- copied from meru mod
|
||||||
local SEEDDIFF3 = 9130 -- 9130 -- Values should match minetest mapgen desert perlin.
|
local SEEDDIFF3 = 9130 -- 9130 -- Values should match minetest mapgen desert perlin.
|
||||||
@ -79,29 +85,63 @@ local OCTAVES3 = 3 -- 3
|
|||||||
local PERSISTENCE3 = 0.5 -- 0.5
|
local PERSISTENCE3 = 0.5 -- 0.5
|
||||||
local SCALE3 = 250 -- 250
|
local SCALE3 = 250 -- 250
|
||||||
|
|
||||||
--Get snow at position.
|
-- cache perlin noise tests
|
||||||
local function get_snow(pos)
|
local perlin_scale, rarity
|
||||||
--Legacy support.
|
local cold_perl_values = {}
|
||||||
if weather_legacy == "snow" then
|
setmetatable(cold_perl_values, {__mode = "kv"})
|
||||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
local function cold_perlin_test(x, y)
|
||||||
if perlin1:get2d({x=pos.x, y=pos.z}) <= 0.53 then
|
if not cold_perl_values[y] then
|
||||||
return false
|
cold_perl_values[y] = {}
|
||||||
|
setmetatable(cold_perl_values[y], {__mode = "kv"})
|
||||||
|
end
|
||||||
|
|
||||||
|
local v = cold_perl_values[y][x]
|
||||||
|
if v ~= nil then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
|
if not rarity then
|
||||||
|
rarity = snow.mapgen.smooth_rarity_min
|
||||||
|
perlin_scale = snow.mapgen.perlin_scale
|
||||||
|
end
|
||||||
|
|
||||||
|
v = minetest.get_perlin(112,3, 0.5, perlin_scale):get2d({x=x, y=y}) >= rarity
|
||||||
|
cold_perl_values[y][x] = v
|
||||||
|
return v
|
||||||
end
|
end
|
||||||
|
|
||||||
-- disable falling snow in desert
|
-- disable falling snow in desert
|
||||||
local desert_perlin = minetest.get_perlin(SEEDDIFF3, OCTAVES3, PERSISTENCE3, SCALE3)
|
local desert_perl_values = {}
|
||||||
local noise3 = desert_perlin:get2d({x=pos.x+150,y=pos.z+50}) -- Offsets must match minetest mapgen desert perlin.
|
setmetatable(desert_perl_values, {__mode = "kv"})
|
||||||
if noise3 > 0.35 then -- Smooth transition 0.35 to 0.45.
|
local function is_desert(x, y)
|
||||||
return false
|
if not desert_perl_values[y] then
|
||||||
end
|
desert_perl_values[y] = {}
|
||||||
return true
|
setmetatable(desert_perl_values[y], {__mode = "kv"})
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local addvectors = vector and vector.add
|
local v = desert_perl_values[y][x]
|
||||||
|
if v ~= nil then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Offsets must match minetest mapgen desert perlin.
|
||||||
|
-- Smooth transition 0.35 to 0.45.
|
||||||
|
v = minetest.get_perlin(SEEDDIFF3, OCTAVES3, PERSISTENCE3, SCALE3):get2d({x=x+150,y=y+50}) <= 0.35
|
||||||
|
desert_perl_values[y][x] = v
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
|
--Get snow at position.
|
||||||
|
local function get_snow(pos)
|
||||||
|
return weather_legacy == "snow" --Legacy support.
|
||||||
|
and cold_perlin_test(pos.x, pos.z)
|
||||||
|
and not is_desert(pos.x, pos.z)
|
||||||
|
end
|
||||||
|
|
||||||
|
local addvectors = vector.add
|
||||||
|
|
||||||
--Returns a random position between minp and maxp.
|
--Returns a random position between minp and maxp.
|
||||||
|
-- TODO: make a fload random position
|
||||||
local function randpos(minp, maxp)
|
local function randpos(minp, maxp)
|
||||||
local x,z
|
local x,z
|
||||||
if minp.x > maxp.x then
|
if minp.x > maxp.x then
|
||||||
@ -146,7 +186,7 @@ local function snow_fall(pos, player, animate)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for y=pos.y+10,pos.y-15,-1 do
|
for y=pos.y+9,pos.y-15,-1 do
|
||||||
local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name
|
local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name
|
||||||
if n ~= "air" and n ~= "ignore" then
|
if n ~= "air" and n ~= "ignore" then
|
||||||
ground_y = y
|
ground_y = y
|
||||||
@ -159,7 +199,9 @@ local function snow_fall(pos, player, animate)
|
|||||||
|
|
||||||
pos = {x=pos.x, y=ground_y, z=pos.z}
|
pos = {x=pos.x, y=ground_y, z=pos.z}
|
||||||
|
|
||||||
if get_snow(pos) then
|
if not get_snow(pos) then
|
||||||
|
return
|
||||||
|
end
|
||||||
if animate then
|
if animate then
|
||||||
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
||||||
minetest.add_particlespawner(get_snow_particledef({
|
minetest.add_particlespawner(get_snow_particledef({
|
||||||
@ -173,9 +215,9 @@ local function snow_fall(pos, player, animate)
|
|||||||
snow.place(pos, true)
|
snow.place(pos, true)
|
||||||
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ
|
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ
|
||||||
end
|
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()
|
||||||
@ -184,7 +226,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({
|
||||||
@ -227,8 +269,29 @@ 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
|
||||||
|
infolog("step function set to calc_snowfall")
|
||||||
|
else
|
||||||
|
step_func = function() end
|
||||||
|
infolog("step function set to empty function")
|
||||||
|
end
|
||||||
|
|
||||||
|
snow.register_on_configuring(function(name, v)
|
||||||
|
if name == "enable_snowfall" then
|
||||||
|
if v then
|
||||||
|
step_func = calc_snowfall
|
||||||
|
infolog("step function set to calc_snowfall")
|
||||||
|
else
|
||||||
|
step_func = function() end
|
||||||
|
infolog("step function set to empty function")
|
||||||
|
end
|
||||||
|
elseif name == "lighter_snowfall" then
|
||||||
|
lighter_snowfall = v
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
@ -10,29 +10,70 @@ saplings grow into trees. --]]
|
|||||||
-- ~ LazyJ, 2014_05_13
|
-- ~ LazyJ, 2014_05_13
|
||||||
|
|
||||||
|
|
||||||
--[[ Part 1: To disable the mapgen, add the *starting* comment under this line.
|
-- Part 1: To disable the mapgen, add the *starting* comment under this line.
|
||||||
|
|
||||||
|
|
||||||
|
snow.mapgen = snow.mapgen or {}
|
||||||
|
local mg = snow.mapgen
|
||||||
|
|
||||||
|
-- perlin noise "hills" are not peaks but looking like sinus curve
|
||||||
|
local function upper_rarity(rarity)
|
||||||
|
return math.sign(rarity)*math.sin(math.abs(rarity)*math.pi/2)
|
||||||
|
end
|
||||||
|
|
||||||
|
local rarity = snow.mapgen_rarity
|
||||||
|
local size = snow.mapgen_size
|
||||||
|
local smooth = snow.smooth_biomes
|
||||||
|
|
||||||
|
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
|
||||||
|
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.
|
||||||
minetest.register_on_mapgen_init(function(MapgenParams)
|
local mgname = minetest.get_mapgen_setting"mg_name"
|
||||||
local mgname = MapgenParams.mgname
|
|
||||||
if not mgname then
|
if not mgname then
|
||||||
io.write("[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!\n")
|
minetest.log("error", "[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!")
|
||||||
end
|
end
|
||||||
|
local path = minetest.get_modpath"snow"
|
||||||
if mgname == "v7" then
|
if mgname == "v7" then
|
||||||
--Load mapgen_v7 compatibility.
|
--Load mapgen_v7 compatibility.
|
||||||
dofile(minetest.get_modpath("snow").."/src/mapgen_v7.lua")
|
dofile(path.."/src/mapgen_v7.lua")
|
||||||
else
|
else
|
||||||
--Load mapgen_v6 compatibility.
|
--Load mapgen_v6 compatibility.
|
||||||
dofile(minetest.get_modpath("snow").."/src/mapgen_v6.lua")
|
dofile(path.."/src/mapgen_v6.lua")
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
|
|
||||||
-- To complete the commenting-out add the *closing* comment under this line.
|
-- To complete the commenting-out add the *closing* comment under this line.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local pine_tree = {
|
local pine_tree = {
|
||||||
axiom="TABff",
|
axiom="TABff",
|
||||||
rules_a="[&T+f+ff+ff+ff+f]GA",
|
rules_a="[&T+f+ff+ff+ff+f]GA",
|
||||||
@ -66,7 +107,6 @@ local xmas_tree = {
|
|||||||
--Makes pine tree
|
--Makes pine tree
|
||||||
function snow.make_pine(pos,snow,xmas)
|
function snow.make_pine(pos,snow,xmas)
|
||||||
local minetest = minetest
|
local minetest = minetest
|
||||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
|
||||||
local try_node = function(pos, node)
|
local try_node = function(pos, node)
|
||||||
local n = minetest.get_node(pos).name
|
local n = minetest.get_node(pos).name
|
||||||
if n == "air"
|
if n == "air"
|
||||||
@ -95,7 +135,7 @@ function snow.make_pine(pos,snow,xmas)
|
|||||||
if xmas then
|
if xmas then
|
||||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ
|
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ
|
||||||
elseif snow
|
elseif snow
|
||||||
and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
and minetest.get_perlin(112,3, 0.5, perlin_scale):get2d({x=pos.x,y=pos.z}) > nosmooth_rarity then
|
||||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
|
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -109,7 +149,7 @@ function snow.voxelmanip_pine(pos,a,data)
|
|||||||
local c_pinetree = minetest.get_content_id("default:pinetree")
|
local c_pinetree = minetest.get_content_id("default:pinetree")
|
||||||
local c_air = minetest.get_content_id("air")
|
local c_air = minetest.get_content_id("air")
|
||||||
|
|
||||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
local perlin1 = minetest.get_perlin(112,3, 0.5, perlin_scale)
|
||||||
for z = -1,1 do
|
for z = -1,1 do
|
||||||
local z = pos.z + z
|
local z = pos.z + z
|
||||||
for x = -1,1 do
|
for x = -1,1 do
|
||||||
@ -120,7 +160,7 @@ function snow.voxelmanip_pine(pos,a,data)
|
|||||||
data[a:index(x,pos.y+i,z)] = c_pine_needles
|
data[a:index(x,pos.y+i,z)] = c_pine_needles
|
||||||
if x ~= 0
|
if x ~= 0
|
||||||
and z ~= 0
|
and z ~= 0
|
||||||
and perlin1:get2d({x=x,y=z}) > 0.53 then
|
and perlin1:get2d({x=x,y=z}) > nosmooth_rarity then
|
||||||
local abovenode = a:index(x,pos.y+i+1,z)
|
local abovenode = a:index(x,pos.y+i+1,z)
|
||||||
data[abovenode] = c_snow
|
data[abovenode] = c_snow
|
||||||
end
|
end
|
||||||
@ -135,16 +175,16 @@ function snow.voxelmanip_pine(pos,a,data)
|
|||||||
data[a:index(x-1,y,z)] = c_pine_needles
|
data[a:index(x-1,y,z)] = c_pine_needles
|
||||||
data[a:index(x,y,z+1)] = c_pine_needles
|
data[a:index(x,y,z+1)] = c_pine_needles
|
||||||
data[a:index(x,y,z-1)] = c_pine_needles
|
data[a:index(x,y,z-1)] = c_pine_needles
|
||||||
if perlin1:get2d({x=x+1,y=z}) > 0.53 then
|
if perlin1:get2d({x=x+1,y=z}) > nosmooth_rarity then
|
||||||
data[a:index(x+1,y+1,z)] = c_snow
|
data[a:index(x+1,y+1,z)] = c_snow
|
||||||
end
|
end
|
||||||
if perlin1:get2d({x=x+1,y=z}) > 0.53 then
|
if perlin1:get2d({x=x+1,y=z}) > nosmooth_rarity then
|
||||||
data[a:index(x-1,y+1,z)] = c_snow
|
data[a:index(x-1,y+1,z)] = c_snow
|
||||||
end
|
end
|
||||||
if perlin1:get2d({x=x,y=z+1}) > 0.53 then
|
if perlin1:get2d({x=x,y=z+1}) > nosmooth_rarity then
|
||||||
data[a:index(x,y+1,z+1)] = c_snow
|
data[a:index(x,y+1,z+1)] = c_snow
|
||||||
end
|
end
|
||||||
if perlin1:get2d({x=x,y=z-1}) > 0.53 then
|
if perlin1:get2d({x=x,y=z-1}) > nosmooth_rarity then
|
||||||
data[a:index(x,y+1,z-1)] = c_snow
|
data[a:index(x,y+1,z-1)] = c_snow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -153,8 +193,7 @@ function snow.voxelmanip_pine(pos,a,data)
|
|||||||
end
|
end
|
||||||
data[a:index(pos.x,pos.y+5,pos.z)] = c_pine_needles
|
data[a:index(pos.x,pos.y+5,pos.z)] = c_pine_needles
|
||||||
data[a:index(pos.x,pos.y+6,pos.z)] = c_pine_needles
|
data[a:index(pos.x,pos.y+6,pos.z)] = c_pine_needles
|
||||||
if perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
if perlin1:get2d({x=pos.x,y=pos.z}) > nosmooth_rarity then
|
||||||
data[a:index(pos.x,pos.y+7,pos.z)] = c_snow
|
data[a:index(pos.x,pos.y+7,pos.z)] = c_snow
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
]]
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
-- https://github.com/paramat/meru/blob/master/init.lua#L52
|
-- https://github.com/paramat/meru/blob/master/init.lua#L52
|
||||||
--[[ Parameters must match mgv6 biome noise
|
-- Parameters must match mgv6 biome noise
|
||||||
|
|
||||||
local np_default = {
|
local np_default = {
|
||||||
offset = 0,
|
offset = 0,
|
||||||
scale = 1,
|
scale = 1,
|
||||||
@ -9,17 +10,21 @@ local np_default = {
|
|||||||
persist = 0.5
|
persist = 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-- 2D noise for coldness
|
-- 2D noise for coldness
|
||||||
|
|
||||||
|
local mg = snow.mapgen
|
||||||
|
local scale = mg.perlin_scale
|
||||||
local np_cold = {
|
local np_cold = {
|
||||||
offset = 0,
|
offset = 0,
|
||||||
scale = -1,
|
scale = 1,
|
||||||
spread = {x=256, y=256, z=256},
|
spread = {x=scale, y=scale, z=scale},
|
||||||
seed = 112,
|
seed = 112,
|
||||||
octaves = 3,
|
octaves = 3,
|
||||||
persist = 0.5
|
persist = 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-- 2D noise for icetype
|
-- 2D noise for icetype
|
||||||
|
|
||||||
local np_ice = {
|
local np_ice = {
|
||||||
@ -31,29 +36,39 @@ local np_ice = {
|
|||||||
persist = 0.5
|
persist = 0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
-- 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 = math.pi * x / 16000
|
||||||
local y = 0
|
local y = 0
|
||||||
for k = 1,1000 do
|
for k = 1,1000 do
|
||||||
y = y + 1000*math.sin(math.pi * k^a * n)/(math.pi * k^a)
|
y = y + math.sin(k^a * n)/(k^a)
|
||||||
end
|
end
|
||||||
return y
|
return 1000*y/math.pi
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- caching functions
|
||||||
|
|
||||||
|
local ws_values = {}
|
||||||
|
local function get_ws_value(a, x)
|
||||||
|
local v = ws_values[a]
|
||||||
|
if v then
|
||||||
|
v = v[x]
|
||||||
|
if v then
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
else
|
||||||
|
ws_values[a] = {}
|
||||||
|
-- weak table, see https://www.lua.org/pil/17.1.html
|
||||||
|
setmetatable(ws_values[a], {__mode = "kv"})
|
||||||
|
end
|
||||||
|
v = do_ws_func(a, x)
|
||||||
|
ws_values[a][x] = v
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
local plantlike_ids = {}
|
local plantlike_ids = {}
|
||||||
|
setmetatable(plantlike_ids, {__mode = "kv"})
|
||||||
local function is_plantlike(id)
|
local function is_plantlike(id)
|
||||||
if plantlike_ids[id] ~= nil then
|
if plantlike_ids[id] ~= nil then
|
||||||
return plantlike_ids[id]
|
return plantlike_ids[id]
|
||||||
@ -74,6 +89,7 @@ local function is_plantlike(id)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local snowable_ids = {}
|
local snowable_ids = {}
|
||||||
|
setmetatable(snowable_ids, {__mode = "kv"})
|
||||||
local function is_snowable(id)
|
local function is_snowable(id)
|
||||||
if snowable_ids[id] ~= nil then
|
if snowable_ids[id] ~= nil then
|
||||||
return snowable_ids[id]
|
return snowable_ids[id]
|
||||||
@ -95,7 +111,8 @@ local function is_snowable(id)
|
|||||||
return true
|
return true
|
||||||
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"),
|
||||||
@ -120,8 +137,41 @@ 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_rarity_max = mg.smooth_rarity_max
|
||||||
|
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)
|
minetest.register_on_generated(function(minp, maxp, seed)
|
||||||
local t1 = os.clock()
|
local t1 = os.clock()
|
||||||
|
|
||||||
@ -130,23 +180,23 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local x1 = maxp.x
|
local x1 = maxp.x
|
||||||
local z1 = maxp.z
|
local z1 = maxp.z
|
||||||
|
|
||||||
local smooth = snow.smooth_biomes
|
|
||||||
|
|
||||||
if not c then
|
if not c then
|
||||||
define_contents()
|
define_contents()
|
||||||
end
|
end
|
||||||
|
|
||||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
local vm, emin, emax = minetest.get_mapgen_object"voxelmanip"
|
||||||
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
|
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
||||||
local data = vm:get_data()
|
local data = vm:get_data()
|
||||||
local param2s = vm:get_param2_data()
|
local param2s = vm:get_param2_data()
|
||||||
|
|
||||||
|
local heightmap = minetest.get_mapgen_object"heightmap"
|
||||||
|
|
||||||
local snow_tab,num = {},1
|
local snow_tab,num = {},1
|
||||||
local pines_tab,pnum = {},1
|
local pines_tab,pnum = {},1
|
||||||
|
|
||||||
local sidelen = x1 - x0 + 1
|
local sidelen = x1 - x0 + 1
|
||||||
local chulens = {x=sidelen, y=sidelen, z=sidelen}
|
local chulens = {x=sidelen, y=sidelen, z=sidelen}
|
||||||
local nvals_default = minetest.get_perlin_map(np_default, chulens):get2dMap_flat({x=x0+150, y=z0+50})
|
local nvals_default = minetest.get_perlin_map(np_default, chulens):get2dMap_flat{x=x0+150, y=z0+50}
|
||||||
local nvals_cold, nvals_ice
|
local nvals_cold, nvals_ice
|
||||||
|
|
||||||
-- Choose biomes
|
-- Choose biomes
|
||||||
@ -162,7 +212,10 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
-- Reseed random
|
-- Reseed random
|
||||||
pr = PseudoRandom(seed+68)
|
pr = PseudoRandom(seed+68)
|
||||||
|
|
||||||
|
local nodes_added
|
||||||
|
|
||||||
-- Loop through columns in chunk
|
-- Loop through columns in chunk
|
||||||
|
local smooth = smooth and not snowy
|
||||||
local write_to_map = false
|
local write_to_map = false
|
||||||
local ni = 1
|
local ni = 1
|
||||||
for z = z0, z1 do
|
for z = z0, z1 do
|
||||||
@ -171,15 +224,18 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local test
|
local test
|
||||||
if nvals_default[ni] < 0.35 then
|
if nvals_default[ni] < 0.35 then
|
||||||
if not nvals_cold then
|
if not nvals_cold then
|
||||||
nvals_cold = minetest.get_perlin_map(np_cold, chulens):get2dMap_flat({x=x0, y=z0})
|
nvals_cold = minetest.get_perlin_map(np_cold, chulens):get2dMap_flat{x=x0, y=z0}
|
||||||
end
|
end
|
||||||
test = math.min(nvals_cold[ni], 1)
|
test = math.min(nvals_cold[ni], 1)
|
||||||
if smooth
|
if smooth then
|
||||||
and not snowy then
|
if test >= smooth_rarity_max
|
||||||
if (test > 0.73 or (test > 0.43 and pr:next(0,29) > (0.73 - test) * 100 )) then
|
or (
|
||||||
|
test > smooth_rarity_min
|
||||||
|
and pr:next(1, 1000) <= ((test-smooth_rarity_min)/smooth_rarity_dif)*1000
|
||||||
|
) then
|
||||||
in_biome = true
|
in_biome = true
|
||||||
end
|
end
|
||||||
elseif test > 0.53 then
|
elseif test > nosmooth_rarity then
|
||||||
in_biome = true
|
in_biome = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -187,25 +243,23 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
if not in_biome then
|
if not in_biome then
|
||||||
if alpine
|
if alpine
|
||||||
and test
|
and test
|
||||||
and test > 0.43 then
|
and test > smooth_rarity_min then
|
||||||
-- remove trees near alpine
|
-- remove trees near alpine
|
||||||
local ground_y = nil
|
local ground_y
|
||||||
for y = maxp.y, minp.y, -1 do
|
if data[area:index(x, maxp.y, z)] == c.air then
|
||||||
local nodid = data[area:index(x, y, z)]
|
for y = math.min(heightmap[ni]+20, maxp.y), math.max(minp.y, heightmap[ni]-5), -1 do
|
||||||
if nodid ~= c.air
|
if data[area:index(x, y, z)] ~= c.air then
|
||||||
and nodid ~= c.ignore then
|
|
||||||
ground_y = y
|
ground_y = y
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if ground_y == maxp.y then -- avoid awful snow layers at chunk boundaries underground
|
|
||||||
ground_y = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ground_y then
|
if ground_y then
|
||||||
local vi = area:index(x, ground_y, z)
|
local vi = area:index(x, ground_y, z)
|
||||||
if data[vi] == c.leaves
|
if data[vi] == c.leaves
|
||||||
or data[vi] == c.jungleleaves then
|
or data[vi] == c.jungleleaves then
|
||||||
|
nodes_added = true
|
||||||
for y = ground_y, -16, -1 do
|
for y = ground_y, -16, -1 do
|
||||||
local vi = area:index(x, y, z)
|
local vi = area:index(x, y, z)
|
||||||
local id = data[vi]
|
local id = data[vi]
|
||||||
@ -224,9 +278,10 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
nodes_added = true
|
||||||
write_to_map = true
|
write_to_map = true
|
||||||
if not nvals_ice then
|
if not nvals_ice then
|
||||||
nvals_ice = minetest.get_perlin_map(np_ice, chulens):get2dMap_flat({x=x0, y=z0})
|
nvals_ice = minetest.get_perlin_map(np_ice, chulens):get2dMap_flat{x=x0, y=z0}
|
||||||
end
|
end
|
||||||
local icetype = nvals_ice[ni]
|
local icetype = nvals_ice[ni]
|
||||||
local cool = icetype > 0 -- only spawns ice on edge of water
|
local cool = icetype > 0 -- only spawns ice on edge of water
|
||||||
@ -235,16 +290,17 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
local icesheet = icetype > -0.6 and icetype <= -0.4
|
local icesheet = icetype > -0.6 and icetype <= -0.4
|
||||||
local icecave = icetype <= -0.6
|
local icecave = icetype <= -0.6
|
||||||
|
|
||||||
|
|
||||||
local ground_y
|
local ground_y
|
||||||
for y = maxp.y, minp.y, -1 do
|
-- avoid generating underground
|
||||||
local nodid = data[area:index(x, y, z)]
|
if data[area:index(x, maxp.y, z)] == c.air then
|
||||||
if nodid ~= c.air and nodid ~= c.ignore then
|
-- search for non air node from 20 m above ground down to 5 m below ground (confined by minp and maxp)
|
||||||
|
for y = math.min(heightmap[ni]+20, maxp.y), math.max(minp.y, heightmap[ni]-5), -1 do
|
||||||
|
if data[area:index(x, y, z)] ~= c.air then
|
||||||
ground_y = y
|
ground_y = y
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if ground_y == maxp.y then -- avoid awful snow layers at chunk boundaries underground
|
|
||||||
ground_y = nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ground_y then
|
if ground_y then
|
||||||
@ -253,7 +309,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
|
|
||||||
if c_ground == c.dirt_with_grass then
|
if c_ground == c.dirt_with_grass then
|
||||||
if alpine
|
if alpine
|
||||||
and test > 0.53 then
|
and test > nosmooth_rarity then
|
||||||
snow_tab[num] = {ground_y, z, x, test}
|
snow_tab[num] = {ground_y, z, x, test}
|
||||||
num = num+1
|
num = num+1
|
||||||
-- generate stone ground
|
-- generate stone ground
|
||||||
@ -274,7 +330,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
data[area:index(x, ground_y+1, z)] = c.dry_shrub
|
data[area:index(x, ground_y+1, z)] = c.dry_shrub
|
||||||
else
|
else
|
||||||
if snowy
|
if snowy
|
||||||
or test > 0.8 then
|
or test > smooth_rarity_max then
|
||||||
-- more, deeper snow
|
-- more, deeper snow
|
||||||
data[node] = c.snow_block
|
data[node] = c.snow_block
|
||||||
else
|
else
|
||||||
@ -363,7 +419,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--[[ elseif alpine then
|
elseif alpine then
|
||||||
-- make stone pillars out of trees and other stuff
|
-- make stone pillars out of trees and other stuff
|
||||||
for y = ground_y, math.max(-6, minp.y-6), -1 do
|
for y = ground_y, math.max(-6, minp.y-6), -1 do
|
||||||
local stone = area:index(x, y, z)
|
local stone = area:index(x, y, z)
|
||||||
@ -374,7 +430,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
end
|
end
|
||||||
-- put snow onto it
|
-- put snow onto it
|
||||||
snow_tab[num] = {ground_y, z, x, test}
|
snow_tab[num] = {ground_y, z, x, test}
|
||||||
num = num+1 --]] -- MFF (06/10/2015)
|
num = num+1
|
||||||
elseif c_ground ~= c.desert_sand then
|
elseif c_ground ~= c.desert_sand then
|
||||||
if is_snowable(c_ground) then
|
if is_snowable(c_ground) then
|
||||||
-- put snow onto it
|
-- put snow onto it
|
||||||
@ -414,19 +470,26 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- abort if mapgen doesn't change sth
|
||||||
|
if not nodes_added then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- try to fix oom memory crashes
|
||||||
|
minetest.after(0, collectgarbage)
|
||||||
|
|
||||||
if num ~= 1 then
|
if num ~= 1 then
|
||||||
for _,i in pairs(snow_tab) do
|
for _,i in pairs(snow_tab) do
|
||||||
-- set snow
|
-- set snow
|
||||||
data[area:index(i[3], i[1]+1, i[2])] = c.snow
|
data[area:index(i[3], i[1]+1, i[2])] = c.snow
|
||||||
end
|
end
|
||||||
local wsz, wsx
|
|
||||||
for _,i in pairs(snow_tab) do
|
for _,i in pairs(snow_tab) do
|
||||||
local y,z,x,test = unpack(i)
|
local y,z,x,test = unpack(i)
|
||||||
test = (test-0.53)/0.47 -- /(1-0.53)
|
test = (test-nosmooth_rarity)/(1-nosmooth_rarity) -- /(1-0.53)
|
||||||
if test > 0 then
|
if test > 0 then
|
||||||
local maxh = math.floor(test*10)%10+1
|
local maxh = math.floor(test*10)%10+1
|
||||||
if maxh ~= 1 then
|
if maxh ~= 1 then
|
||||||
local h = math.floor( do_ws_func(2, x) + do_ws_func(5, z)*5)%10+1
|
local h = math.floor(get_ws_value(2, x) + get_ws_value(5, z)*5)%10+1
|
||||||
if h ~= 1 then
|
if h ~= 1 then
|
||||||
-- search for nearby snow
|
-- search for nearby snow
|
||||||
y = y+1
|
y = y+1
|
||||||
@ -477,10 +540,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
|
||||||
|
@ -6,8 +6,8 @@ minetest.register_biome({
|
|||||||
node_filler = "default:dirt",
|
node_filler = "default:dirt",
|
||||||
depth_filler = 2,
|
depth_filler = 2,
|
||||||
|
|
||||||
y_min = snow.min_height,
|
height_min = snow.min_height,
|
||||||
y_max = snow.min_height+60,
|
height_max = snow.min_height+60,
|
||||||
heat_point = 10.0,
|
heat_point = 10.0,
|
||||||
humidity_point = 40.0,
|
humidity_point = 40.0,
|
||||||
})
|
})
|
||||||
@ -20,8 +20,8 @@ minetest.register_biome({
|
|||||||
node_filler = "default:dirt",
|
node_filler = "default:dirt",
|
||||||
depth_filler = 2,
|
depth_filler = 2,
|
||||||
|
|
||||||
y_min = snow.min_height,
|
height_min = snow.min_height,
|
||||||
y_max = snow.min_height+60,
|
height_max = snow.min_height+60,
|
||||||
heat_point = 10.0,
|
heat_point = 10.0,
|
||||||
humidity_point = 55.0,
|
humidity_point = 55.0,
|
||||||
})
|
})
|
||||||
@ -34,8 +34,8 @@ minetest.register_biome({
|
|||||||
node_filler = "default:dirt",
|
node_filler = "default:dirt",
|
||||||
depth_filler = 2,
|
depth_filler = 2,
|
||||||
|
|
||||||
y_min = snow.min_height,
|
height_min = snow.min_height,
|
||||||
y_max = snow.min_height+60,
|
height_max = snow.min_height+60,
|
||||||
heat_point = 10.0,
|
heat_point = 10.0,
|
||||||
humidity_point = 70.0,
|
humidity_point = 70.0,
|
||||||
})
|
})
|
||||||
@ -47,8 +47,8 @@ minetest.register_biome({
|
|||||||
depth_top = 1,
|
depth_top = 1,
|
||||||
node_filler = "default:stone",
|
node_filler = "default:stone",
|
||||||
|
|
||||||
y_min = snow.min_height+60,
|
height_min = snow.min_height+60,
|
||||||
y_max = 31000,
|
height_max = 31000,
|
||||||
heat_point = 10.0,
|
heat_point = 10.0,
|
||||||
humidity_point = 40.0,
|
humidity_point = 40.0,
|
||||||
})
|
})
|
||||||
@ -61,8 +61,8 @@ minetest.register_biome({
|
|||||||
node_filler = "default:stone",
|
node_filler = "default:stone",
|
||||||
depth_filler = 0,
|
depth_filler = 0,
|
||||||
|
|
||||||
y_min = -31000,
|
height_min = -31000,
|
||||||
y_max = 2,
|
height_max = 2,
|
||||||
heat_point = 10.0,
|
heat_point = 10.0,
|
||||||
humidity_point = 40.0,
|
humidity_point = 40.0,
|
||||||
})
|
})
|
||||||
|
@ -38,17 +38,27 @@ 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
|
||||||
--Christmas easter egg
|
table.insert(drop.items, 1, {
|
||||||
minetest.register_on_mapgen_init( function()
|
items = {"snow:xmas_tree"},
|
||||||
if rawget(_G, "skins") then
|
rarity = 120,
|
||||||
skins.add("character_snow_man")
|
})
|
||||||
|
else
|
||||||
|
table.remove(drop.items, 1)
|
||||||
end
|
end
|
||||||
|
minetest.override_item("snow:needles", {drop = drop})
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Christmas egg
|
||||||
|
if minetest.global_exists"skins" then
|
||||||
|
skins.add"character_snow_man"
|
||||||
end
|
end
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
-- Decorated Pine Leaves
|
-- Decorated Pine Leaves
|
||||||
@ -181,6 +191,7 @@ minetest.register_node("snow:shrub", table.copy(nodedef))
|
|||||||
nodedef.tiles = {"snow_shrub.png^snow_shrub_covering.png"}
|
nodedef.tiles = {"snow_shrub.png^snow_shrub_covering.png"}
|
||||||
nodedef.inventory_image = "snow_shrub.png^snow_shrub_covering.png"
|
nodedef.inventory_image = "snow_shrub.png^snow_shrub_covering.png"
|
||||||
nodedef.wield_image = "snow_shrub.png^snow_shrub_covering.png"
|
nodedef.wield_image = "snow_shrub.png^snow_shrub_covering.png"
|
||||||
|
nodedef.paramtype2 = "degrotate"
|
||||||
nodedef.drop = "snow:shrub"
|
nodedef.drop = "snow:shrub"
|
||||||
nodedef.furnace_burntime = 3
|
nodedef.furnace_burntime = 3
|
||||||
minetest.register_node("snow:shrub_covered", nodedef)
|
minetest.register_node("snow:shrub_covered", nodedef)
|
||||||
@ -198,6 +209,7 @@ if rawget(_G, "flowers") then
|
|||||||
tiles = { "snow_" .. name .. ".png" },
|
tiles = { "snow_" .. name .. ".png" },
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
|
paramtype2 = "degrotate",
|
||||||
walkable = false,
|
walkable = false,
|
||||||
drop = "",
|
drop = "",
|
||||||
groups = {snappy=3, attached_node = 1},
|
groups = {snappy=3, attached_node = 1},
|
||||||
@ -232,6 +244,7 @@ nodedef = {
|
|||||||
drawtype = "plantlike",
|
drawtype = "plantlike",
|
||||||
tiles = {"snow_apple.png"},
|
tiles = {"snow_apple.png"},
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
|
paramtype2 = "degrotate",
|
||||||
walkable = false,
|
walkable = false,
|
||||||
sunlight_propagates = apple.sunlight_propagates,
|
sunlight_propagates = apple.sunlight_propagates,
|
||||||
selection_box = apple.selection_box,
|
selection_box = apple.selection_box,
|
||||||
|
@ -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(self, 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(self, 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})
|
||||||
|
@ -8,13 +8,30 @@
|
|||||||
|
|
||||||
local creative_mode = minetest.setting_getbool("creative_mode")
|
local creative_mode = minetest.setting_getbool("creative_mode")
|
||||||
|
|
||||||
|
|
||||||
|
local snowball_velocity, entity_attack_delay
|
||||||
|
local function update_snowball_vel(v)
|
||||||
|
snowball_velocity = v
|
||||||
|
local walkspeed = tonumber(minetest.setting_get("movement_speed_walk")) or 4
|
||||||
|
entity_attack_delay = (walkspeed+1)/v
|
||||||
|
end
|
||||||
|
update_snowball_vel(snow.snowball_velocity)
|
||||||
|
|
||||||
|
local snowball_gravity = snow.snowball_gravity
|
||||||
|
snow.register_on_configuring(function(name, v)
|
||||||
|
if name == "snowball_velocity" then
|
||||||
|
update_snowball_vel(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, just_acitvated
|
||||||
local timer = 0
|
|
||||||
|
|
||||||
--Shoot snowball
|
--Shoot snowball
|
||||||
local function snow_shoot_snowball(item, player)
|
local function snow_shoot_snowball(item, player)
|
||||||
@ -25,13 +42,13 @@ 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:get_luaentity().thrower = player:get_player_name()
|
obj:setvelocity(vector.multiply(dir, snowball_velocity))
|
||||||
obj:setvelocity(vector.multiply(dir, snow.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})
|
||||||
|
obj:get_luaentity().thrower = player:get_player_name()
|
||||||
if creative_mode then
|
if creative_mode then
|
||||||
if not someone_throwing then
|
if not someone_throwing then
|
||||||
someone_throwing = true
|
someone_throwing = true
|
||||||
timer = -0.5
|
just_acitvated = true
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -40,13 +57,7 @@ local function snow_shoot_snowball(item, player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if creative_mode then
|
if creative_mode then
|
||||||
local function update_step(dtime)
|
local function update_step()
|
||||||
timer = timer+dtime
|
|
||||||
if timer < 0.006 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
timer = 0
|
|
||||||
|
|
||||||
local active
|
local active
|
||||||
for _,player in pairs(minetest.get_connected_players()) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
if player:get_player_control().LMB then
|
if player:get_player_control().LMB then
|
||||||
@ -66,13 +77,21 @@ if creative_mode then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- do automatic throwing using a globalstep
|
-- do automatic throwing using minetest.after
|
||||||
minetest.register_globalstep(function(dtime)
|
local function do_step()
|
||||||
|
local timer
|
||||||
-- only if one holds left click
|
-- only if one holds left click
|
||||||
if someone_throwing then
|
if someone_throwing
|
||||||
update_step(dtime)
|
and not just_acitvated then
|
||||||
|
update_step()
|
||||||
|
timer = 0.006
|
||||||
|
else
|
||||||
|
timer = 0.5
|
||||||
|
just_acitvated = false
|
||||||
end
|
end
|
||||||
end)
|
minetest.after(timer, do_step)
|
||||||
|
end
|
||||||
|
minetest.after(3, do_step)
|
||||||
end
|
end
|
||||||
|
|
||||||
--The snowball Entity
|
--The snowball Entity
|
||||||
@ -80,7 +99,6 @@ local snow_snowball_ENTITY = {
|
|||||||
physical = false,
|
physical = false,
|
||||||
timer = 0,
|
timer = 0,
|
||||||
collisionbox = {-5/16,-5/16,-5/16, 5/16,5/16,5/16},
|
collisionbox = {-5/16,-5/16,-5/16, 5/16,5/16,5/16},
|
||||||
thrower = "",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function snow_snowball_ENTITY.on_activate(self)
|
function snow_snowball_ENTITY.on_activate(self)
|
||||||
@ -118,25 +136,6 @@ function snow_snowball_ENTITY.on_step(self, dtime)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.timer > 0.15 then
|
|
||||||
for i, v in pairs(minetest.get_objects_inside_radius(self.object:getpos(), 1)) do
|
|
||||||
if v ~= self.object then
|
|
||||||
local entity_name = v:get_entity_name()
|
|
||||||
if entity_name and entity_name ~= "snow:snowball_entity"
|
|
||||||
and entity_name ~= "__builtin:item"
|
|
||||||
and entity_name ~= "gauges:hp_bar" then
|
|
||||||
local puncher = self.object
|
|
||||||
if minetest.get_player_by_name(self.thrower or "") then
|
|
||||||
puncher = minetest.get_player_by_name(self.thrower)
|
|
||||||
end
|
|
||||||
v:punch(puncher, 1.0, {full_punch_interval=1.0, damage_groups = {fleshy=1} })
|
|
||||||
minetest.add_item(self.object:getpos(), "default:snow")
|
|
||||||
self.object:remove()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if self.physical then
|
if self.physical then
|
||||||
local fell = self.object:getvelocity().y == 0
|
local fell = self.object:getvelocity().y == 0
|
||||||
if not fell then
|
if not fell then
|
||||||
@ -163,13 +162,41 @@ function snow_snowball_ENTITY.on_step(self, dtime)
|
|||||||
--self.object:setvelocity({x=0, y=0, z=0})
|
--self.object:setvelocity({x=0, y=0, z=0})
|
||||||
pos = self.lastpos
|
pos = self.lastpos
|
||||||
self.object:setpos(pos)
|
self.object:setpos(pos)
|
||||||
local gain = vector.length(self.object:getvelocity())/30
|
minetest.sound_play("default_snow_footstep", {pos=pos, gain=vector.length(self.object:getvelocity())/30})
|
||||||
minetest.sound_play("default_snow_footstep", {pos=pos, gain=gain})
|
|
||||||
self.object:set_properties({physical = true})
|
self.object:set_properties({physical = true})
|
||||||
self.physical = true
|
self.physical = true
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.lastpos = vector.new(pos)
|
self.lastpos = vector.new(pos)
|
||||||
|
|
||||||
|
if self.timer < entity_attack_delay then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for _,v in pairs(minetest.get_objects_inside_radius(pos, 1.73)) do
|
||||||
|
if v ~= self.object then
|
||||||
|
local entity_name = v:get_entity_name()
|
||||||
|
if entity_name ~= "snow:snowball_entity"
|
||||||
|
and entity_name ~= "__builtin:item"
|
||||||
|
and entity_name ~= "gauges:hp_bar" then
|
||||||
|
local vvel = v:getvelocity() or v:get_player_velocity()
|
||||||
|
local veldif = self.object:getvelocity()
|
||||||
|
if vvel then
|
||||||
|
veldif = vector.subtract(veldif, vvel)
|
||||||
|
end
|
||||||
|
local gain = vector.length(veldif)/20
|
||||||
|
v:punch(
|
||||||
|
(self.thrower and minetest.get_player_by_name(self.thrower))
|
||||||
|
or self.object,
|
||||||
|
1,
|
||||||
|
{full_punch_interval=1, damage_groups = {fleshy=math.ceil(gain)}}
|
||||||
|
)
|
||||||
|
minetest.sound_play("default_snow_footstep", {pos=pos, gain=gain})
|
||||||
|
spawn_falling_node(pos, {name = "default:snow"})
|
||||||
|
self.object:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ snow = {
|
|||||||
christmas_content = true,
|
christmas_content = true,
|
||||||
smooth_snow = true,
|
smooth_snow = true,
|
||||||
min_height = 3,
|
min_height = 3,
|
||||||
|
mapgen_rarity = 18,
|
||||||
|
mapgen_size = 210,
|
||||||
}
|
}
|
||||||
|
|
||||||
--Config documentation.
|
--Config documentation.
|
||||||
@ -24,74 +26,115 @@ local doc = {
|
|||||||
smooth_snow = "Disable this to stop snow from being smoothed.",
|
smooth_snow = "Disable this to stop snow from being smoothed.",
|
||||||
christmas_content = "Disable this to remove christmas saplings from being found.",
|
christmas_content = "Disable this to remove christmas saplings from being found.",
|
||||||
min_height = "The minumum height a snow biome will generate (mgv7)",
|
min_height = "The minumum height a snow biome will generate (mgv7)",
|
||||||
|
mapgen_rarity = "mapgen rarity in %",
|
||||||
|
mapgen_size = "size of the generated… (has an effect to the rarity, too)",
|
||||||
}
|
}
|
||||||
|
|
||||||
--Manage config.
|
|
||||||
|
-- functions for dynamically changing settings
|
||||||
|
|
||||||
|
local on_configurings,n = {},1
|
||||||
|
function snow.register_on_configuring(func)
|
||||||
|
on_configurings[n] = func
|
||||||
|
n = n+1
|
||||||
|
end
|
||||||
|
|
||||||
|
local function change_setting(name, value)
|
||||||
|
if snow[name] == value then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for i = 1,n-1 do
|
||||||
|
if on_configurings[i](name, value) == false then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
snow[name] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function value_from_string(v)
|
||||||
|
if v == "true" then
|
||||||
|
v = true
|
||||||
|
elseif v == "false" then
|
||||||
|
v = false
|
||||||
|
else
|
||||||
|
local a_number = tonumber(v)
|
||||||
|
if a_number then
|
||||||
|
v = a_number
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return v
|
||||||
|
end
|
||||||
|
|
||||||
|
local allowed_types = {string = true, number = true, boolean = true}
|
||||||
|
|
||||||
--Saves contents of config to file.
|
--Saves contents of config to file.
|
||||||
local function saveConfig(path, config, doc)
|
local function saveConfig(path, config, doc)
|
||||||
local file = io.open(path,"w")
|
local file = io.open(path,"w")
|
||||||
if file then
|
if not file then
|
||||||
|
minetest.log("error", "[snow] could not open config file for writing at "..path)
|
||||||
|
return
|
||||||
|
end
|
||||||
for i,v in pairs(config) do
|
for i,v in pairs(config) do
|
||||||
local t = type(v)
|
if allowed_types[type(v)] then
|
||||||
if t == "string" or t == "number" or t == "boolean" then
|
|
||||||
if doc and doc[i] then
|
if doc and doc[i] then
|
||||||
file:write("# "..doc[i].."\n")
|
file:write("# "..doc[i].."\n")
|
||||||
end
|
end
|
||||||
file:write(i.." = "..tostring(v).."\n")
|
file:write(i.." = "..tostring(v).."\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
file:close()
|
||||||
end
|
end
|
||||||
end
|
|
||||||
--Loads config and returns config values inside table.
|
local modpath = minetest.get_modpath("snow")
|
||||||
local function loadConfig(path)
|
|
||||||
local config = {}
|
minetest.register_on_shutdown(function()
|
||||||
|
saveConfig(modpath.."/config.txt", snow, doc)
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
-- load settings from config.txt
|
||||||
|
|
||||||
|
local config
|
||||||
|
do
|
||||||
|
local path = modpath.."/config.txt"
|
||||||
local file = io.open(path,"r")
|
local file = io.open(path,"r")
|
||||||
if file then
|
if not file then
|
||||||
|
--Create config file.
|
||||||
|
return
|
||||||
|
end
|
||||||
io.close(file)
|
io.close(file)
|
||||||
|
config = {}
|
||||||
for line in io.lines(path) do
|
for line in io.lines(path) do
|
||||||
if line:sub(1,1) ~= "#" then
|
if line:sub(1,1) ~= "#" then
|
||||||
local i, v = line:match("^(%S*) = (%S*)")
|
local i, v = line:match("^(%S*) = (%S*)")
|
||||||
if i and v then
|
if i and v then
|
||||||
if v == "true" then v = true end
|
config[i] = value_from_string(v)
|
||||||
if v == "false" then v = false end
|
|
||||||
if tonumber(v) then v = tonumber(v) end
|
|
||||||
config[i] = v
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return config
|
|
||||||
else
|
|
||||||
--Create config file.
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_shutdown(function()
|
|
||||||
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local config = loadConfig(minetest.get_modpath("snow").."/config.txt")
|
|
||||||
if config then
|
if config then
|
||||||
for i,v in pairs(config) do
|
for i,v in pairs(config) do
|
||||||
if type(snow[i]) == type(v) then
|
if type(snow[i]) == type(v) then
|
||||||
snow[i] = v
|
snow[i] = v
|
||||||
|
else
|
||||||
|
minetest.log("error", "[snow] wrong type of setting "..i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
saveConfig(modpath.."/config.txt", snow, doc)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- load settings from minetest.conf
|
||||||
|
|
||||||
for i,v in pairs(snow) do
|
for i,v in pairs(snow) do
|
||||||
local t = type(v)
|
if allowed_types[type(v)] then
|
||||||
if t == "string"
|
|
||||||
or t == "number"
|
|
||||||
or t == "boolean" then
|
|
||||||
local v = minetest.setting_get("snow_"..i)
|
local v = minetest.setting_get("snow_"..i)
|
||||||
if v ~= nil then
|
if v ~= nil then
|
||||||
if v == "true" then v = true end
|
snow[i] = value_from_string(v)
|
||||||
if v == "false" then v = false end
|
|
||||||
if tonumber(v) then v = tonumber(v) end
|
|
||||||
snow[i] = v
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -99,53 +142,52 @@ end
|
|||||||
|
|
||||||
--MENU
|
--MENU
|
||||||
|
|
||||||
local get_formspec = function()
|
local function form_sort_func(a,b)
|
||||||
local p = -0.5
|
return a[1] < b[1]
|
||||||
local formspec = "label[0,-0.3;Settings:]"
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
local function form_sort_func_bool(a,b)
|
||||||
|
if a[2] == b[2] then
|
||||||
|
return a[1] < b[1]
|
||||||
|
else
|
||||||
|
return b[2]
|
||||||
|
end
|
||||||
|
end--]]
|
||||||
|
|
||||||
|
local function get_formspec()
|
||||||
|
local ids,n1,n2 = {{},{}},1,1
|
||||||
for i,v in pairs(snow) do
|
for i,v in pairs(snow) do
|
||||||
local t = type(v)
|
local t = type(v)
|
||||||
if t == "string"
|
if t == "string"
|
||||||
or t == "number" then
|
or t == "number" then
|
||||||
p = p + 1.5
|
ids[2][n2] = {i,v}
|
||||||
formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]"
|
n2 = n2+1
|
||||||
elseif t == "boolean" then
|
elseif t == "boolean" then
|
||||||
|
ids[1][n1] = {i,v}
|
||||||
|
n1 = n1+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.sort(ids[2], form_sort_func)
|
||||||
|
table.sort(ids[1], form_sort_func)
|
||||||
|
|
||||||
|
local p = -0.5
|
||||||
|
local formspec = "label[0,-0.3;Settings:]"
|
||||||
|
for n = 1,n1-1 do
|
||||||
|
local i,v = unpack(ids[1][n])
|
||||||
p = p + 0.5
|
p = p + 0.5
|
||||||
formspec = formspec.."checkbox[0,"..p..";snow:"..i..";"..i..";"..tostring(v).."]"
|
formspec = formspec.."checkbox[0,"..p..";snow:"..i..";"..i..";"..tostring(v).."]"
|
||||||
end
|
end
|
||||||
|
for n = 1,n2-1 do
|
||||||
|
local i,v = unpack(ids[2][n])
|
||||||
|
p = p + 1.5
|
||||||
|
formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]"
|
||||||
end
|
end
|
||||||
p = p + 1
|
p = p + 1
|
||||||
formspec = "size[4,"..p..";]\n"..formspec
|
formspec = "size[4,"..p..";]\n"..formspec
|
||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
||||||
if formname ~= "snow:menu" then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
for i,v in pairs(snow) do
|
|
||||||
local t = type(v)
|
|
||||||
if t == "string" or t == "number" or t == "boolean" then
|
|
||||||
local field = fields["snow:"..i]
|
|
||||||
if field then
|
|
||||||
if t == "string" then
|
|
||||||
snow[i] = field
|
|
||||||
end
|
|
||||||
if t == "number" then
|
|
||||||
snow[i] = tonumber(field)
|
|
||||||
end
|
|
||||||
if t == "boolean" then
|
|
||||||
if field == "true" then
|
|
||||||
snow[i] = true
|
|
||||||
elseif field == "false" then
|
|
||||||
snow[i] = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_chatcommand("snow", {
|
minetest.register_chatcommand("snow", {
|
||||||
description = "Show a menu for various actions",
|
description = "Show a menu for various actions",
|
||||||
privs = {server=true},
|
privs = {server=true},
|
||||||
@ -154,3 +196,33 @@ minetest.register_chatcommand("snow", {
|
|||||||
minetest.show_formspec(name, "snow:menu", get_formspec())
|
minetest.show_formspec(name, "snow:menu", get_formspec())
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
|
if formname ~= "snow:menu" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for i,v in pairs(snow) do
|
||||||
|
local t = type(v)
|
||||||
|
if allowed_types[t] then
|
||||||
|
local field = fields["snow:"..i]
|
||||||
|
if field then
|
||||||
|
if t == "number" then
|
||||||
|
field = tonumber(field)
|
||||||
|
elseif t == "boolean" then
|
||||||
|
if field == "true" then
|
||||||
|
field = true
|
||||||
|
elseif field == "false" then
|
||||||
|
field = false
|
||||||
|
else
|
||||||
|
field = nil
|
||||||
|
end
|
||||||
|
elseif t ~= "string" then
|
||||||
|
field = nil
|
||||||
|
end
|
||||||
|
if field ~= nil then
|
||||||
|
change_setting(i, field)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user