Merge branch 'master' into master

This commit is contained in:
HybridDog 2018-08-18 10:21:31 +02:00 committed by GitHub
commit bdf4933671
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 445 additions and 595 deletions

View File

@ -1,5 +1,10 @@
CHANGELOG:
------------
Version 4.0
Snow mod is now a complimentary mod to the default snow found in minetest.
HybridDog's large changes, fixes and more (see commit log).
Version 3.2

View File

@ -75,7 +75,7 @@ dofile(srcpath.."falling_snow.lua")
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)
function snow.place(pos, disablesound)
local node = minetest.get_node_or_nil(pos)
--Oops, maybe there is no node?
@ -89,17 +89,23 @@ function snow.place(pos)
if level < 63 then
if minetest.get_item_group(minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name, "leafdecay") == 0
and not is_uneven(pos) then
if not disablesound then
minetest.sound_play("default_snow_footstep", {pos=pos})
end
minetest.add_node_level(pos, 7)
end
elseif level == 63 then
local p = minetest.find_node_near(pos, 10, "default:dirt_with_grass")
if p
and minetest.get_node_light(p, 0.5) == 15 then
if not disablesound then
minetest.sound_play("default_grass_footstep", {pos=pos})
end
minetest.place_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="default:snow"})
else
if not disablesound then
minetest.sound_play("default_snow_footstep", {pos=pos})
end
minetest.add_node(pos, {name="default:snowblock"})
end
end
@ -111,7 +117,7 @@ function snow.place(pos)
or drawtype == "allfaces_optional" then
pos.y = pos.y+1
local sound = data.sounds
if sound then
if sound and not disablesound then
sound = sound.footstep
if sound then
minetest.sound_play(sound.name, {pos=pos, gain=sound.gain})

View File

@ -1,3 +1,40 @@
License of media (snowdrift are from paramat)
---------------------------
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
You are free to:
Share — copy and redistribute the material in any medium or format.
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:
Attribution — You must give appropriate credit, provide a link to the license, and
indicate if changes were made. You may do so in any reasonable manner, but not in any way
that suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute
your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.
Notices:
You do not have to comply with the license for elements of the material in the public
domain or where your use is permitted by an applicable exception or limitation.
No warranties are given. The license may not give you all of the permissions necessary
for your intended use. For example, other rights such as publicity, privacy, or moral
rights may limit how you use the material.
For more details:
http://creativecommons.org/licenses/by-sa/3.0/
License of source code and other textures.
----------------------
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

1
mod.conf Normal file
View File

@ -0,0 +1 @@
name = snow

View File

@ -5,21 +5,19 @@
____) | | | | (_) \ V V / | | | | (_) | (_| |
|_____/|_| |_|\___/ \_/\_/ |_| |_|\___/ \__,_|
Version 3.2
Version 4.0
By Splizard and LazyJ.
By Splizard, HybridDog and LazyJ.
Minetest version: 0.4.9
Minetest version: 0.4.16+
Depends: default
License: GPL v2
License: GPL v3
Complimentary Mods:
---------------------
* "Snowdrift" by paramat
* "More Blocks" by Calinou (2014_05_11 or newer)
* "Skins" by Zeg9
Install:
Forum post: http://minetest.net/forum/viewtopic.php?id=2290
@ -43,26 +41,8 @@ Place this folder in your minetest mods folder.
world's "world.mt" file:
load_mod_snow = true
NOTICE
While this mod is installed you may experience slower map loading while a snow biome is generated.
USAGE:
-------
If you walk around a bit you will find snow biomes scattered around the world.
There are nine biome types:
* Normal
* Icebergs
* Icesheet
* Broken icesheet
* Icecave
* Coast
* Alpine
* Snowy
* Plain
Snow can be picked up and thrown as snowballs or stacked into snow blocks.
Snow and ice melts when near warm blocks such as torches or igniters such as lava.
Snow blocks freeze water source blocks around them.
@ -86,24 +66,21 @@ Icy Snow:
Snow Ice
Ice Snow
MAPGEN_V7:
------------
If you are using minetest 0.4.8 or the latest dev version of minetest you can choose to generate a v7 map.
This option can be found when creating a new map from the menu.
Snow Biomes has support for this though you might need a couple other biomes too otherwise you will only spawn snow.
There are a couple of bugs and limitations with this such as no ice being generated at the moment.
Config file:
------------
After starting a game in minetest with snow mod, a config file will be placed in this folder that contains the various options for snow mod.
As admin you can use the /snow command in-game to make various changes.
You can change various settings from the advanced settings in Minetest.
* Go to the settings tab.
* Click on Advanced Settings.
* Click on Mods.
* Click on snow.
* Change stuff!
UNINSTALL:
------------
Simply delete the folder snow from the mods folder.
TODO:
— use the settingtypes.txt
— test if the fixed ground_y search works correctly at chunkcorners at ground level

38
settingtypes.txt Normal file
View File

@ -0,0 +1,38 @@
#The gravity of thrown snowballs.
snow_snowball_gravity (Snowball Gravity) float 0.91
#How fast players throw snowballs.
snow_snowball_velocity (Snowball Velocity) float 19
#Enable/Disable sleds.
snow_sleds (Enable Sleds) bool true
#Enables falling snow.
snow_enable_snowfall (Enable Snowfall) bool true
#Reduces the amount of resources and fps used by snowfall.
snow_lighter_snowfall (Use Light Snowfall) bool false
#Enables debug output. Currently it only prints mgv6 info.
snow_debug (Debug Mode) bool false
#Disable this to remove christmas saplings from being found.
snow_christmas_content (Enable Christmas Content) bool true
#Enables debug output. Currently it only prints mgv6 info.
snow_smooth_biomes (Smooth Biome Transitions) bool true
#The minumum height a snow biome will generate (mgv7)
snow_min_height (Minumum Height for Snow Biomes) int 3
#Disable this to stop snow from being smoothed.
snow_smooth_snow (Multiple Snow Levels) bool true
#mapgen rarity in %.
snow_mapgen_rarity (Snow Biome Rarity %) float 18
#size of the generated… (has an effect to the rarity, too)
snow_mapgen_size (Snow Biome Size) float 210
#Minetest finally has capable snow biomes by default, lets not mess it up with the old snowgen.
snow_disable_mapgen (Disable mod-generated biomes) bool true

View File

@ -1,202 +1,6 @@
--[[
--=================
--======================================
LazyJ's Fork of Splizard's "Snow" Mod
by LazyJ
version: Umpteen and 7/5ths something or another.
2014_04_12
--======================================
--=================
-- Parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
THE LIST OF CHANGES I'VE MADE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Falling snow would destroy nodes it deposited snow on. I figured out that if
I switched the 'snow.place' with 'minetest.place_node' and increased the
y position by 2, then the nodes were nolonger destroyed and the snow
would start to pile up.
~~~~~~
TODO
~~~~~~
* Add code to prevent snowfall from depositing snow on or
near torches and lava.
* Add code to prevent snowfall from depositing snow on
'walkable = false' defined nodes.
both are already fixed -- Hybrid Dog
--]]
--=============================================================
-- CODE STUFF
--=============================================================
local weather_legacy
local worldpath = minetest.get_worldpath()
local read_weather_legacy = function ()
local file = io.open(worldpath.."/weather_v6", "r")
if not file then return end
local readweather = file:read()
file:close()
return readweather
end
--Weather for legacy versions of minetest.
local save_weather_legacy = function ()
local file = io.open(worldpath.."/weather_v6", "w+")
file:write(weather_legacy)
file:close()
end
weather_legacy = read_weather_legacy() or ""
local function leg_step()
if weather_legacy == "snow" then
if math.random(1000) == 1 then
weather_legacy = "none"
save_weather_legacy()
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.
local OCTAVES3 = 3 -- 3
local PERSISTENCE3 = 0.5 -- 0.5
local SCALE3 = 250 -- 250
-- 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
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
local em = ""
if type(x) ~= "number" then
em = em.. "x no number but "..type(x).." "
elseif x%1 ~= 0 then
em = em.. "x no integer but "..x.." "
end
if type(y) ~= "number" then
em = em.. "y no number but "..type(y).." "
elseif y%1 ~= 0 then
em = em.. "y no integer but "..y.." "
end
if em ~= "" then
error(em)
end
if cold_perl_values[y] then
cold_perl_values[y][x] = v
end
return v
end
-- 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
x = math.random(maxp.x,minp.x)
else
x = math.random(minp.x,maxp.x)
end
if minp.z > maxp.z then
z = math.random(maxp.z,minp.z)
else
z = math.random(minp.z,maxp.z)
end
return {x=x,y=minp.y,z=z}
end
local default_snow_particle = {
amount = 3,
time = 0.5,
exptime = 5,
size = 50,
collisiondetection = false,
vertical = false,
}
local function get_snow_particledef(data)
for n,i in pairs(default_snow_particle) do
data[n] = data[n] or i
end
for _,i in pairs({"vel", "acc", "exptime", "size"}) do
data["min"..i] = data[i]
data["max"..i] = data[i]
end
data.texture = "weather_snow.png^[transform"..math.random(0,7)
return data
end
local function snow_fall(pos, player, animate)
function snow_fall(pos, player, animate)
local ground_y = nil
for y=pos.y+10,pos.y+20,1 do
local n = minetest.get_node({x=pos.x,y=y,z=pos.z}).name
@ -217,99 +21,198 @@ local function snow_fall(pos, player, animate)
pos = {x=pos.x, y=ground_y, z=pos.z}
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 = vector.round(player:getpos())
local YLIMIT = 1 -- Set to world's water level
-- Particles are timed to disappear at this y
-- Particles do not spawn when player's head is below this y
local PRECSPR = 6 -- Time scale for precipitation variation in minutes
local PRECOFF = -0.4 -- Precipitation offset, higher = rains more often
local GSCYCLE = 0.5 -- Globalstep cycle (seconds)
local FLAKES = 32 -- Snowflakes per cycle
local DROPS = 128 -- Raindrops per cycle
local RAINGAIN = 0.2 -- Rain sound volume
local COLLIDE = false -- Whether particles collide with nodes
local NISVAL = 39 -- Clouds RGB value at night
local DASVAL = 175 -- Clouds RGB value in daytime
-- Make sure player is not in a cave/house...
if get_snow(ppos)
and minetest.get_node_light(ppos, 0.5) == 15 then
local animate
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({
amount = 5,
minpos = addvectors(ppos, {x=-9, y=3, z=-9}),
maxpos = addvectors(ppos, {x= 9, y=5, z= 9}),
vel = vel,
acc = acc,
size = 25,
playername = player:get_player_name()
}))
local np_prec = {
offset = 0,
scale = 1,
spread = {x = PRECSPR, y = PRECSPR, z = PRECSPR},
seed = 813,
octaves = 1,
persist = 0,
lacunarity = 2.0,
--flags = ""
}
minetest.add_particlespawner(get_snow_particledef({
amount = 4,
minpos = addvectors(ppos, {x=-5, y=3.2, z=-5}),
maxpos = addvectors(ppos, {x= 5, y=1.6, z= 5}),
vel = vel,
acc = acc,
exptime = 4,
size = 25,
playername = player:get_player_name()
}))
-- These 2 must match biome heat and humidity noise parameters for a world
animate = false
else
animate = true
end
local np_temp = {
offset = 50,
scale = 50,
spread = {x = 1000, y = 1000, z = 1000},
seed = 5349,
octaves = 3,
persist = 0.5,
lacunarity = 2.0,
--flags = ""
}
if math.random(1,5) == 4 then
snow_fall(
randpos(
addvectors(ppos, {x=-20, y=0, z=-20}),
addvectors(ppos, {x= 20, y=0, z= 20})
),
player,
animate
)
end
end
end
end
local np_humid = {
offset = 50,
scale = 50,
spread = {x = 1000, y = 1000, z = 1000},
seed = 842,
octaves = 3,
persist = 0.5,
lacunarity = 2.0,
--flags = ""
}
local step_func
minetest.register_globalstep(function()
step_func()
end)
-- Stuff
local difsval = DASVAL - NISVAL
local grad = 14 / 95
local yint = 1496 / 95
-- Initialise noise objects to nil
local nobj_temp = nil
local nobj_humid = nil
local nobj_prec = nil
-- Globalstep function
local timer = 0
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")
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer < GSCYCLE then
return
end
elseif name == "lighter_snowfall" then
lighter_snowfall = v
end
end)
timer = 0
for _, player in ipairs(minetest.get_connected_players()) do
local player_name = player:get_player_name()
local ppos = player:getpos()
local pposy = math.floor(ppos.y) + 2 -- Precipitation when swimming
if pposy >= YLIMIT - 2 then
local pposx = math.floor(ppos.x)
local pposz = math.floor(ppos.z)
local ppos = {x = pposx, y = pposy, z = pposz}
local nobj_temp = nobj_temp or minetest.get_perlin(np_temp)
local nobj_humid = nobj_humid or minetest.get_perlin(np_humid)
local nobj_prec = nobj_prec or minetest.get_perlin(np_prec)
local nval_temp = nobj_temp:get2d({x = pposx, y = pposz})
local nval_humid = nobj_humid:get2d({x = pposx, y = pposz})
local nval_prec = nobj_prec:get2d({x = os.clock() / 60, y = 0})
-- Biome system: Frozen biomes below heat 35,
-- deserts below line 14 * t - 95 * h = -1496
-- h = (14 * t + 1496) / 95
-- h = 14/95 * t + 1496/95
-- where 14/95 is gradient and 1496/95 is y intersection
-- h - 14/95 t = 1496/95 y intersection
-- so area above line is
-- h - 14/95 t > 1496/95
local freeze = nval_temp < 35
local precip = nval_prec < (nval_humid - 50) / 50 + PRECOFF and
nval_humid - grad * nval_temp > yint
if snow.debug then
precip = true
end
-- Check if player is outside
local outside = minetest.get_node_light(ppos, 0.5) == 15
-- Occasionally reset player sky
if math.random() < 0.1 then
if precip then
-- Set overcast sky
local sval
local time = minetest.get_timeofday()
if time >= 0.5 then
time = 1 - time
end
-- Sky brightness transitions:
-- First transition (24000 -) 4500, (1 -) 0.1875
-- Last transition (24000 -) 5750, (1 -) 0.2396
if time <= 0.1875 then
sval = NISVAL
elseif time >= 0.2396 then
sval = DASVAL
else
sval = math.floor(NISVAL +
((time - 0.1875) / 0.0521) * difsval)
end
-- Set sky to overcast bluish-grey
player:set_sky(
{r = sval, g = sval, b = sval + 16, a = 255},
"plain",
{}
)
else
-- Reset sky to normal
player:set_sky({}, "regular", {})
end
end
if precip and outside then
-- Precipitation
if freeze then
-- Snowfall
local extime = math.min((pposy + 12 - YLIMIT) / 2, 9)
local x, y, z = pposx - 24 + math.random(0, 48), pposy + 12, pposz - 24 + math.random(0, 48)
if not snow.lighter_snowfall then
snow_fall({
x = x,
y = y,
z = z
}, true)
end
for flake = 1, FLAKES do
x, y, z = pposx - 24 + math.random(0, 48), pposy + 12, pposz - 24 + math.random(0, 48)
minetest.add_particle({
pos = {
x = x,
y = y,
z = z
},
velocity = {
x = (-20 + math.random(0, 40)) / 100,
y = -2.0,
z = (-20 + math.random(0, 40)) / 100
},
acceleration = {x = 0, y = 0, z = 0},
expirationtime = extime,
size = 2.8,
collisiondetection = COLLIDE,
collision_removal = true,
vertical = false,
texture = "snowdrift_snowflake" ..
math.random(1, 12) .. ".png",
playername = player:get_player_name()
})
end
end
end
end
end
end)
end

View File

@ -12,63 +12,66 @@ saplings grow into trees. --]]
-- Part 1: To disable the mapgen, add the *starting* comment under this line.
local perlin_scale, nosmooth_rarity
if not snow.disable_mapgen then
print("[snow] Mapgen enabled!")
snow.mapgen = snow.mapgen or {}
local mg = snow.mapgen
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
-- 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
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
local rarity = snow.mapgen_rarity
local size = snow.mapgen_size
local smooth = snow.smooth_biomes
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
-- TODO: if e.g. size and rarity get changed at once, don't calculate the values more times
calc_values()
end)
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.
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")
--Identify the mapgen.
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
end
-- To complete the commenting-out add the *closing* comment under this line.

View File

@ -266,12 +266,14 @@ nodedef.groups.flammable = 1
minetest.register_node("snow:apple", nodedef)
snow.known_plants[minetest.get_content_id("default:apple")] = minetest.get_content_id("snow:apple")
-- decay from default/nodes.lua:2537
default.register_leafdecay{
trunks = {"default:tree"},
leaves = {"snow:apple", "snow:leaves"},
radius = minetest.get_mapgen_setting"mg_name" == "v6" and 2 or 3,
}
if not snow.disable_mapgen then
-- decay from default/nodes.lua:2537
default.register_leafdecay{
trunks = {"default:tree"},
leaves = {"snow:apple", "snow:leaves"},
radius = minetest.get_mapgen_setting"mg_name" == "v6" and 2 or 3,
}
end
-- TODO
snow.known_plants[minetest.get_content_id("default:jungleleaves")] = minetest.get_content_id("default:jungleleaves")
@ -389,13 +391,21 @@ minetest.override_item("default:snow", {
}
},
leveled = 7,
paramtype2 = "leveled",
node_box = {
type = "leveled",
fixed = {
{-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
},
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
},
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3, falling_node=1, melts=2, float=1},
collision_box = {
type = "leveled",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
},
selection_box = {
type = "leveled",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5},
},
groups = {cracky=3, crumbly=3, choppy=3, oddly_breakable_by_hand=3,
falling_node=1, melts=2, float=1},
sunlight_propagates = true,
walkable = true,
node_placement_prediction = "",
@ -428,43 +438,71 @@ minetest.override_item("default:snow", {
end
end,
--Manage snow levels.
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local oldnode_under = minetest.get_node_or_nil(under)
local above = pointed_thing.above
if not oldnode_under
or not above then
return
on_place = function(itemstack, player, pt)
local oldnode_under = minetest.get_node_or_nil(pt.under)
if not oldnode_under then
return itemstack, false
end
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
olddef_under = olddef_under or minetest.nodedef_default
local olddef_under = minetest.registered_nodes[oldnode_under.name]
if not olddef_under then
return itemstack, false
end
local place_to
-- If node under is buildable_to, place into it instead (eg. snow)
local pos, node
if olddef_under.buildable_to then
place_to = under
pos = pt.under
node = oldnode_under
else
-- Place above pointed node
place_to = above
pos = pt.above
node = minetest.get_node(pos)
local def = minetest.registered_nodes[node.name]
if not def
or not def.buildable_to then
return itemstack, false
end
end
local level = minetest.get_node_level(place_to)
if level == 63 then
minetest.set_node(place_to, {name="default:snowblock"})
else
minetest.set_node_level(place_to, level+7)
-- nil player can place (for snowballs)
if player
and minetest.is_protected(pos, player:get_player_name()) then
return itemstack, false
end
if minetest.get_node(place_to).name ~= "default:snow" then
local itemstack, placed = minetest.item_place_node(itemstack, placer, pointed_thing)
return itemstack, placed
if node.name ~= "default:snow" then
if minetest.get_node{x=pos.x, y=pos.y-1, z=pos.z}.name ==
"default:snow" then
-- grow the snow below (fixes levelled problem)
pos.y = pos.y - 1
else
-- place a snow
return minetest.item_place_node(itemstack, player, pt)
end
end
-- grow the snow
local level = minetest.get_node_level(pos)
level = level + 7
if level < 64 then
minetest.set_node_level(pos, level)
else
-- place a snowblock and snow onto it if possible
local p = {x=pos.x, y=pos.y+1, z=pos.z}
local def = minetest.registered_nodes[minetest.get_node(p).name]
if not def
or not def.buildable_to then
return itemstack, false
end
minetest.set_node(pos, {name="default:snowblock"})
minetest.set_node(p, {name="default:snow"})
level = math.max(level - 64, 7)
minetest.set_node_level(p, level)
end
itemstack:take_item()
return itemstack
return itemstack, true
end,
on_use = snow.shoot_snowball
})

View File

@ -129,7 +129,7 @@ local function sled_rightclick(self, player)
position = {x=0.5, y=0.89},
name = "sled",
scale = {x=2, y=2},
text = "You are on the sled! Press the sneak key to get off the sled.", -- LazyJ
text = "You are on the sled! Hold the sneak key to get off the sled.", -- LazyJ
direction = 0,
})
-- End part 1

View File

@ -129,22 +129,40 @@ end
--Snowball_entity.on_step()--> called when snowball is moving.
function snow_snowball_ENTITY.on_step(self, dtime)
self.timer = self.timer+dtime
self.timer = self.timer + dtime
if self.timer > 10 then
-- 10 seconds is too long for a snowball to fly somewhere
-- 10 seconds are too long for a snowball to fly somewhere
self.object:remove()
return
end
if self.physical then
local fell = self.object:getvelocity().y == 0
local vel = self.object:getvelocity()
local fell = vel.y == 0
if not fell then
if self.probably_stuck then
self.probably_stuck = nil
end
return
end
if self.probably_stuck
and vel.x == 0
and vel.z == 0 then
-- add a small velocity to move it from the corner
vel.x = math.random() - 0.5
vel.z = math.random() - 0.5
self.object:set_velocity(vel)
self.probably_stuck = nil
return
end
local pos = vector.round(self.object:getpos())
if minetest.get_node(pos).name == "air" then
pos.y = pos.y-1
if minetest.get_node(pos).name == "air" then
if vel.x == 0
and vel.z == 0 then
self.probably_stuck = true
end
return
end
end

View File

@ -1,33 +1,18 @@
--Global config and function table.
snow = {
snowball_gravity = 100/109,
snowball_velocity = 19,
sleds = true,
enable_snowfall = true,
lighter_snowfall = false,
debug = false,
smooth_biomes = true,
christmas_content = true,
smooth_snow = true,
min_height = 3,
mapgen_rarity = 18,
mapgen_size = 210,
}
--Config documentation.
local doc = {
snowball_gravity = "The gravity of thrown snowballs",
snowball_velocity = "How fast players throw snowballs",
sleds = "Disable this to prevent sleds from being riden.",
enable_snowfall = "Enables falling snow.",
lighter_snowfall = "Reduces the amount of resources and fps used by snowfall.",
debug = "Enables debug output. Currently it only prints mgv6 info.",
smooth_biomes = "Enables smooth transition of biomes (mgv6)",
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)",
snowball_gravity = tonumber(minetest.settings:get("snow_snowball_gravity")) or 0.91,
snowball_velocity = tonumber(minetest.settings:get("snow_snowball_velocity")) or 19,
sleds = minetest.settings:get_bool("snow_sleds", true),
enable_snowfall = minetest.settings:get_bool("snow_enable_snowfall", true),
lighter_snowfall = minetest.settings:get_bool("snow_lighter_snowfall", false),
debug = minetest.settings:get_bool("snow_debug", false),
smooth_biomes = minetest.settings:get_bool("snow_smooth_biomes", true),
christmas_content = minetest.settings:get_bool("snow_christmas_content", true),
smooth_snow = minetest.settings:get_bool("snow_smooth_snow", true),
min_height = tonumber(minetest.settings:get("snow_min_height")) or 3,
mapgen_rarity = tonumber(minetest.settings:get("snow_mapgen_rarity")) or 18,
mapgen_size = tonumber(minetest.settings:get("snow_mapgen_size")) or 210,
disable_mapgen = minetest.settings:get_bool("snow_disable_mapgen", true),
}
@ -65,164 +50,3 @@ local function value_from_string(v)
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 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
local modpath = minetest.get_modpath("snow")
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")
if not file then
--Create config file.
return
end
config = {}
for line in file:lines() 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
io.close(file)
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(modpath.."/config.txt", snow, doc)
end
-- load settings from minetest.conf
for i,v in pairs(snow) do
if allowed_types[type(v)] then
local v = minetest.settings:get("snow_"..i)
if v ~= nil then
snow[i] = value_from_string(v)
end
end
end
--MENU
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
ids[2][n2] = {i,v}
n2 = n2+1
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
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_chatcommand("snow", {
description = "Show a menu for various actions",
privs = {server=true},
func = function(name)
minetest.chat_send_player(name, "Showing snow menu…")
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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B