1
0
mirror of https://github.com/Splizard/minetest-mod-snow.git synced 2024-12-28 07:30:17 +01:00

add infomessage to the snow chatcommand, add a bit light to the lit star texture and allow en- and disabling snowfall ingame

This commit is contained in:
HybridDog 2015-05-26 20:37:57 +02:00
parent c0b40b5cbf
commit 062a451bc7
5 changed files with 146 additions and 127 deletions

View File

@ -123,55 +123,56 @@ end
-- Checks if the snow level is even at any given pos.
-- Smooth Snow
if snow.smooth_snow then
snow.is_uneven = function(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
local p = {x=pos.x+x, y=pos.y, z=pos.z+z}
local node = get_node(p)
local function is_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
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 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
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"
and bnode.name ~= "default:snow" then
p.y = p.y-1
local bnode = get_node(p)
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
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"
and bnode.name ~= "default:snow" then
p.y = p.y-1
snow.place(p)
return true
end
snow.place(p)
return true
end
end
if found then
local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz}
if snow.is_uneven(p) ~= true then
minetest.add_node_level(p, 7)
end
return true
end
end
else
snow.is_uneven = function()
if found then
local p = {x=pos.x+foundx, y=pos.y, z=pos.z+foundz}
if snow.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

View File

@ -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})
local vel = {x=0, y= -1, z=-1}
local acc = {x=0, y= 0, z=0}
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}
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
if math.random(1,5) == 4 then
snow_fall(randpos(sminp, smaxp), player, true)
end
animate = true
end
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
minetest.register_globalstep(function(dtime)
if snow.enable_snowfall then
calc_snowfall()
end
end)

View File

@ -53,8 +53,7 @@ than I originally planned. :p ~ LazyJ
--
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
@ -77,7 +76,8 @@ local sled = {
local players_sled = {}
function sled:on_rightclick(clicker)
if (not self.driver) and snow.sleds then
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})
@ -110,7 +110,7 @@ function sled:on_rightclick(clicker)
direction = 0,
})
-- End part 1
end
end
end
function sled:on_activate(staticdata, dtime_s)
@ -126,13 +126,20 @@ end
function sled:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
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
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer+dtime
if timer < 1 then
return
end
timer = 0
for _, player in pairs(minetest.get_connected_players()) do
if players_sled[player:get_player_name()] then
default.player_set_animation(player, "sit", 0)
@ -140,28 +147,37 @@ minetest.register_globalstep(function(dtime)
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
})
if not self.driver then
return
end
timer = timer+dtime
if timer < 1 then
return
end
timer = 0
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()
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()
end
end
end
@ -176,15 +192,13 @@ minetest.register_craftitem("snow:sled", {
liquids_pointable = true,
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)
end
on_use = function(itemstack, placer)
if players_sled[placer:get_player_name()] then
return
end
if minetest.get_node(placer:getpos()).name == "default:snow" then
local sled = minetest.add_entity({x=0,y=-1000, z=0}, "snow:sled")
sled:get_luaentity():on_rightclick(placer)
end
end,
})

View File

@ -159,6 +159,7 @@ 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,
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 302 B

After

Width:  |  Height:  |  Size: 319 B