mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-12-24 17:50:37 +01:00
parent
e4ef41d7af
commit
b8e61fd763
3
mods/snow/.gitignore
vendored
Normal file
3
mods/snow/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
config.txt
|
||||
debug.txt
|
||||
*~
|
@ -1,2 +1,3 @@
|
||||
default
|
||||
moreblocks?
|
||||
technic_worldgen?
|
||||
|
@ -71,7 +71,7 @@ dofile(minetest.get_modpath("snow").."/src/sled.lua")
|
||||
|
||||
-- Check for "MoreBlocks". If not found, skip this next "dofile".
|
||||
|
||||
if (minetest.get_modpath("moreblocks")) then
|
||||
if minetest.get_modpath("moreblocks") then
|
||||
|
||||
dofile(minetest.get_modpath("snow").."/src/stairsplus.lua")
|
||||
|
||||
@ -82,34 +82,52 @@ end
|
||||
function snow.place(pos)
|
||||
if pos.y < -19000 then return end -- Don't put anything in the nether!
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
local drawtype = ""
|
||||
if node and minetest.registered_nodes[node.name] then
|
||||
drawtype = minetest.registered_nodes[node.name].drawtype
|
||||
end
|
||||
|
||||
--Oops, maybe there is no node?
|
||||
if node == nil then
|
||||
if not node
|
||||
or not minetest.registered_nodes[node.name] then
|
||||
return
|
||||
end
|
||||
|
||||
local bnode = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
|
||||
if node.name == "default:snow" and minetest.get_node_level(pos) < 63 then
|
||||
if minetest.get_item_group(bnode.name, "leafdecay") == 0 and snow.is_uneven(pos) ~= true then
|
||||
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
|
||||
minetest.sound_play("default_snow_footstep", {pos=pos})
|
||||
minetest.add_node_level(pos, 7)
|
||||
end
|
||||
elseif node.name == "default:snow" and minetest.get_node_level(pos) == 63 then
|
||||
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 p
|
||||
and minetest.get_node_light(p, 0.5) == 15 then
|
||||
minetest.sound_play("default_grass_footstep", {pos=pos})
|
||||
minetest.place_node({x=pos.x, y=pos.y+1, z=pos.z}, {name="default:snow"})
|
||||
else
|
||||
minetest.sound_play("default_snow_footstep", {pos=pos})
|
||||
minetest.add_node(pos, {name="default:snowblock"})
|
||||
end
|
||||
elseif node.name ~= "default:ice" and bnode.name ~= "air" then
|
||||
if drawtype == "normal" or drawtype == "allfaces_optional" then
|
||||
minetest.place_node({x=pos.x,y=pos.y+1,z=pos.z}, {name="default:snow"})
|
||||
end
|
||||
elseif node.name ~= "default:ice"
|
||||
and bnode.name ~= "air" then
|
||||
local data = minetest.registered_nodes[node.name]
|
||||
local drawtype = data.drawtype
|
||||
if drawtype == "normal"
|
||||
or drawtype == "allfaces_optional" then
|
||||
pos.y = pos.y+1
|
||||
local sound = data.sounds
|
||||
if sound then
|
||||
sound = sound.footstep
|
||||
if sound then
|
||||
minetest.sound_play(sound.name, {pos=pos, gain=sound.gain})
|
||||
end
|
||||
end
|
||||
minetest.place_node(pos, {name="default:snow"})
|
||||
elseif drawtype == "plantlike" then
|
||||
pos.y = pos.y - 1
|
||||
if minetest.get_node(pos).name == "default:dirt_with_grass" then
|
||||
minetest.sound_play("default_grass_footstep", {pos=pos})
|
||||
minetest.add_node(pos, {name="default:dirt_with_snow"})
|
||||
end
|
||||
end
|
||||
@ -118,9 +136,7 @@ end
|
||||
|
||||
-- Checks if the snow level is even at any given pos.
|
||||
-- Smooth Snow
|
||||
local smooth_snow = snow.smooth_snow
|
||||
snow.is_uneven = function(pos)
|
||||
if smooth_snow then
|
||||
local function is_uneven(pos)
|
||||
local num = minetest.get_node_level(pos)
|
||||
local get_node = minetest.get_node
|
||||
local add_node = minetest.add_node
|
||||
@ -128,40 +144,48 @@ snow.is_uneven = function(pos)
|
||||
local foundx
|
||||
local foundy
|
||||
local foundz
|
||||
for x=-1,1 do
|
||||
for z = -1,1 do
|
||||
local node = get_node({x=pos.x+x,y=pos.y,z=pos.z+z})
|
||||
local bnode = get_node({x=pos.x+x,y=pos.y-1,z=pos.z+z})
|
||||
local drawtype
|
||||
if node and minetest.registered_nodes[node.name] then
|
||||
drawtype = minetest.registered_nodes[node.name].drawtype
|
||||
end
|
||||
for x = -1,1 do
|
||||
local p = {x=pos.x+x, y=pos.y, z=pos.z+z}
|
||||
local node = get_node(p)
|
||||
p.y = p.y-1
|
||||
local bnode = get_node(p)
|
||||
|
||||
if drawtype == "plantlike" then
|
||||
if bnode.name == "default:dirt_with_grass" then
|
||||
add_node({x=pos.x+x,y=pos.y-1,z=pos.z+z}, {name="default:dirt_with_snow"})
|
||||
if node
|
||||
and minetest.registered_nodes[node.name]
|
||||
and minetest.registered_nodes[node.name].drawtype == "plantlike"
|
||||
and bnode.name == "default:dirt_with_grass" then
|
||||
add_node(p, {name="default:dirt_with_snow"})
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
if (not(x == 0 and y == 0)) and node.name == "default:snow" and minetest.get_node_level({x=pos.x+x,y=pos.y,z=pos.z+z}) < num then
|
||||
p.y = p.y+1
|
||||
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" and bnode.name ~= "air" then
|
||||
if not (bnode.name == "default:snow") then
|
||||
snow.place({x=pos.x+x,y=pos.y-1,z=pos.z+z})
|
||||
elseif node.name == "air"
|
||||
and bnode.name ~= "air"
|
||||
and bnode.name ~= "default:snow" then
|
||||
p.y = p.y-1
|
||||
snow.place(p)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if found then
|
||||
local node = get_node({x=pos.x+foundx,y=pos.y,z=pos.z+foundz})
|
||||
if snow.is_uneven({x=pos.x+foundx,y=pos.y,z=pos.z+foundz}) ~= true then
|
||||
minetest.add_node_level({x=pos.x+foundx,y=pos.y,z=pos.z+foundz}, 7)
|
||||
local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz}
|
||||
if is_uneven(p) ~= true 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
|
||||
end
|
||||
|
@ -40,10 +40,6 @@ near torches and lava.
|
||||
--=============================================================
|
||||
|
||||
|
||||
if not snow.enable_snowfall then
|
||||
return
|
||||
end
|
||||
|
||||
local weather_legacy
|
||||
|
||||
local read_weather_legacy = function ()
|
||||
@ -84,7 +80,7 @@ local PERSISTENCE3 = 0.5 -- 0.5
|
||||
local SCALE3 = 250 -- 250
|
||||
|
||||
--Get snow at position.
|
||||
local get_snow = function(pos)
|
||||
local function get_snow(pos)
|
||||
--Legacy support.
|
||||
if weather_legacy == "snow" then
|
||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
||||
@ -106,14 +102,19 @@ end
|
||||
local addvectors = vector and vector.add
|
||||
|
||||
--Returns a random position between minp and maxp.
|
||||
local randpos = function (minp, maxp)
|
||||
local x,y,z
|
||||
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
|
||||
y = minp.y
|
||||
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=y,z=z}
|
||||
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 = {
|
||||
@ -152,22 +153,20 @@ local function snow_fall(pos, player, animate)
|
||||
break
|
||||
end
|
||||
end
|
||||
if not ground_y then return end
|
||||
pos = {x=pos.x, y=ground_y, z=pos.z}
|
||||
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
||||
if not ground_y then
|
||||
return
|
||||
end
|
||||
|
||||
pos = {x=pos.x, y=ground_y, z=pos.z}
|
||||
|
||||
if get_snow(pos) then
|
||||
if animate then
|
||||
local minp = addvectors(spos, {x=-9, y=3, z=-9})
|
||||
local maxp = addvectors(spos, {x= 9, y=5, z= 9})
|
||||
local vel = {x=0, y= -1, z=-1}
|
||||
local acc = {x=0, y= 0, z=0}
|
||||
local spos = {x=pos.x, y=ground_y+10, z=pos.z}
|
||||
minetest.add_particlespawner(get_snow_particledef({
|
||||
minpos = minp,
|
||||
maxpos = maxp,
|
||||
vel = vel,
|
||||
acc = acc,
|
||||
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
|
||||
@ -177,30 +176,21 @@ local function snow_fall(pos, player, animate)
|
||||
end
|
||||
|
||||
-- Snow
|
||||
minetest.register_globalstep(function(dtime)
|
||||
local function calc_snowfall()
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local ppos = player:getpos()
|
||||
|
||||
local sminp = addvectors(ppos, {x=-20, y=0, z=-20})
|
||||
local smaxp = addvectors(ppos, {x= 20, y=0, z= 20})
|
||||
|
||||
-- Make sure player is not in a cave/house...
|
||||
if get_snow(ppos) and minetest.get_node_light(ppos, 0.5) == 15 then
|
||||
|
||||
local minp = addvectors(ppos, {x=-9, y=3, z=-9})
|
||||
local maxp = addvectors(ppos, {x= 9, y=5, z= 9})
|
||||
|
||||
local minp_deep = addvectors(ppos, {x=-5, y=3.2, z=-5})
|
||||
local maxp_deep = addvectors(ppos, {x= 5, y=1.6, z= 5})
|
||||
|
||||
if get_snow(ppos)
|
||||
and minetest.get_node_light(ppos, 0.5) == 15 then
|
||||
local animate
|
||||
if not snow.lighter_snowfall then
|
||||
local vel = {x=0, y=-1, z=-1}
|
||||
local acc = {x=0, y=0, z=0}
|
||||
|
||||
if not snow.lighter_snowfall then
|
||||
minetest.add_particlespawner(get_snow_particledef({
|
||||
amount = 5,
|
||||
minpos = minp,
|
||||
maxpos = maxp,
|
||||
minpos = addvectors(ppos, {x=-9, y=3, z=-9}),
|
||||
maxpos = addvectors(ppos, {x= 9, y=5, z= 9}),
|
||||
vel = vel,
|
||||
acc = acc,
|
||||
size = 25,
|
||||
@ -209,8 +199,8 @@ minetest.register_globalstep(function(dtime)
|
||||
|
||||
minetest.add_particlespawner(get_snow_particledef({
|
||||
amount = 4,
|
||||
minpos = minp_deep,
|
||||
maxpos = maxp_deep,
|
||||
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,
|
||||
@ -218,14 +208,27 @@ minetest.register_globalstep(function(dtime)
|
||||
playername = player:get_player_name()
|
||||
}))
|
||||
|
||||
if math.random(1,5) == 4 then
|
||||
snow_fall(randpos(sminp, smaxp), player)
|
||||
end
|
||||
animate = false
|
||||
else
|
||||
animate = true
|
||||
end
|
||||
|
||||
if math.random(1,5) == 4 then
|
||||
snow_fall(randpos(sminp, smaxp), player, true)
|
||||
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
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if snow.enable_snowfall then
|
||||
calc_snowfall()
|
||||
end
|
||||
end)
|
||||
|
@ -13,13 +13,10 @@ saplings grow into trees. --]]
|
||||
-- Part 1: To disable the mapgen, add the *starting* comment under this line.
|
||||
|
||||
|
||||
local mgname = ""
|
||||
|
||||
--Identify the mapgen.
|
||||
minetest.register_on_mapgen_init(function(MapgenParams)
|
||||
if MapgenParams.mgname then
|
||||
mgname = MapgenParams.mgname
|
||||
else
|
||||
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
|
||||
@ -72,18 +69,19 @@ function snow.make_pine(pos,snow,xmas)
|
||||
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" or n == "ignore" then
|
||||
if n == "air"
|
||||
or n == "ignore" then
|
||||
minetest.add_node(pos, node)
|
||||
end
|
||||
end
|
||||
--Clear ground.
|
||||
for x=-1,1 do
|
||||
for z = -1,1 do
|
||||
if minetest.get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snow" then
|
||||
minetest.remove_node({x=pos.x+x,y=pos.y,z=pos.z+z})
|
||||
end
|
||||
if minetest.get_node({x=pos.x+x,y=pos.y,z=pos.z+z}).name == "default:snowblock" then
|
||||
minetest.remove_node({x=pos.x+x,y=pos.y,z=pos.z+z})
|
||||
for x = -1,1 do
|
||||
local p = {x=pos.x+x,y=pos.y,z=pos.z+z}
|
||||
local nd = minetest.get_node(p).name
|
||||
if nd == "default:snow"
|
||||
or nd == "default:snowblock" then
|
||||
minetest.remove_node(p)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -107,7 +105,8 @@ function snow.make_pine(pos,snow,xmas)
|
||||
end
|
||||
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
|
||||
elseif snow
|
||||
and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
||||
try_node({x=pos.x,y=pos.y+7,z=pos.z},{name="default:snow"})
|
||||
end
|
||||
end
|
||||
@ -122,32 +121,32 @@ function snow.voxelmanip_pine(pos,a,data)
|
||||
local c_air = minetest.get_content_id("air")
|
||||
|
||||
local perlin1 = minetest.get_perlin(112,3, 0.5, 150)
|
||||
--Clear ground.
|
||||
for x=-1,1 do
|
||||
for z = -1,1 do
|
||||
local node = a:index(pos.x+x,pos.y,pos.z+z)
|
||||
local z = pos.z + z
|
||||
for x = -1,1 do
|
||||
local x = pos.x + x
|
||||
|
||||
--Clear ground.
|
||||
local node = a:index(x,pos.y,z)
|
||||
if data[node] == c_snow then
|
||||
data[node] = c_air
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--Make tree.
|
||||
for i=0, 4 do
|
||||
if i==1 or i==2 then
|
||||
for x=-1,1 do
|
||||
for z=-1,1 do
|
||||
local x = pos.x + x
|
||||
local z = pos.z + z
|
||||
for i = 1,2 do
|
||||
local node = a:index(x,pos.y+i,z)
|
||||
data[node] = c_pine_needles
|
||||
if snow and x ~= 0 and z ~= 0 and perlin1:get2d({x=x,y=z}) > 0.53 then
|
||||
if snow
|
||||
and x ~= 0
|
||||
and z ~= 0
|
||||
and perlin1:get2d({x=x,y=z}) > 0.53 then
|
||||
local abovenode = a:index(x,pos.y+i+1,z)
|
||||
data[abovenode] = c_snow
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if i==3 or i==4 then
|
||||
for i=3, 4 do
|
||||
local x = pos.x
|
||||
local y = pos.y+i
|
||||
local z = pos.z
|
||||
@ -170,11 +169,13 @@ function snow.voxelmanip_pine(pos,a,data)
|
||||
end
|
||||
end
|
||||
end
|
||||
for i=0, 4 do
|
||||
data[a:index(pos.x,pos.y+i,pos.z)] = c_pinetree
|
||||
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 snow and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
||||
if snow
|
||||
and perlin1:get2d({x=pos.x,y=pos.z}) > 0.53 then
|
||||
data[a:index(pos.x,pos.y+7,pos.z)] = c_snow
|
||||
end
|
||||
end
|
||||
|
@ -22,33 +22,38 @@ local np_ice = {
|
||||
|
||||
-- Debugging function
|
||||
|
||||
local biome_to_string = function(num,num2)
|
||||
local biome, biome2
|
||||
if num == 1 then
|
||||
biome = "snowy"
|
||||
elseif num == 2 then
|
||||
biome = "plain"
|
||||
elseif num == 3 then
|
||||
biome = "alpine"
|
||||
elseif num == 4 or num == 5 then
|
||||
biome = "normal"
|
||||
else
|
||||
biome = "unknown "..num
|
||||
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
|
||||
if num2 == 1 then
|
||||
biome2 = "cool"
|
||||
elseif num2 == 2 then
|
||||
biome2 = "icebergs"
|
||||
elseif num2 == 3 then
|
||||
biome2 = "icesheet"
|
||||
elseif num2 == 4 then
|
||||
biome2 = "icecave"
|
||||
elseif num2 == 5 then
|
||||
biome2 = "icehole"
|
||||
else
|
||||
biome2 = "unknown "..num
|
||||
|
||||
local function do_ws_func(a, x)
|
||||
local n = x/(16000)
|
||||
local y = 0
|
||||
for k=1,1000 do
|
||||
y = y + 1000*(math.sin(math.pi * k^a * n)/(math.pi * k^a))
|
||||
end
|
||||
return biome, biome2
|
||||
return y
|
||||
end
|
||||
|
||||
local ws_lists = {}
|
||||
local function get_ws_list(a,x)
|
||||
ws_lists[a] = ws_lists[a] or {}
|
||||
local v = ws_lists[a][x]
|
||||
if v then
|
||||
return v
|
||||
end
|
||||
v = {}
|
||||
for x=x,x + (80 - 1) do
|
||||
local y = do_ws_func(a, x)
|
||||
v[x] = y
|
||||
end
|
||||
ws_lists[a][x] = v
|
||||
return v
|
||||
end
|
||||
|
||||
-- On generated function
|
||||
@ -61,11 +66,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
local x1 = maxp.x
|
||||
local z1 = maxp.z
|
||||
|
||||
local debug = snow.debug
|
||||
local min_height = snow.min_height
|
||||
local spawn_pine = snow.voxelmanip_pine
|
||||
local smooth = snow.smooth_biomes
|
||||
local legacy = snow.legacy
|
||||
|
||||
local c_dirt_with_grass = minetest.get_content_id("default:dirt_with_grass")
|
||||
local c_dirt = minetest.get_content_id("default:dirt")
|
||||
@ -91,30 +93,21 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
|
||||
local data = vm:get_data()
|
||||
|
||||
local snow_tab,num = {},1
|
||||
|
||||
local sidelen = x1 - x0 + 1
|
||||
local chulens = {x=sidelen, y=sidelen, z=sidelen}
|
||||
local minpos = {x=x0, y=z0}
|
||||
local nvals_cold = minetest.get_perlin_map(np_cold, chulens):get2dMap_flat({x=x0, y=z0})
|
||||
local nvals_ice = minetest.get_perlin_map(np_ice, chulens):get2dMap_flat({x=x0, y=z0})
|
||||
|
||||
-- Choose biomes
|
||||
local pr = PseudoRandom(seed+57)
|
||||
local biome
|
||||
-- Land biomes
|
||||
biome = pr:next(1, 5)
|
||||
local biome = pr:next(1, 5)
|
||||
local snowy = biome == 1 -- spawns alot of snow
|
||||
local plain = biome == 2 -- spawns not much
|
||||
local alpine = biome == 3 -- rocky terrain
|
||||
-- Water biomes
|
||||
local biome2 = pr:next(1, 5)
|
||||
local cool = biome == 1 -- only spawns ice on edge of water
|
||||
local icebergs = biome == 2
|
||||
local icesheet = biome == 3
|
||||
local icecave = biome == 4
|
||||
local icehole = biome == 5 -- icesheet with holes
|
||||
-- Misc biome settings
|
||||
local icy = pr:next(1, 2) == 2 -- if enabled spawns ice in sand instead of snow blocks
|
||||
local mossy = pr:next(1,2) == 1 -- spawns moss in snow
|
||||
local shrubs = pr:next(1,2) == 1 -- spawns dry shrubs in snow
|
||||
local pines = pr:next(1,2) == 1 -- spawns pines
|
||||
-- Reseed random
|
||||
@ -135,11 +128,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
|
||||
if not in_biome then
|
||||
if alpine == true and test > 0.43 then
|
||||
if alpine and test > 0.43 then
|
||||
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
|
||||
if nodid ~= c_air
|
||||
and nodid ~= c_ignore then
|
||||
ground_y = y
|
||||
break
|
||||
end
|
||||
@ -155,7 +149,6 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
if id == c_leaves
|
||||
or id == c_jungleleaves
|
||||
or id == c_tree
|
||||
or id == c_air
|
||||
or id == c_apple then
|
||||
data[vi] = c_air
|
||||
else
|
||||
@ -169,9 +162,9 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
elseif in_biome then
|
||||
write_to_map = true
|
||||
local icetype = nvals_ice[ni]
|
||||
local cool = icetype > 0
|
||||
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
|
||||
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
|
||||
|
||||
@ -191,7 +184,8 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
|
||||
if ground_y and data[node] == c_dirt_with_grass then
|
||||
if alpine and test > 0.53 then
|
||||
data[abovenode] = c_snow
|
||||
snow_tab[num] = {abovenode, z, x, test}
|
||||
num = num+1
|
||||
for y = ground_y, -6, -1 do
|
||||
local vi = area:index(x, y, z)
|
||||
if data[vi] == c_stone then
|
||||
@ -210,18 +204,21 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
data[abovenode] = c_snow_block
|
||||
else
|
||||
data[node] = c_dirt_with_snow
|
||||
data[abovenode] = c_snow
|
||||
snow_tab[num] = {abovenode, z, x, test}
|
||||
num = num+1
|
||||
end
|
||||
elseif ground_y and data[node] == c_sand then
|
||||
if not icy then
|
||||
data[abovenode] = c_snow
|
||||
snow_tab[num] = {abovenode, z, x, test}
|
||||
num = num+1
|
||||
else
|
||||
data[node] = c_ice
|
||||
end
|
||||
elseif ground_y and data[node] == c_leaves
|
||||
or data[node] == c_jungleleaves or data[node] == c_apple then
|
||||
if alpine then
|
||||
data[abovenode] = c_snow
|
||||
snow_tab[num] = {abovenode, z, x, test}
|
||||
num = num+1
|
||||
for y = ground_y, -6, -1 do
|
||||
local stone = area:index(x, y, z)
|
||||
if data[stone] == c_stone then
|
||||
@ -231,54 +228,64 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
end
|
||||
else
|
||||
data[abovenode] = c_snow
|
||||
snow_tab[num] = {abovenode, z, x, test}
|
||||
num = num+1
|
||||
end
|
||||
elseif ground_y and data[node] == c_junglegrass then
|
||||
elseif ground_y
|
||||
and data[node] == c_junglegrass then
|
||||
data[node] = c_dry_shrub
|
||||
elseif ground_y and data[node] == c_papyrus then
|
||||
elseif ground_y
|
||||
and data[node] == c_papyrus then
|
||||
for y = ground_y, ground_y-4, -1 do
|
||||
local vi = area:index(x, y, z)
|
||||
if data[vi] == c_papyrus then
|
||||
local via = area:index(x, ground_y, z)
|
||||
data[via] = c_snow
|
||||
snow_tab[num] = {area:index(x, ground_y, z), z, x, test}
|
||||
num = num+1
|
||||
data[vi] = c_snow_block
|
||||
end
|
||||
end
|
||||
elseif ground_y and data[node] == c_water then
|
||||
if not icesheet and not icecave and not icehole then
|
||||
elseif ground_y
|
||||
and data[node] == c_water then
|
||||
if not icesheet
|
||||
and not icecave
|
||||
and not icehole then
|
||||
local x1 = data[area:index(x+1, ground_y, z)]
|
||||
local z1 = data[area:index(x, ground_y, z+1)]
|
||||
local xz1 = data[area:index(x+1, ground_y, z+1)]
|
||||
local xz2 = data[area:index(x-1, ground_y, z-1)]
|
||||
local x2 = data[area:index(x-1, ground_y, z)]
|
||||
local z2 = data[area:index(x, ground_y, z-1)]
|
||||
local rand = (pr:next(1,4) == 1) and (cool or icebergs)
|
||||
local ice
|
||||
if rand then
|
||||
for _,i in ipairs({x1,z1,xz1,xz2,x2,z2}) do
|
||||
if i == c_ice then
|
||||
ice = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not ice then
|
||||
for _,i in ipairs({x1,z1,xz1,xz2,x2,z2}) do
|
||||
if i ~= c_water
|
||||
and i ~= c_ice
|
||||
and i ~= c_air
|
||||
and i ~= c_ignore then
|
||||
ice = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
local y = data[area:index(x, ground_y-1, z)]
|
||||
local rand = pr:next(1,4) == 1
|
||||
if ((x1 and x1 ~= c_water and x1 ~= c_ice
|
||||
and x1 ~= c_air and x1 ~= c_ignore)
|
||||
or (rand and (cool or icebergs) and x1 == c_ice))
|
||||
or ((z1 and z1 ~= c_water and z1 ~= c_ice
|
||||
and z1 ~= c_air and z1 ~= c_ignore)
|
||||
or (rand and (cool or icebergs) and z1 == c_ice))
|
||||
or ((xz1 and xz1 ~= c_water and xz1 ~= c_ice
|
||||
and xz1 ~= c_air and xz1 ~= c_ignore)
|
||||
or (rand and (cool or icebergs) and xz1 == c_ice))
|
||||
or ((xz2 and xz2 ~= c_water and xz2 ~= c_ice
|
||||
and xz2 ~= c_air and xz2 ~= c_ignore)
|
||||
or (rand and (cool or icebergs) and xz2 == c_ice))
|
||||
or ((x2 and x2 ~= c_water and x2 ~= c_ice
|
||||
and x2 ~= c_air and x2 ~= c_ignore)
|
||||
or (rand and (cool or icebergs) and x2 == c_ice))
|
||||
or ((z2 and z2 ~= c_water and z2 ~= c_ice
|
||||
and z2 ~= c_air and z2 ~= c_ignore)
|
||||
or (rand and (cool or icebergs) and z2 == c_ice))
|
||||
if ice
|
||||
or (y ~= c_water and y ~= c_ice) -- and y ~= "air") …I don't think y can be a string here ~HybridDog
|
||||
or (icebergs and pr:next(1,6) == 1) then
|
||||
data[node] = c_ice
|
||||
end
|
||||
else
|
||||
if (icehole and pr:next(1,10) > 1)
|
||||
or icecave or icesheet then
|
||||
or icecave
|
||||
or icesheet then
|
||||
data[node] = c_ice
|
||||
end
|
||||
if icecave then
|
||||
@ -299,15 +306,46 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
end
|
||||
|
||||
local param2s
|
||||
if num ~= 1 then
|
||||
local wsz, wsx
|
||||
for _,i in pairs(snow_tab) do
|
||||
local p,z,x,test = unpack(i)
|
||||
data[p] = c_snow
|
||||
test = test-0.73
|
||||
if test > 0 then
|
||||
local minh = math.floor(test*4*9)%9+1
|
||||
if minh ~= 1 then
|
||||
if not wsz then
|
||||
wsz = get_ws_list(5, z0)
|
||||
wsx = get_ws_list(2, x0)
|
||||
param2s = vm:get_param2_data()
|
||||
end
|
||||
local h = math.min(minh, math.floor(wsx[x]+wsz[z]*5)%9+1)
|
||||
if h ~= 1 then
|
||||
if h == 9 then
|
||||
h = 4
|
||||
end
|
||||
param2s[p] = h*7
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
vm:set_data(data)
|
||||
if param2s then
|
||||
vm:set_param2_data(param2s)
|
||||
end
|
||||
vm:set_lighting({day=0, night=0})
|
||||
vm:calc_lighting()
|
||||
vm:write_to_map()
|
||||
|
||||
if write_to_map and debug then -- print if any column of mapchunk was snow biome
|
||||
local biome_string,biome2_string = biome_to_string(biome,biome2)
|
||||
if write_to_map
|
||||
and snow.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.." and "..biome2_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)
|
||||
|
||||
|
@ -197,8 +197,9 @@ minetest.register_node("snow:star", {
|
||||
--groups = {snappy=2,dig_immediate=3},
|
||||
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1}, -- Don't want the ornament breaking too easily because you have to punch it to turn it on and off. ~ LazyJ
|
||||
sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}), -- Breaking "glass" sound makes it sound like a real, broken, Xmas tree ornament (Sorry, Mom!). ;)- ~ LazyJ
|
||||
on_punch = function(pos, node, puncher) -- Added a "lit" star that can be punched on or off depending on your preference. ~ LazyJ
|
||||
minetest.set_node(pos, {name = "snow:star_lit"})
|
||||
on_punch = function(pos, node) -- Added a "lit" star that can be punched on or off depending on your preference. ~ LazyJ
|
||||
node.name = "snow:star_lit"
|
||||
minetest.set_node(pos, node)
|
||||
nodeupdate(pos)
|
||||
end,
|
||||
})
|
||||
@ -217,8 +218,9 @@ minetest.register_node("snow:star_lit", {
|
||||
drop = "snow:star",
|
||||
groups = {cracky=1, crumbly=1, choppy=1, oddly_breakable_by_hand=1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_glass_defaults({dig = {name="default_glass_footstep", gain=0.2}}),
|
||||
on_punch = function(pos, node, puncher)
|
||||
minetest.set_node(pos, {name = "snow:star"})
|
||||
on_punch = function(pos, node)
|
||||
node.name = "snow:star"
|
||||
minetest.set_node(pos, node)
|
||||
nodeupdate(pos)
|
||||
end,
|
||||
})
|
||||
@ -328,7 +330,7 @@ minetest.override_item("default:ice", {
|
||||
on_construct = snow_onto_dirt,
|
||||
liquids_pointable = true,
|
||||
--Make ice freeze over when placed by a maximum of 10 blocks.
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
after_place_node = function(pos)
|
||||
minetest.set_node(pos, {name="default:ice", param2=math.random(0,10)})
|
||||
end
|
||||
})
|
||||
|
@ -39,6 +39,7 @@ scattered in my note-taking program. This "Oh, I'll just make a little tweak her
|
||||
little tweak there" project has evolved into something much bigger and more complex
|
||||
than I originally planned. :p ~ LazyJ
|
||||
|
||||
* find out why the sled disappears after rightclicking it ~ HybridDog
|
||||
|
||||
--]]
|
||||
|
||||
@ -52,9 +53,19 @@ than I originally planned. :p ~ LazyJ
|
||||
-- Helper functions
|
||||
--
|
||||
|
||||
vector.zero = vector.zero or {x=0, y=0, z=0}
|
||||
|
||||
local function table_find(t, v)
|
||||
for i = 1,#t do
|
||||
if t[i] == v then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function is_water(pos)
|
||||
local nn = minetest.get_node(pos).name
|
||||
return minetest.get_item_group(nn, "water") ~= 0
|
||||
return minetest.get_item_group(minetest.get_node(pos).name, "water") ~= 0
|
||||
end
|
||||
|
||||
|
||||
@ -63,45 +74,58 @@ end
|
||||
--
|
||||
|
||||
local sled = {
|
||||
physical = false,
|
||||
physical = true,
|
||||
collisionbox = {-0.6,-0.25,-0.6, 0.6,0.3,0.6},
|
||||
visual = "mesh",
|
||||
mesh = "sled.x",
|
||||
textures = {"sled.png"},
|
||||
nil,
|
||||
|
||||
driver = nil,
|
||||
sliding = false,
|
||||
}
|
||||
|
||||
local players_sled = {}
|
||||
local function join_sled(self, player)
|
||||
local pos = self.object:getpos()
|
||||
player:setpos(pos)
|
||||
local name = player:get_player_name()
|
||||
players_sled[name] = true
|
||||
default.player_attached[name] = true
|
||||
default.player_set_animation(player, "sit" , 30)
|
||||
self.driver = name
|
||||
self.object:set_attach(player, "", {x=0,y=-9,z=0}, {x=0,y=90,z=0})
|
||||
self.object:setyaw(player:get_look_yaw())-- - math.pi/2)
|
||||
end
|
||||
|
||||
function sled:on_rightclick(clicker)
|
||||
if (not self.driver) and snow.sleds then
|
||||
players_sled[clicker:get_player_name()] = true
|
||||
self.driver = clicker
|
||||
self.object:set_attach(clicker, "", {x=0,y=-9,z=0}, {x=0,y=90,z=0})
|
||||
clicker:set_physics_override({
|
||||
local function leave_sled(self, player)
|
||||
local name = player:get_player_name()
|
||||
players_sled[name] = false
|
||||
self.driver = nil
|
||||
player:set_detach()
|
||||
default.player_attached[name] = false
|
||||
default.player_set_animation(player, "stand" , 30)
|
||||
|
||||
player:set_physics_override({
|
||||
speed = 1,
|
||||
jump = 1,
|
||||
})
|
||||
player:hud_remove(self.HUD) -- And here is part 2. ~ LazyJ
|
||||
self.object:remove()
|
||||
|
||||
--Give the sled back again
|
||||
player:get_inventory():add_item("main", "snow:sled")
|
||||
end
|
||||
|
||||
function sled:on_rightclick(player)
|
||||
if self.driver
|
||||
or not snow.sleds then
|
||||
return
|
||||
end
|
||||
join_sled(self, player)
|
||||
player:set_physics_override({
|
||||
speed = 2, -- multiplier to default value
|
||||
jump = 0, -- multiplier to default value
|
||||
gravity = 1
|
||||
})
|
||||
--[[
|
||||
local HUD =
|
||||
{
|
||||
hud_elem_type = "text", -- see HUD element types
|
||||
position = {x=0.5, y=0.89},
|
||||
name = "sled",
|
||||
scale = {x=2, y=2},
|
||||
text = "You are sledding, hold sneak to stop.",
|
||||
direction = 0,
|
||||
}
|
||||
|
||||
clicker:hud_add(HUD)
|
||||
--]]
|
||||
|
||||
-- Here is part 1 of the fix. ~ LazyJ
|
||||
self.HUD = clicker:hud_add({
|
||||
self.HUD = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = {x=0.5, y=0.89},
|
||||
name = "sled",
|
||||
@ -111,57 +135,55 @@ function sled:on_rightclick(clicker)
|
||||
})
|
||||
-- End part 1
|
||||
end
|
||||
end
|
||||
|
||||
function sled:on_activate(staticdata, dtime_s)
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
self.object:setacceleration({x=0, y=-10, z=0})
|
||||
if staticdata then
|
||||
self.v = tonumber(staticdata)
|
||||
end
|
||||
end
|
||||
|
||||
function sled:get_staticdata()
|
||||
return tostring(v)
|
||||
return tostring(self.v)
|
||||
end
|
||||
|
||||
function sled:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
|
||||
function sled:on_punch(puncher)
|
||||
self.object:remove()
|
||||
if puncher and puncher:is_player() then
|
||||
if puncher
|
||||
and puncher:is_player() then
|
||||
puncher:get_inventory():add_item("main", "snow:sled")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
if players_sled[player:get_player_name()] then
|
||||
default.player_set_animation(player, "sit", 0)
|
||||
local driveable_nodes = {"default:snow","default:snowblock","default:ice","default:dirt_with_snow", "group:icemaker"}
|
||||
local function accelerating_possible(pos)
|
||||
if is_water(pos) then
|
||||
return false
|
||||
end
|
||||
if table_find(driveable_nodes, minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name) then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
end)
|
||||
|
||||
local timer = 0
|
||||
function sled:on_step(dtime)
|
||||
if self.driver then
|
||||
local p = self.object:getpos()
|
||||
p.y = p.y+0.4
|
||||
local s = self.object:getpos()
|
||||
s.y = s.y -0.5
|
||||
local keys = self.driver:get_player_control()
|
||||
if keys["sneak"] or is_water(p) or (not minetest.find_node_near(s, 1, {"default:snow","default:snowblock","default:ice","default:dirt_with_snow", "group:icemaker"})) then -- LazyJ
|
||||
self.driver:set_physics_override({
|
||||
speed = 1, -- multiplier to default value
|
||||
jump = 1, -- multiplier to default value
|
||||
gravity = 1
|
||||
})
|
||||
|
||||
players_sled[self.driver:get_player_name()] = false
|
||||
self.object:set_detach()
|
||||
--self.driver:hud_remove("sled")
|
||||
self.driver:hud_remove(self.HUD) -- And here is part 2. ~ LazyJ
|
||||
self.driver = nil
|
||||
self.object:remove()
|
||||
|
||||
if not self.driver then
|
||||
return
|
||||
end
|
||||
timer = timer+dtime
|
||||
if timer < 1 then
|
||||
return
|
||||
end
|
||||
timer = 0
|
||||
local player = minetest.get_player_by_name(self.driver)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
if player:get_player_control().sneak
|
||||
or not accelerating_possible(vector.round(self.object:getpos())) then
|
||||
leave_sled(self, player)
|
||||
end
|
||||
end
|
||||
|
||||
@ -177,14 +199,16 @@ minetest.register_craftitem("snow:sled", {
|
||||
stack_max = 1,
|
||||
|
||||
on_use = function(itemstack, placer)
|
||||
local pos = {x=0,y=-1000, z=0}
|
||||
local name = placer:get_player_name()
|
||||
local player_pos = placer:getpos()
|
||||
if not players_sled[name] then
|
||||
if minetest.get_node(player_pos).name == "default:snow" then
|
||||
local sled = minetest.add_entity(pos, "snow:sled")
|
||||
sled:get_luaentity():on_rightclick(placer)
|
||||
if players_sled[placer:get_player_name()] then
|
||||
return
|
||||
end
|
||||
local pos = placer:getpos()
|
||||
if accelerating_possible(vector.round(pos)) then
|
||||
pos.y = pos.y+0.5
|
||||
|
||||
--Get on the sled and remove it from inventory.
|
||||
minetest.add_entity(pos, "snow:sled"):right_click(placer)
|
||||
itemstack:take_item(); return itemstack
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
@ -6,60 +6,148 @@
|
||||
-- Quite a bit of trial-and-error learning here and it boiled down to a
|
||||
-- small handful of code lines making the difference. ~ LazyJ
|
||||
|
||||
local snowball_GRAVITY=9
|
||||
local snowball_VELOCITY=19
|
||||
local creative_mode = minetest.setting_getbool("creative_mode")
|
||||
|
||||
local function get_gravity()
|
||||
local grav = tonumber(minetest.setting_get("movement_gravity")) or 9.81
|
||||
return grav*snow.snowball_gravity
|
||||
end
|
||||
|
||||
local someone_throwing
|
||||
local timer = 0
|
||||
|
||||
--Shoot snowball
|
||||
local snow_shoot_snowball=function (item, player, pointed_thing)
|
||||
local playerpos=player:getpos()
|
||||
local obj=minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, "snow:snowball_entity")
|
||||
local function snow_shoot_snowball(item, player)
|
||||
local addp = {y = 1.625} -- + (math.random()-0.5)/5}
|
||||
local dir = player:get_look_dir()
|
||||
obj:setvelocity({x=dir.x*snowball_VELOCITY, y=dir.y*snowball_VELOCITY, z=dir.z*snowball_VELOCITY})
|
||||
obj:setacceleration({x=dir.x*-3, y=-snowball_GRAVITY, z=dir.z*-3})
|
||||
local dif = 2*math.sqrt(dir.z*dir.z+dir.x*dir.x)
|
||||
addp.x = dir.z/dif -- + (math.random()-0.5)/5
|
||||
addp.z = -dir.x/dif -- + (math.random()-0.5)/5
|
||||
local pos = vector.add(player:getpos(), addp)
|
||||
local obj = minetest.add_entity(pos, "snow:snowball_entity")
|
||||
obj:setvelocity(vector.multiply(dir, snow.snowball_velocity))
|
||||
obj:setacceleration({x=dir.x*-3, y=-get_gravity(), z=dir.z*-3})
|
||||
if creative_mode then
|
||||
if not someone_throwing then
|
||||
someone_throwing = true
|
||||
timer = -0.5
|
||||
end
|
||||
return
|
||||
end
|
||||
item:take_item()
|
||||
return item
|
||||
end
|
||||
|
||||
if creative_mode then
|
||||
local function update_step(dtime)
|
||||
timer = timer+dtime
|
||||
if timer < 0.006 then
|
||||
return
|
||||
end
|
||||
timer = 0
|
||||
|
||||
local active
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
if player:get_player_control().LMB then
|
||||
local item = player:get_wielded_item()
|
||||
local itemname = item:get_name()
|
||||
if itemname == "default:snow" then
|
||||
snow_shoot_snowball(nil, player)
|
||||
active = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- disable the function if noone currently throws them
|
||||
if not active then
|
||||
someone_throwing = false
|
||||
end
|
||||
end
|
||||
|
||||
-- do automatic throwing using a globalstep
|
||||
minetest.register_globalstep(function(dtime)
|
||||
-- only if one holds left click
|
||||
if someone_throwing then
|
||||
update_step(dtime)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
--The snowball Entity
|
||||
snow_snowball_ENTITY={
|
||||
local snow_snowball_ENTITY = {
|
||||
physical = false,
|
||||
timer = 0,
|
||||
textures = {"default_snowball.png"},
|
||||
lastpos={},
|
||||
collisionbox = {0,0,0,0,0,0},
|
||||
collisionbox = {-5/16,-5/16,-5/16, 5/16,5/16,5/16},
|
||||
}
|
||||
|
||||
--Snowball_entity.on_step()--> called when snowball is moving.
|
||||
snow_snowball_ENTITY.on_step = function(self, dtime)
|
||||
self.timer=self.timer+dtime
|
||||
local pos = self.object:getpos()
|
||||
local node = minetest.get_node(pos)
|
||||
function snow_snowball_ENTITY.on_activate(self)
|
||||
self.object:set_properties({textures = {"default_snowball.png^[transform"..math.random(0,7)}})
|
||||
self.object:setacceleration({x=0, y=-get_gravity(), z=0})
|
||||
self.lastpos = self.object:getpos()
|
||||
minetest.after(0.1, function(obj)
|
||||
if not obj then
|
||||
return
|
||||
end
|
||||
local vel = obj:getvelocity()
|
||||
if vel
|
||||
and vel.y ~= 0 then
|
||||
return
|
||||
end
|
||||
minetest.after(0, function(obj)
|
||||
if not obj then
|
||||
return
|
||||
end
|
||||
local vel = obj:getvelocity()
|
||||
if not vel
|
||||
or vel.y == 0 then
|
||||
obj:remove()
|
||||
end
|
||||
end, obj)
|
||||
end, self.object)
|
||||
end
|
||||
|
||||
--Become item when hitting a node.
|
||||
if self.lastpos.x~=nil then --If there is no lastpos for some reason. ~ Splizard
|
||||
-- Check to see what is one node above where the snow is
|
||||
-- going to be placed. ~ LazyJ, 2014_04_08
|
||||
local abovesnowballtarget = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
-- Identify the name of the node that was found above. ~ LazyJ, 2014_04_08
|
||||
local findwhatisabove = minetest.get_node(abovesnowballtarget).name
|
||||
-- If the node above is air, then it's OK to go on to the next step. ~ LazyJ, 2014_04_08
|
||||
if findwhatisabove == "air" then
|
||||
-- If the node where the snow is going is anything except air, then it's OK to put
|
||||
-- the snow on it. ~ Original line of code by Splizard, comment by LazyJ so I can
|
||||
-- keep track of what this code does. ~ LazyJ, 2014_04_07
|
||||
if node.name ~= "air" then
|
||||
snow.place(pos) -- this is the original code, I replaced it with
|
||||
-- minetest.place_node and bumped the y position up by 2 (make the snow drop
|
||||
-- from a node above and pile up). ~ LazyJ, 2014_04_07
|
||||
--minetest.place_node({x=pos.x, y=pos.y+2, z=pos.z}, {name="default:snow"})
|
||||
--Snowball_entity.on_step()--> called when snowball is moving.
|
||||
function snow_snowball_ENTITY.on_step(self, dtime)
|
||||
self.timer = self.timer+dtime
|
||||
if self.timer > 600 then
|
||||
-- 10 minutes are too long for a snowball to fly somewhere
|
||||
self.object:remove()
|
||||
end
|
||||
else -- If findwhatisabove is not equal to "air" then cancel the snowball
|
||||
-- with self.object:remove() ~ LazyJ, 2014_04_08
|
||||
|
||||
if self.physical then
|
||||
local fell = self.object:getvelocity().y == 0
|
||||
if not fell then
|
||||
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
|
||||
return
|
||||
end
|
||||
end
|
||||
snow.place(pos)
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
local pos = vector.round(self.object:getpos())
|
||||
if vector.equals(pos, self.lastpos) then
|
||||
return
|
||||
end
|
||||
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
|
||||
if minetest.get_node(pos).name ~= "air" then
|
||||
self.object:setacceleration({x=0, y=-get_gravity(), z=0})
|
||||
--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})
|
||||
self.object:set_properties({physical = true})
|
||||
self.physical = true
|
||||
return
|
||||
end
|
||||
self.lastpos = vector.new(pos)
|
||||
end
|
||||
|
||||
|
||||
@ -118,16 +206,8 @@ minetest.override_item("default:snow", {
|
||||
drop = {
|
||||
max_items = 2,
|
||||
items = {
|
||||
{
|
||||
-- player will get sapling with 1/20 chance
|
||||
items = {'snow:moss'},
|
||||
rarity = 20,
|
||||
},
|
||||
{
|
||||
-- player will get leaves only if he get no saplings,
|
||||
-- this is because max_items is 1
|
||||
items = {'default:snow'},
|
||||
}
|
||||
{items = {'snow:moss'}, rarity = 20,},
|
||||
{items = {'default:snow'},}
|
||||
}
|
||||
},
|
||||
leveled = 7,
|
||||
@ -142,73 +222,64 @@ minetest.override_item("default:snow", {
|
||||
--Disable placement prediction for snow.
|
||||
node_placement_prediction = "",
|
||||
on_construct = function(pos)
|
||||
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt_with_grass"
|
||||
or minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt" then
|
||||
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, {name="default:dirt_with_snow"})
|
||||
pos.y = pos.y-1
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == "default:dirt_with_grass"
|
||||
or node.name == "default:dirt" then
|
||||
node.name = "default:dirt_with_snow"
|
||||
minetest.set_node(pos, node)
|
||||
end
|
||||
end,
|
||||
--Remove dirt_with_snow and replace with dirt_with_grass.
|
||||
--[[after_destruct = function(pos)
|
||||
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "default:dirt_with_snow" then
|
||||
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, {name="default:dirt_with_grass"})
|
||||
end
|
||||
end,]]
|
||||
--Handle node drops due to node level.
|
||||
on_dig = function(pos, node, digger)
|
||||
local level = minetest.get_node_level(pos)
|
||||
minetest.node_dig(pos, node, digger)
|
||||
if minetest.get_node(pos).name ~= node.name then
|
||||
if digger:get_inventory() then
|
||||
local _, dropped_item
|
||||
local left = digger:get_inventory():add_item("main", "default:snow "..tostring(level/7-1))
|
||||
local inv = digger:get_inventory()
|
||||
if not inv then
|
||||
return
|
||||
end
|
||||
local left = inv:add_item("main", "default:snow "..tostring(level/7-1))
|
||||
if not left:is_empty() then
|
||||
local p = {
|
||||
minetest.add_item({
|
||||
x = pos.x + math.random()/2-0.25,
|
||||
y = pos.y + math.random()/2-0.25,
|
||||
z = pos.z + math.random()/2-0.25,
|
||||
}
|
||||
minetest.add_item(p, left)
|
||||
end
|
||||
}, left)
|
||||
end
|
||||
end
|
||||
end,
|
||||
--Manage snow levels.
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
local node
|
||||
local above
|
||||
local level
|
||||
|
||||
local under = pointed_thing.under
|
||||
local oldnode_under = minetest.get_node_or_nil(under)
|
||||
local above = pointed_thing.above
|
||||
local oldnode_above = minetest.get_node_or_nil(above)
|
||||
|
||||
if not oldnode_under or not oldnode_above then
|
||||
if not oldnode_under
|
||||
or not above then
|
||||
return
|
||||
end
|
||||
|
||||
local olddef_under = ItemStack({name=oldnode_under.name}):get_definition()
|
||||
olddef_under = olddef_under or minetest.nodedef_default
|
||||
local olddef_above = ItemStack({name=oldnode_above.name}):get_definition()
|
||||
olddef_above = olddef_above or minetest.nodedef_default
|
||||
|
||||
-- Place above pointed node
|
||||
local place_to = {x = above.x, y = above.y, z = above.z}
|
||||
|
||||
local place_to
|
||||
-- If node under is buildable_to, place into it instead (eg. snow)
|
||||
if olddef_under.buildable_to then
|
||||
place_to = {x = under.x, y = under.y, z = under.z}
|
||||
place_to = under
|
||||
else
|
||||
-- Place above pointed node
|
||||
place_to = above
|
||||
end
|
||||
|
||||
node = minetest.get_node(place_to)
|
||||
level = minetest.get_node_level(place_to)
|
||||
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)
|
||||
end
|
||||
|
||||
if node.name ~= "default:snow" then
|
||||
if minetest.get_node(place_to).name ~= "default:snow" then
|
||||
local itemstack, placed = minetest.item_place_node(itemstack, placer, pointed_thing)
|
||||
return itemstack, placed
|
||||
end
|
||||
@ -217,8 +288,7 @@ minetest.override_item("default:snow", {
|
||||
|
||||
return itemstack
|
||||
end,
|
||||
on_use = snow_shoot_snowball -- This line is from the 'Snow' mod,
|
||||
-- the reset is default Minetest. ~ LazyJ
|
||||
on_use = snow_shoot_snowball
|
||||
})
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
--Global config and function table.
|
||||
snow = {
|
||||
legacy = true,
|
||||
snowball_gravity = 100/109,
|
||||
snowball_velocity = 19,
|
||||
sleds = true,
|
||||
enable_snowfall = true,
|
||||
lighter_snowfall = false,
|
||||
@ -8,20 +9,21 @@ snow = {
|
||||
smooth_biomes = true,
|
||||
christmas_content = true,
|
||||
smooth_snow = true,
|
||||
min_height = 50,
|
||||
min_height = 3,
|
||||
}
|
||||
|
||||
--Config documentation.
|
||||
local doc = {
|
||||
legacy = "Whether you are running a legacy minetest version (auto-detected).",
|
||||
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.",
|
||||
smooth_biomes = "Enables smooth transition of biomes",
|
||||
christmas_content = "Disable this to remove christmas saplings from being found.",
|
||||
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.",
|
||||
min_height = "The minumum height a snow biome will generate.",
|
||||
christmas_content = "Disable this to remove christmas saplings from being found.",
|
||||
min_height = "The minumum height a snow biome will generate (mgv7)",
|
||||
}
|
||||
|
||||
--Manage config.
|
||||
@ -64,7 +66,9 @@ local function loadConfig(path)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_shutdown(function() saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc) 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
|
||||
@ -79,7 +83,9 @@ end
|
||||
|
||||
for i,v in pairs(snow) do
|
||||
local t = type(v)
|
||||
if t == "string" or t == "number" or t == "boolean" then
|
||||
if t == "string"
|
||||
or t == "number"
|
||||
or t == "boolean" then
|
||||
local v = minetest.setting_get("snow_"..i)
|
||||
if v ~= nil then
|
||||
if v == "true" then v = true end
|
||||
@ -90,18 +96,6 @@ for i,v in pairs(snow) do
|
||||
end
|
||||
end
|
||||
|
||||
--AUTO DETECT and/or OVERIDEN values--
|
||||
|
||||
--legacy--
|
||||
--Detect if we are running the latest minetest.
|
||||
if minetest.register_on_mapgen_init then
|
||||
snow.legacy = false
|
||||
else
|
||||
snow.legacy = true
|
||||
end
|
||||
if config and snow.legacy ~= config.legacy then
|
||||
saveConfig(minetest.get_modpath("snow").."/config.txt", snow, doc)
|
||||
end
|
||||
|
||||
--MENU
|
||||
|
||||
@ -110,7 +104,8 @@ local get_formspec = function()
|
||||
local formspec = "label[0,-0.3;Settings:]"
|
||||
for i,v in pairs(snow) do
|
||||
local t = type(v)
|
||||
if t == "string" or t == "number" then
|
||||
if t == "string"
|
||||
or t == "number" then
|
||||
p = p + 1.5
|
||||
formspec = formspec.."field[0.3,"..p..";2,1;snow:"..i..";"..i..";"..v.."]"
|
||||
elseif t == "boolean" then
|
||||
@ -124,20 +119,25 @@ local get_formspec = function()
|
||||
end
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if formname == "snow:menu" then
|
||||
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
|
||||
if fields["snow:"..i] then
|
||||
local field = fields["snow:"..i]
|
||||
if field then
|
||||
if t == "string" then
|
||||
snow[i] = fields["snow:"..i]
|
||||
snow[i] = field
|
||||
end
|
||||
if t == "number" then
|
||||
snow[i] = tonumber(fields["snow:"..i])
|
||||
snow[i] = tonumber(field)
|
||||
end
|
||||
if t == "boolean" then
|
||||
if fields["snow:"..i] == "true" then snow[i] = true end
|
||||
if fields["snow:"..i] == "false" then snow[i] = false end
|
||||
if field == "true" then
|
||||
snow[i] = true
|
||||
elseif field == "false" then
|
||||
snow[i] = false
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -149,7 +149,8 @@ end)
|
||||
minetest.register_chatcommand("snow", {
|
||||
description = "Show a menu for various actions",
|
||||
privs = {server=true},
|
||||
func = function(name, param)
|
||||
func = function(name)
|
||||
minetest.chat_send_player(name, "Showing snow menu…")
|
||||
minetest.show_formspec(name, "snow:menu", get_formspec())
|
||||
end,
|
||||
})
|
||||
|
Binary file not shown.
BIN
mods/snow/textures/default_snowball.png
Normal file
BIN
mods/snow/textures/default_snowball.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 211 B |
@ -1,67 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="16"
|
||||
height="16"
|
||||
id="svg2"
|
||||
version="1.1"
|
||||
inkscape:version="0.48.4 r9939"
|
||||
sodipodi:docname="inkscape_default_ice.svg">
|
||||
<defs
|
||||
id="defs4" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="45.4375"
|
||||
inkscape:cx="6.8335626"
|
||||
inkscape:cy="8"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
inkscape:showpageshadow="false"
|
||||
inkscape:window-width="1328"
|
||||
inkscape:window-height="895"
|
||||
inkscape:window-x="197"
|
||||
inkscape:window-y="70"
|
||||
inkscape:window-maximized="0" />
|
||||
<metadata
|
||||
id="metadata7">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-1036.3622)">
|
||||
<rect
|
||||
style="fill:#91d2ff;fill-rule:evenodd;stroke:none;fill-opacity:1;opacity:0.90000000000000002"
|
||||
id="rect2985"
|
||||
width="16"
|
||||
height="16"
|
||||
x="0"
|
||||
y="1036.3622"
|
||||
inkscape:export-xdpi="90"
|
||||
inkscape:export-ydpi="90"
|
||||
inkscape:export-filename="/home/trickpaint/Minetest/Minetest_game_stuff/049_modtest/worlds/developing_snow_overhaul/worldmods/snow_developing/snow/textures/default_ice.png" />
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
Before Width: | Height: | Size: 206 B |
Binary file not shown.
Before Width: | Height: | Size: 189 B |
Binary file not shown.
Before Width: | Height: | Size: 350 B |
Binary file not shown.
Loading…
Reference in New Issue
Block a user