mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-26 09:40:28 +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
|
||||
--dofile(minetest.get_modpath("snow").."/util.lua")
|
||||
--dofile(minetest.get_modpath("snow").."/mapgen.lua")
|
||||
--dofile(minetest.get_modpath("snow").."/sled.lua")
|
||||
--dofile(modpath.."/util.lua")
|
||||
--dofile(modpath.."/mapgen.lua")
|
||||
--dofile(modpath.."/sled.lua")
|
||||
-- "falling_snow.lua" disabled since weather functions minetest.get_heat(pos) and minetest.get_humidity(pos)
|
||||
-- have been removed from Minetest.
|
||||
-- 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
|
||||
-- dofile(minetest.get_modpath("snow").."/src/abms.lua")
|
||||
dofile(minetest.get_modpath("snow").."/src/aliases.lua")
|
||||
dofile(minetest.get_modpath("snow").."/src/crafting.lua")
|
||||
dofile(minetest.get_modpath("snow").."/src/snowball.lua")
|
||||
local modpath = minetest.get_modpath("snow")
|
||||
dofile(modpath.."/src/abms.lua")
|
||||
dofile(modpath.."/src/aliases.lua")
|
||||
dofile(modpath.."/src/crafting.lua")
|
||||
|
||||
|
||||
-- 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
|
||||
-- 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(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.
|
||||
-- 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(minetest.get_modpath("snow").."/aliases.lua")
|
||||
dofile(minetest.get_modpath("snow").."/src/basic_stairs_slabs.lua")
|
||||
-- dofile(minetest.get_modpath("snow").."/src/mapgen.lua")
|
||||
dofile(minetest.get_modpath("snow").."/src/sled.lua")
|
||||
-- dofile(minetest.get_modpath("snow").."/src/falling_snow.lua")
|
||||
dofile(modpath.."/src/nodes.lua")
|
||||
dofile(modpath.."/src/basic_stairs_slabs.lua")
|
||||
-- dofile(modpath.."/src/mapgen.lua")
|
||||
dofile(modpath.."/src/sled.lua")
|
||||
-- dofile(modpath.."/src/falling_snow.lua")
|
||||
|
||||
|
||||
|
||||
-- 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
|
||||
|
||||
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)
|
||||
@ -90,12 +92,11 @@ function snow.place(pos)
|
||||
return
|
||||
end
|
||||
|
||||
local bnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
||||
if node.name == "default:snow" then
|
||||
local level = minetest.get_node_level(pos)
|
||||
if level < 63 then
|
||||
if minetest.get_item_group(bnode.name, "leafdecay") == 0
|
||||
and not snow.is_uneven(pos) then
|
||||
if minetest.get_item_group(minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name, "leafdecay") == 0
|
||||
and not is_uneven(pos) then
|
||||
minetest.sound_play("default_snow_footstep", {pos=pos})
|
||||
minetest.add_node_level(pos, 7)
|
||||
end
|
||||
@ -111,7 +112,7 @@ function snow.place(pos)
|
||||
end
|
||||
end
|
||||
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 drawtype = data.drawtype
|
||||
if drawtype == "normal"
|
||||
@ -137,13 +138,11 @@ 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
|
||||
local found
|
||||
local foundx
|
||||
local foundy
|
||||
local foundz
|
||||
for z = -1,1 do
|
||||
for x = -1,1 do
|
||||
@ -164,7 +163,6 @@ local function is_uneven(pos)
|
||||
if not (x == 0 and z == 0)
|
||||
and node.name == "default:snow"
|
||||
and minetest.get_node_level(p) < num then
|
||||
found = true
|
||||
foundx = x
|
||||
foundz = z
|
||||
elseif node.name == "air"
|
||||
@ -176,17 +174,27 @@ local function is_uneven(pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
if found then
|
||||
if foundx then
|
||||
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)
|
||||
end
|
||||
return true
|
||||
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)
|
||||
|
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,27 +108,29 @@ minetest.register_abm({
|
||||
interval = 20,
|
||||
chance = 4,
|
||||
action = function(pos, node)
|
||||
if node.param2 > 0 then
|
||||
for l = 0,1 do
|
||||
for i = -1,1,2 do
|
||||
for _,p in pairs({
|
||||
{x=pos.x+i, z=pos.z-l*i},
|
||||
{x=pos.x+l*i, z=pos.z+i}
|
||||
}) do
|
||||
if math.random(2) == 2 then
|
||||
p.y = pos.y
|
||||
if minetest.get_node(p).name == "default:water_source" then
|
||||
minetest.add_node(p,{name="default:ice", param2 = math.random(0,node.param2-1)})
|
||||
end
|
||||
if node.param2 == 0 then
|
||||
return
|
||||
end
|
||||
for l = 0,1 do
|
||||
for i = -1,1,2 do
|
||||
for _,p in pairs({
|
||||
{x=pos.x+i, z=pos.z-l*i},
|
||||
{x=pos.x+l*i, z=pos.z+i}
|
||||
}) do
|
||||
if math.random(2) == 2 then
|
||||
p.y = pos.y
|
||||
if minetest.get_node(p).name == "default:water_source" then
|
||||
minetest.add_node(p,{name="default:ice", param2 = math.random(0,node.param2-1)})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if math.random(8) == 8 then
|
||||
minetest.add_node(pos, {name="default:water_source"})
|
||||
else
|
||||
minetest.add_node(pos, {name="default:ice", param2 = 0})
|
||||
end
|
||||
end
|
||||
if math.random(8) == 8 then
|
||||
minetest.add_node(pos, {name="default:water_source"})
|
||||
else
|
||||
node.param2 = 0
|
||||
minetest.add_node(pos, node)
|
||||
end
|
||||
end,
|
||||
})
|
||||
@ -141,6 +143,7 @@ minetest.register_abm({
|
||||
neighbors = {"snow:moss"},
|
||||
interval = 20,
|
||||
chance = 6,
|
||||
catch_up = false,
|
||||
action = function(pos, node)
|
||||
node.name = "default:mossycobble"
|
||||
minetest.add_node(pos, node)
|
||||
@ -206,3 +209,17 @@ minetest.register_abm({
|
||||
--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("snowycobble", "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.
|
||||
-- Stair
|
||||
|
@ -31,6 +31,7 @@ near torches and lava.
|
||||
* Add code to prevent snowfall from depositing snow on
|
||||
'walkable = false' defined nodes.
|
||||
|
||||
both are already fixed -- Hybrid Dog
|
||||
--]]
|
||||
|
||||
|
||||
@ -42,8 +43,9 @@ near torches and lava.
|
||||
|
||||
local weather_legacy
|
||||
|
||||
local worldpath = minetest.get_worldpath()
|
||||
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
|
||||
local readweather = file:read()
|
||||
file:close()
|
||||
@ -52,26 +54,30 @@ end
|
||||
|
||||
--Weather for legacy versions of minetest.
|
||||
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:close()
|
||||
end
|
||||
|
||||
weather_legacy = read_weather_legacy() or ""
|
||||
weather_legacy = read_weather_legacy() or ""
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if weather_legacy == "snow" then
|
||||
if math.random(1, 10000) == 1 then
|
||||
weather_legacy = "none"
|
||||
save_weather_legacy()
|
||||
end
|
||||
else
|
||||
if math.random(1, 50000) == 2 then
|
||||
weather_legacy = "snow"
|
||||
save_weather_legacy()
|
||||
end
|
||||
local function leg_step()
|
||||
if weather_legacy == "snow" then
|
||||
if math.random(1000) == 1 then
|
||||
weather_legacy = "none"
|
||||
save_weather_legacy()
|
||||
end
|
||||
end)
|
||||
elseif math.random(5000) == 2 then
|
||||
weather_legacy = "snow"
|
||||
save_weather_legacy()
|
||||
end
|
||||
minetest.after(2, leg_step)
|
||||
end
|
||||
minetest.after(4, leg_step)
|
||||
|
||||
local function infolog(msg)
|
||||
minetest.log("info", "[snow] falling_snow: "..msg)
|
||||
end
|
||||
|
||||
-- copied from meru mod
|
||||
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 SCALE3 = 250 -- 250
|
||||
|
||||
--Get snow at position.
|
||||
local function get_snow(pos)
|
||||
--Legacy support.
|
||||
if weather_legacy == "snow" then
|
||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
||||
if perlin1:get2d({x=pos.x, y=pos.z}) <= 0.53 then
|
||||
return false
|
||||
end
|
||||
|
||||
-- disable falling snow in desert
|
||||
local desert_perlin = minetest.get_perlin(SEEDDIFF3, OCTAVES3, PERSISTENCE3, SCALE3)
|
||||
local noise3 = desert_perlin:get2d({x=pos.x+150,y=pos.z+50}) -- Offsets must match minetest mapgen desert perlin.
|
||||
if noise3 > 0.35 then -- Smooth transition 0.35 to 0.45.
|
||||
return false
|
||||
end
|
||||
return true
|
||||
-- cache perlin noise tests
|
||||
local perlin_scale, rarity
|
||||
local cold_perl_values = {}
|
||||
setmetatable(cold_perl_values, {__mode = "kv"})
|
||||
local function cold_perlin_test(x, y)
|
||||
if not cold_perl_values[y] then
|
||||
cold_perl_values[y] = {}
|
||||
setmetatable(cold_perl_values[y], {__mode = "kv"})
|
||||
end
|
||||
return false
|
||||
|
||||
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
|
||||
|
||||
local addvectors = vector and vector.add
|
||||
-- disable falling snow in desert
|
||||
local desert_perl_values = {}
|
||||
setmetatable(desert_perl_values, {__mode = "kv"})
|
||||
local function is_desert(x, y)
|
||||
if not desert_perl_values[y] then
|
||||
desert_perl_values[y] = {}
|
||||
setmetatable(desert_perl_values[y], {__mode = "kv"})
|
||||
end
|
||||
|
||||
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.
|
||||
-- TODO: make a fload random position
|
||||
local function randpos(minp, maxp)
|
||||
local x,z
|
||||
if minp.x > maxp.x then
|
||||
@ -146,7 +186,7 @@ local function snow_fall(pos, player, animate)
|
||||
return
|
||||
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
|
||||
if n ~= "air" and n ~= "ignore" then
|
||||
ground_y = y
|
||||
@ -159,23 +199,25 @@ local function snow_fall(pos, player, animate)
|
||||
|
||||
pos = {x=pos.x, y=ground_y, z=pos.z}
|
||||
|
||||
if get_snow(pos) then
|
||||
if animate then
|
||||
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
||||
minetest.add_particlespawner(get_snow_particledef({
|
||||
minpos = addvectors(spos, {x=-9, y=3, z=-9}),
|
||||
maxpos = addvectors(spos, {x= 9, y=5, z= 9}),
|
||||
vel = {x=0, y=-1, z=-1},
|
||||
acc = {x=0, y=0, z=0},
|
||||
playername = player:get_player_name()
|
||||
}))
|
||||
end
|
||||
snow.place(pos, true)
|
||||
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ
|
||||
if not get_snow(pos) then
|
||||
return
|
||||
end
|
||||
if animate then
|
||||
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
||||
minetest.add_particlespawner(get_snow_particledef({
|
||||
minpos = addvectors(spos, {x=-9, y=3, z=-9}),
|
||||
maxpos = addvectors(spos, {x= 9, y=5, z= 9}),
|
||||
vel = {x=0, y=-1, z=-1},
|
||||
acc = {x=0, y=0, z=0},
|
||||
playername = player:get_player_name()
|
||||
}))
|
||||
end
|
||||
snow.place(pos, true)
|
||||
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"}) -- LazyJ
|
||||
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()
|
||||
@ -184,7 +226,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({
|
||||
@ -227,8 +269,29 @@ 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
|
||||
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)
|
||||
|
@ -10,29 +10,70 @@ saplings grow into trees. --]]
|
||||
-- ~ 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.
|
||||
minetest.register_on_mapgen_init(function(MapgenParams)
|
||||
local mgname = MapgenParams.mgname
|
||||
if not mgname then
|
||||
io.write("[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!\n")
|
||||
end
|
||||
if mgname == "v7" then
|
||||
--Load mapgen_v7 compatibility.
|
||||
dofile(minetest.get_modpath("snow").."/src/mapgen_v7.lua")
|
||||
else
|
||||
--Load mapgen_v6 compatibility.
|
||||
dofile(minetest.get_modpath("snow").."/src/mapgen_v6.lua")
|
||||
end
|
||||
end)
|
||||
local mgname = minetest.get_mapgen_setting"mg_name"
|
||||
if not mgname then
|
||||
minetest.log("error", "[MOD] Snow Biomes: WARNING! mapgen could not be identifyed!")
|
||||
end
|
||||
local path = minetest.get_modpath"snow"
|
||||
if mgname == "v7" then
|
||||
--Load mapgen_v7 compatibility.
|
||||
dofile(path.."/src/mapgen_v7.lua")
|
||||
else
|
||||
--Load mapgen_v6 compatibility.
|
||||
dofile(path.."/src/mapgen_v6.lua")
|
||||
end
|
||||
|
||||
-- To complete the commenting-out add the *closing* comment under this line.
|
||||
|
||||
|
||||
|
||||
|
||||
local pine_tree = {
|
||||
axiom="TABff",
|
||||
rules_a="[&T+f+ff+ff+ff+f]GA",
|
||||
@ -66,7 +107,6 @@ local xmas_tree = {
|
||||
--Makes pine tree
|
||||
function snow.make_pine(pos,snow,xmas)
|
||||
local minetest = minetest
|
||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
||||
local try_node = function(pos, node)
|
||||
local n = minetest.get_node(pos).name
|
||||
if n == "air"
|
||||
@ -95,7 +135,7 @@ function snow.make_pine(pos,snow,xmas)
|
||||
if xmas then
|
||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="snow:star_lit"}) -- Added lit star. ~ LazyJ
|
||||
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"})
|
||||
end
|
||||
end
|
||||
@ -109,7 +149,7 @@ function snow.voxelmanip_pine(pos,a,data)
|
||||
local c_pinetree = minetest.get_content_id("default:pinetree")
|
||||
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
|
||||
local z = pos.z + z
|
||||
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
|
||||
if x ~= 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)
|
||||
data[abovenode] = c_snow
|
||||
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,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
|
||||
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
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
@ -153,8 +193,7 @@ function snow.voxelmanip_pine(pos,a,data)
|
||||
end
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
]]
|
||||
|
@ -1,5 +1,6 @@
|
||||
-- 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 = {
|
||||
offset = 0,
|
||||
scale = 1,
|
||||
@ -9,17 +10,21 @@ local np_default = {
|
||||
persist = 0.5
|
||||
}
|
||||
|
||||
|
||||
-- 2D noise for coldness
|
||||
|
||||
local mg = snow.mapgen
|
||||
local scale = mg.perlin_scale
|
||||
local np_cold = {
|
||||
offset = 0,
|
||||
scale = -1,
|
||||
spread = {x=256, y=256, z=256},
|
||||
scale = 1,
|
||||
spread = {x=scale, y=scale, z=scale},
|
||||
seed = 112,
|
||||
octaves = 3,
|
||||
persist = 0.5
|
||||
}
|
||||
|
||||
|
||||
-- 2D noise for icetype
|
||||
|
||||
local np_ice = {
|
||||
@ -31,29 +36,39 @@ local np_ice = {
|
||||
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 n = x/(16000)
|
||||
local n = math.pi * x / 16000
|
||||
local y = 0
|
||||
for k=1,1000 do
|
||||
y = y + 1000*math.sin(math.pi * k^a * n)/(math.pi * k^a)
|
||||
for k = 1,1000 do
|
||||
y = y + math.sin(k^a * n)/(k^a)
|
||||
end
|
||||
return y
|
||||
return 1000*y/math.pi
|
||||
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 = {}
|
||||
setmetatable(plantlike_ids, {__mode = "kv"})
|
||||
local function is_plantlike(id)
|
||||
if plantlike_ids[id] ~= nil then
|
||||
return plantlike_ids[id]
|
||||
@ -74,6 +89,7 @@ local function is_plantlike(id)
|
||||
end
|
||||
|
||||
local snowable_ids = {}
|
||||
setmetatable(snowable_ids, {__mode = "kv"})
|
||||
local function is_snowable(id)
|
||||
if snowable_ids[id] ~= nil then
|
||||
return snowable_ids[id]
|
||||
@ -95,7 +111,8 @@ local function is_snowable(id)
|
||||
return true
|
||||
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"),
|
||||
@ -120,8 +137,41 @@ 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
|
||||
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)
|
||||
local t1 = os.clock()
|
||||
|
||||
@ -130,23 +180,23 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
local x1 = maxp.x
|
||||
local z1 = maxp.z
|
||||
|
||||
local smooth = snow.smooth_biomes
|
||||
|
||||
if not c then
|
||||
define_contents()
|
||||
end
|
||||
|
||||
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
|
||||
local vm, emin, emax = minetest.get_mapgen_object"voxelmanip"
|
||||
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
||||
local data = vm:get_data()
|
||||
local param2s = vm:get_param2_data()
|
||||
|
||||
local heightmap = minetest.get_mapgen_object"heightmap"
|
||||
|
||||
local snow_tab,num = {},1
|
||||
local pines_tab,pnum = {},1
|
||||
|
||||
local sidelen = x1 - x0 + 1
|
||||
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
|
||||
|
||||
-- Choose biomes
|
||||
@ -162,24 +212,30 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
-- Reseed random
|
||||
pr = PseudoRandom(seed+68)
|
||||
|
||||
local nodes_added
|
||||
|
||||
-- Loop through columns in chunk
|
||||
local smooth = smooth and not snowy
|
||||
local write_to_map = false
|
||||
local ni = 1
|
||||
for z = z0, z1 do
|
||||
for x = x0, x1 do
|
||||
local in_biome = false
|
||||
local test
|
||||
if nvals_default[ni] < 0.35 then
|
||||
local in_biome = false
|
||||
local test
|
||||
if nvals_default[ni] < 0.35 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
|
||||
test = math.min(nvals_cold[ni], 1)
|
||||
if smooth
|
||||
and not snowy then
|
||||
if (test > 0.73 or (test > 0.43 and pr:next(0,29) > (0.73 - test) * 100 )) then
|
||||
if smooth then
|
||||
if test >= smooth_rarity_max
|
||||
or (
|
||||
test > smooth_rarity_min
|
||||
and pr:next(1, 1000) <= ((test-smooth_rarity_min)/smooth_rarity_dif)*1000
|
||||
) then
|
||||
in_biome = true
|
||||
end
|
||||
elseif test > 0.53 then
|
||||
elseif test > nosmooth_rarity then
|
||||
in_biome = true
|
||||
end
|
||||
end
|
||||
@ -187,25 +243,23 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
if not in_biome then
|
||||
if alpine
|
||||
and test
|
||||
and test > 0.43 then
|
||||
and test > smooth_rarity_min then
|
||||
-- remove trees near alpine
|
||||
local ground_y = nil
|
||||
for y = maxp.y, minp.y, -1 do
|
||||
local nodid = data[area:index(x, y, z)]
|
||||
if nodid ~= c.air
|
||||
and nodid ~= c.ignore then
|
||||
ground_y = y
|
||||
break
|
||||
local ground_y
|
||||
if data[area:index(x, maxp.y, z)] == c.air then
|
||||
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
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if ground_y == maxp.y then -- avoid awful snow layers at chunk boundaries underground
|
||||
ground_y = nil
|
||||
end
|
||||
|
||||
if ground_y then
|
||||
local vi = area:index(x, ground_y, z)
|
||||
if data[vi] == c.leaves
|
||||
or data[vi] == c.jungleleaves then
|
||||
nodes_added = true
|
||||
for y = ground_y, -16, -1 do
|
||||
local vi = area:index(x, y, z)
|
||||
local id = data[vi]
|
||||
@ -224,28 +278,30 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
end
|
||||
else
|
||||
nodes_added = true
|
||||
write_to_map = true
|
||||
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
|
||||
local icetype = nvals_ice[ni]
|
||||
local icetype = nvals_ice[ni]
|
||||
local cool = icetype > 0 -- only spawns ice on edge of water
|
||||
local icebergs = icetype > -0.2 and icetype <= 0
|
||||
local icehole = icetype > -0.4 and icetype <= -0.2 -- icesheet with holes
|
||||
local icesheet = icetype > -0.6 and icetype <= -0.4
|
||||
local icecave = icetype <= -0.6
|
||||
|
||||
|
||||
local ground_y
|
||||
for y = maxp.y, minp.y, -1 do
|
||||
local nodid = data[area:index(x, y, z)]
|
||||
if nodid ~= c.air and nodid ~= c.ignore then
|
||||
ground_y = y
|
||||
break
|
||||
-- avoid generating underground
|
||||
if data[area:index(x, maxp.y, z)] == c.air 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
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if ground_y == maxp.y then -- avoid awful snow layers at chunk boundaries underground
|
||||
ground_y = nil
|
||||
end
|
||||
|
||||
if ground_y then
|
||||
local node = area:index(x, ground_y, z)
|
||||
@ -253,7 +309,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
|
||||
if c_ground == c.dirt_with_grass then
|
||||
if alpine
|
||||
and test > 0.53 then
|
||||
and test > nosmooth_rarity then
|
||||
snow_tab[num] = {ground_y, z, x, test}
|
||||
num = num+1
|
||||
-- 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
|
||||
else
|
||||
if snowy
|
||||
or test > 0.8 then
|
||||
or test > smooth_rarity_max then
|
||||
-- more, deeper snow
|
||||
data[node] = c.snow_block
|
||||
else
|
||||
@ -363,7 +419,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
break
|
||||
end
|
||||
end
|
||||
--[[ elseif alpine then
|
||||
elseif alpine then
|
||||
-- make stone pillars out of trees and other stuff
|
||||
for y = ground_y, math.max(-6, minp.y-6), -1 do
|
||||
local stone = area:index(x, y, z)
|
||||
@ -374,7 +430,7 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
-- put snow onto it
|
||||
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
|
||||
if is_snowable(c_ground) then
|
||||
-- put snow onto it
|
||||
@ -414,19 +470,26 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
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
|
||||
for _,i in pairs(snow_tab) do
|
||||
-- set snow
|
||||
data[area:index(i[3], i[1]+1, i[2])] = c.snow
|
||||
end
|
||||
local wsz, wsx
|
||||
for _,i in pairs(snow_tab) do
|
||||
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
|
||||
local maxh = math.floor(test*10)%10+1
|
||||
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
|
||||
-- search for nearby snow
|
||||
y = y+1
|
||||
@ -477,10 +540,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
|
||||
|
@ -6,8 +6,8 @@ minetest.register_biome({
|
||||
node_filler = "default:dirt",
|
||||
depth_filler = 2,
|
||||
|
||||
y_min = snow.min_height,
|
||||
y_max = snow.min_height+60,
|
||||
height_min = snow.min_height,
|
||||
height_max = snow.min_height+60,
|
||||
heat_point = 10.0,
|
||||
humidity_point = 40.0,
|
||||
})
|
||||
@ -20,8 +20,8 @@ minetest.register_biome({
|
||||
node_filler = "default:dirt",
|
||||
depth_filler = 2,
|
||||
|
||||
y_min = snow.min_height,
|
||||
y_max = snow.min_height+60,
|
||||
height_min = snow.min_height,
|
||||
height_max = snow.min_height+60,
|
||||
heat_point = 10.0,
|
||||
humidity_point = 55.0,
|
||||
})
|
||||
@ -34,8 +34,8 @@ minetest.register_biome({
|
||||
node_filler = "default:dirt",
|
||||
depth_filler = 2,
|
||||
|
||||
y_min = snow.min_height,
|
||||
y_max = snow.min_height+60,
|
||||
height_min = snow.min_height,
|
||||
height_max = snow.min_height+60,
|
||||
heat_point = 10.0,
|
||||
humidity_point = 70.0,
|
||||
})
|
||||
@ -47,8 +47,8 @@ minetest.register_biome({
|
||||
depth_top = 1,
|
||||
node_filler = "default:stone",
|
||||
|
||||
y_min = snow.min_height+60,
|
||||
y_max = 31000,
|
||||
height_min = snow.min_height+60,
|
||||
height_max = 31000,
|
||||
heat_point = 10.0,
|
||||
humidity_point = 40.0,
|
||||
})
|
||||
@ -61,8 +61,8 @@ minetest.register_biome({
|
||||
node_filler = "default:stone",
|
||||
depth_filler = 0,
|
||||
|
||||
y_min = -31000,
|
||||
y_max = 2,
|
||||
height_min = -31000,
|
||||
height_max = 2,
|
||||
heat_point = 10.0,
|
||||
humidity_point = 40.0,
|
||||
})
|
||||
|
@ -38,17 +38,27 @@ end
|
||||
]]
|
||||
minetest.register_node("snow:needles", table.copy(nodedef))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--Christmas easter egg
|
||||
minetest.register_on_mapgen_init( function()
|
||||
if rawget(_G, "skins") then
|
||||
skins.add("character_snow_man")
|
||||
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)
|
||||
|
||||
|
||||
|
||||
-- Christmas egg
|
||||
if minetest.global_exists"skins" then
|
||||
skins.add"character_snow_man"
|
||||
end
|
||||
)
|
||||
|
||||
|
||||
-- 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.inventory_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.furnace_burntime = 3
|
||||
minetest.register_node("snow:shrub_covered", nodedef)
|
||||
@ -198,6 +209,7 @@ if rawget(_G, "flowers") then
|
||||
tiles = { "snow_" .. name .. ".png" },
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
paramtype2 = "degrotate",
|
||||
walkable = false,
|
||||
drop = "",
|
||||
groups = {snappy=3, attached_node = 1},
|
||||
@ -232,6 +244,7 @@ nodedef = {
|
||||
drawtype = "plantlike",
|
||||
tiles = {"snow_apple.png"},
|
||||
paramtype = "light",
|
||||
paramtype2 = "degrotate",
|
||||
walkable = false,
|
||||
sunlight_propagates = apple.sunlight_propagates,
|
||||
selection_box = apple.selection_box,
|
||||
|
@ -113,9 +113,8 @@ local function leave_sled(self, player)
|
||||
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(self, 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(self, 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})
|
||||
|
@ -8,13 +8,30 @@
|
||||
|
||||
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 grav = tonumber(minetest.setting_get("movement_gravity")) or 9.81
|
||||
return grav*snow.snowball_gravity
|
||||
return grav*snowball_gravity
|
||||
end
|
||||
|
||||
local someone_throwing
|
||||
local timer = 0
|
||||
local someone_throwing, just_acitvated
|
||||
|
||||
--Shoot snowball
|
||||
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
|
||||
local pos = vector.add(player:getpos(), addp)
|
||||
local obj = minetest.add_entity(pos, "snow:snowball_entity")
|
||||
obj:get_luaentity().thrower = player:get_player_name()
|
||||
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:get_luaentity().thrower = player:get_player_name()
|
||||
if creative_mode then
|
||||
if not someone_throwing then
|
||||
someone_throwing = true
|
||||
timer = -0.5
|
||||
just_acitvated = true
|
||||
end
|
||||
return
|
||||
end
|
||||
@ -40,13 +57,7 @@ local function snow_shoot_snowball(item, player)
|
||||
end
|
||||
|
||||
if creative_mode then
|
||||
local function update_step(dtime)
|
||||
timer = timer+dtime
|
||||
if timer < 0.006 then
|
||||
return
|
||||
end
|
||||
timer = 0
|
||||
|
||||
local function update_step()
|
||||
local active
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
if player:get_player_control().LMB then
|
||||
@ -66,13 +77,21 @@ if creative_mode then
|
||||
end
|
||||
end
|
||||
|
||||
-- do automatic throwing using a globalstep
|
||||
minetest.register_globalstep(function(dtime)
|
||||
-- do automatic throwing using minetest.after
|
||||
local function do_step()
|
||||
local timer
|
||||
-- only if one holds left click
|
||||
if someone_throwing then
|
||||
update_step(dtime)
|
||||
if someone_throwing
|
||||
and not just_acitvated then
|
||||
update_step()
|
||||
timer = 0.006
|
||||
else
|
||||
timer = 0.5
|
||||
just_acitvated = false
|
||||
end
|
||||
end)
|
||||
minetest.after(timer, do_step)
|
||||
end
|
||||
minetest.after(3, do_step)
|
||||
end
|
||||
|
||||
--The snowball Entity
|
||||
@ -80,7 +99,6 @@ local snow_snowball_ENTITY = {
|
||||
physical = false,
|
||||
timer = 0,
|
||||
collisionbox = {-5/16,-5/16,-5/16, 5/16,5/16,5/16},
|
||||
thrower = "",
|
||||
}
|
||||
|
||||
function snow_snowball_ENTITY.on_activate(self)
|
||||
@ -118,25 +136,6 @@ function snow_snowball_ENTITY.on_step(self, dtime)
|
||||
return
|
||||
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
|
||||
local fell = self.object:getvelocity().y == 0
|
||||
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})
|
||||
pos = self.lastpos
|
||||
self.object:setpos(pos)
|
||||
local gain = vector.length(self.object:getvelocity())/30
|
||||
minetest.sound_play("default_snow_footstep", {pos=pos, gain=gain})
|
||||
minetest.sound_play("default_snow_footstep", {pos=pos, gain=vector.length(self.object:getvelocity())/30})
|
||||
self.object:set_properties({physical = true})
|
||||
self.physical = true
|
||||
return
|
||||
end
|
||||
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
|
||||
|
||||
|
||||
|
@ -10,6 +10,8 @@ snow = {
|
||||
christmas_content = true,
|
||||
smooth_snow = true,
|
||||
min_height = 3,
|
||||
mapgen_rarity = 18,
|
||||
mapgen_size = 210,
|
||||
}
|
||||
|
||||
--Config documentation.
|
||||
@ -24,74 +26,115 @@ local doc = {
|
||||
smooth_snow = "Disable this to stop snow from being smoothed.",
|
||||
christmas_content = "Disable this to remove christmas saplings from being found.",
|
||||
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.
|
||||
local function saveConfig(path, config, doc)
|
||||
local file = io.open(path,"w")
|
||||
if file then
|
||||
for i,v in pairs(config) do
|
||||
local t = type(v)
|
||||
if t == "string" or t == "number" or t == "boolean" then
|
||||
if doc and doc[i] then
|
||||
file:write("# "..doc[i].."\n")
|
||||
end
|
||||
file:write(i.." = "..tostring(v).."\n")
|
||||
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
|
||||
if allowed_types[type(v)] then
|
||||
if doc and doc[i] then
|
||||
file:write("# "..doc[i].."\n")
|
||||
end
|
||||
file:write(i.." = "..tostring(v).."\n")
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
end
|
||||
--Loads config and returns config values inside table.
|
||||
local function loadConfig(path)
|
||||
local config = {}
|
||||
local file = io.open(path,"r")
|
||||
if file then
|
||||
io.close(file)
|
||||
for line in io.lines(path) do
|
||||
if line:sub(1,1) ~= "#" then
|
||||
local i, v = line:match("^(%S*) = (%S*)")
|
||||
if i and v then
|
||||
if v == "true" then v = true end
|
||||
if v == "false" then v = false end
|
||||
if tonumber(v) then v = tonumber(v) end
|
||||
config[i] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
return config
|
||||
else
|
||||
--Create config file.
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
local modpath = minetest.get_modpath("snow")
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
||||
saveConfig(modpath.."/config.txt", snow, doc)
|
||||
end)
|
||||
|
||||
local config = loadConfig(minetest.get_modpath("snow").."/config.txt")
|
||||
|
||||
-- load settings from config.txt
|
||||
|
||||
local config
|
||||
do
|
||||
local path = modpath.."/config.txt"
|
||||
local file = io.open(path,"r")
|
||||
if not file then
|
||||
--Create config file.
|
||||
return
|
||||
end
|
||||
io.close(file)
|
||||
config = {}
|
||||
for line in io.lines(path) do
|
||||
if line:sub(1,1) ~= "#" then
|
||||
local i, v = line:match("^(%S*) = (%S*)")
|
||||
if i and v then
|
||||
config[i] = value_from_string(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if config then
|
||||
for i,v in pairs(config) do
|
||||
if type(snow[i]) == type(v) then
|
||||
snow[i] = v
|
||||
else
|
||||
minetest.log("error", "[snow] wrong type of setting "..i)
|
||||
end
|
||||
end
|
||||
else
|
||||
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
||||
saveConfig(modpath.."/config.txt", snow, doc)
|
||||
end
|
||||
|
||||
|
||||
-- load settings from minetest.conf
|
||||
|
||||
for i,v in pairs(snow) do
|
||||
local t = type(v)
|
||||
if t == "string"
|
||||
or t == "number"
|
||||
or t == "boolean" then
|
||||
if allowed_types[type(v)] then
|
||||
local v = minetest.setting_get("snow_"..i)
|
||||
if v ~= nil then
|
||||
if v == "true" then v = true end
|
||||
if v == "false" then v = false end
|
||||
if tonumber(v) then v = tonumber(v) end
|
||||
snow[i] = v
|
||||
snow[i] = value_from_string(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -99,53 +142,52 @@ end
|
||||
|
||||
--MENU
|
||||
|
||||
local get_formspec = function()
|
||||
local p = -0.5
|
||||
local formspec = "label[0,-0.3;Settings:]"
|
||||
local function form_sort_func(a,b)
|
||||
return a[1] < b[1]
|
||||
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
|
||||
local t = type(v)
|
||||
if t == "string"
|
||||
or t == "number" then
|
||||
p = p + 1.5
|
||||
formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]"
|
||||
ids[2][n2] = {i,v}
|
||||
n2 = n2+1
|
||||
elseif t == "boolean" then
|
||||
p = p + 0.5
|
||||
formspec = formspec.."checkbox[0,"..p..";snow:"..i..";"..i..";"..tostring(v).."]"
|
||||
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
|
||||
formspec = formspec.."checkbox[0,"..p..";snow:"..i..";"..i..";"..tostring(v).."]"
|
||||
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
|
||||
p = p + 1
|
||||
formspec = "size[4,"..p..";]\n"..formspec
|
||||
return formspec
|
||||
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", {
|
||||
description = "Show a menu for various actions",
|
||||
privs = {server=true},
|
||||
@ -154,3 +196,33 @@ minetest.register_chatcommand("snow", {
|
||||
minetest.show_formspec(name, "snow:menu", get_formspec())
|
||||
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