add some tweaks to meet vanerika subgame needs
3
.gitignore
vendored
@ -1 +1,4 @@
|
|||||||
*~
|
*~
|
||||||
|
.settings/*
|
||||||
|
.project
|
||||||
|
.buildpath
|
7
README
@ -1,7 +0,0 @@
|
|||||||
Weather mod for Minetest (http://minetest.net/)
|
|
||||||
|
|
||||||
License:
|
|
||||||
- Code: LGPL
|
|
||||||
- Textures:
|
|
||||||
- Snow cover: WTFPL
|
|
||||||
- Rain / Snow: CC-BY-SA 3.0, credit goes to TeddyDesTodes, from his weather branch at https://github.com/TeddyDesTodes/minetest/tree/weather
|
|
24
README.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
Weather mod for Minetest (http://minetest.net/)
|
||||||
|
=======================
|
||||||
|
|
||||||
|
License of source code:
|
||||||
|
-----------------------
|
||||||
|
LGPL
|
||||||
|
|
||||||
|
Authors of media files:
|
||||||
|
-----------------------
|
||||||
|
|
||||||
|
TeddyDesTodes:
|
||||||
|
Snowflakes licensed under CC-BY-SA 3.0 by from weather branch at https://github.com/TeddyDesTodes/minetest/tree/weather
|
||||||
|
|
||||||
|
* `weather_snowflake1.png` - CC-BY-SA 3.0
|
||||||
|
* `weather_snowflake2.png` - CC-BY-SA 3.0
|
||||||
|
|
||||||
|
xeranas:
|
||||||
|
|
||||||
|
* `weather_raindrop.png` - CC-0
|
||||||
|
|
||||||
|
inchadney (http://freesound.org/people/inchadney/):
|
||||||
|
|
||||||
|
* `weather_rain.ogg` - CC-BY-SA 3.0 (cut from http://freesound.org/people/inchadney/sounds/58835/)
|
||||||
|
|
Before Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 2.1 KiB |
@ -9,7 +9,7 @@ minetest.register_chatcommand("setweather", {
|
|||||||
description = "Set weather to rain, snow or none", -- full description
|
description = "Set weather to rain, snow or none", -- full description
|
||||||
privs = {weather = true},
|
privs = {weather = true},
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
weather = param
|
weather.state = param
|
||||||
save_weather()
|
save_weather()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -1,17 +1,32 @@
|
|||||||
-- Weather:
|
-- Weather:
|
||||||
-- * rain
|
-- * rain
|
||||||
-- * snow
|
-- * snow
|
||||||
-- * wind (not implemented)
|
|
||||||
|
|
||||||
assert(minetest.add_particlespawner, "I told you to run the latest GitHub!")
|
assert(minetest.add_particlespawner, "Your Minetest version is incompatible with this mod")
|
||||||
|
|
||||||
addvectors = function (v1, v2)
|
weather = {
|
||||||
return {x=v1.x+v2.x, y=v1.y+v2.y, z=v1.z+v2.z}
|
state = "none",
|
||||||
|
players = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
weather.remove_weather = function (player_name)
|
||||||
|
local player_info = weather.players[player_name]
|
||||||
|
minetest.sound_stop(player_info.sound_handler)
|
||||||
|
local p = minetest.get_player_by_name(player_name)
|
||||||
|
if p ~= nil then
|
||||||
|
p:set_sky(player_info.sky_box[1], player_info.sky_box[2], player_info.sky_box[3])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
save_weather = function ()
|
save_weather = function ()
|
||||||
|
for player_name, player_info in pairs(weather.players) do
|
||||||
|
if player_info ~= nil then
|
||||||
|
weather.remove_weather(player_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
weather.players = {}
|
||||||
local file = io.open(minetest.get_worldpath().."/weather", "w+")
|
local file = io.open(minetest.get_worldpath().."/weather", "w+")
|
||||||
file:write(weather)
|
file:write(weather.state)
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -23,22 +38,21 @@ read_weather = function ()
|
|||||||
return readweather
|
return readweather
|
||||||
end
|
end
|
||||||
|
|
||||||
weather = read_weather()
|
weather.state = read_weather()
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
if weather == "rain"
|
if weather.state == "rain" or weather.state == "snow" then
|
||||||
or weather == "snow" then
|
|
||||||
if math.random(1, 10000) == 1 then
|
if math.random(1, 10000) == 1 then
|
||||||
weather = "none"
|
weather.state = "none"
|
||||||
save_weather()
|
save_weather()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local ran = math.random(1, 5000000)
|
if math.random(1, 50000) == 1 then
|
||||||
if ran == 1 then
|
weather.state = "rain"
|
||||||
weather = "rain"
|
|
||||||
save_weather()
|
save_weather()
|
||||||
elseif ran == 2 then
|
end
|
||||||
weather = "snow"
|
if math.random(1, 50000) == 2 then
|
||||||
|
weather.state = "snow"
|
||||||
save_weather()
|
save_weather()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
152
weather/rain.lua
@ -1,35 +1,133 @@
|
|||||||
-- Rain
|
-- Rain
|
||||||
local spawnerdef = {
|
|
||||||
amount = 25,
|
function getRandomRange(offset, range)
|
||||||
time = 0.5,
|
if range < 0 then
|
||||||
minexptime = 0.8,
|
return offset + math.random() + math.random(range, 0)
|
||||||
maxexptime = 0.8,
|
elseif range > 0 then
|
||||||
minsize = 0.8,
|
return offset + math.random() + math.random(0, range)
|
||||||
maxsize = 1.2,
|
else
|
||||||
collisiondetection = true,
|
return 0
|
||||||
vertical = true,
|
|
||||||
texture = "weather_rain.png",
|
|
||||||
}
|
|
||||||
minetest.register_globalstep(function(dtime)
|
|
||||||
if weather ~= "rain" then
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
rain = {}
|
||||||
|
|
||||||
|
rain.add_short_range_particlespawner = function (player)
|
||||||
|
local ppos = player:getpos()
|
||||||
|
local short_range_pos_min = {}
|
||||||
|
short_range_pos_min.x = getRandomRange(ppos.x, -3)
|
||||||
|
short_range_pos_min.y = ppos.y + 3
|
||||||
|
short_range_pos_min.z = getRandomRange(ppos.z, -3)
|
||||||
|
|
||||||
|
if minetest.env:get_node_light(short_range_pos_min, 0.5) ~= 15 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local short_range_pos_max = {}
|
||||||
|
short_range_pos_max.x = getRandomRange(ppos.x, 3)
|
||||||
|
short_range_pos_max.y = ppos.y + 3
|
||||||
|
short_range_pos_max.z = getRandomRange(ppos.z, 3)
|
||||||
|
|
||||||
|
if minetest.env:get_node_light(short_range_pos_max, 0.5) ~= 15 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.add_particlespawner({
|
||||||
|
amount=15,
|
||||||
|
time=0.3,
|
||||||
|
minpos=short_range_pos_min,
|
||||||
|
maxpos=short_range_pos_max,
|
||||||
|
minvel={x=0, y=-20, z=0},
|
||||||
|
maxvel={x=0.2, y=-20, z=0.2},
|
||||||
|
minacc={x=0, y=-10, z=0},
|
||||||
|
maxacc={x=0.2, y=-10, z=0.2},
|
||||||
|
minexptime=0.2,
|
||||||
|
maxexptime=0.3,
|
||||||
|
minsize=0.5,
|
||||||
|
maxsize=2,
|
||||||
|
collisiondetection=true,
|
||||||
|
vertical=true,
|
||||||
|
texture="weather_raindrop.png",
|
||||||
|
player=player:get_player_name()})
|
||||||
|
|
||||||
|
return true
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
rain.add_long_range_particlespawner = function (player)
|
||||||
|
local ppos = player:getpos()
|
||||||
|
local long_range_pos_min = {}
|
||||||
|
long_range_pos_min.x = getRandomRange(ppos.x, -20)
|
||||||
|
long_range_pos_min.y = ppos.y + 10
|
||||||
|
long_range_pos_min.z = getRandomRange(ppos.z, -20)
|
||||||
|
|
||||||
|
if minetest.env:get_node_light(long_range_pos_min, 0.5) ~= 15 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local long_range_pos_max = {}
|
||||||
|
long_range_pos_max.x = getRandomRange(ppos.x, 20)
|
||||||
|
long_range_pos_max.y = ppos.y + 10
|
||||||
|
long_range_pos_max.z = getRandomRange(ppos.z, 20)
|
||||||
|
|
||||||
|
if minetest.env:get_node_light(long_range_pos_max, 0.5) ~= 15 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.add_particlespawner({
|
||||||
|
amount=40,
|
||||||
|
time=0.5,
|
||||||
|
minpos=long_range_pos_min,
|
||||||
|
maxpos=long_range_pos_max,
|
||||||
|
minvel={x=0, y=-20, z=0},
|
||||||
|
maxvel={x=0.2, y=-20, z=0.2},
|
||||||
|
minacc={x=0, y=-20, z=0},
|
||||||
|
maxacc={x=0.2, y=-20, z=0.2},
|
||||||
|
minexptime=0.2,
|
||||||
|
maxexptime=0.5,
|
||||||
|
minsize=0.5,
|
||||||
|
maxsize=2,
|
||||||
|
collisiondetection=true,
|
||||||
|
vertical=true,
|
||||||
|
texture="weather_raindrop.png",
|
||||||
|
player=player:get_player_name()})
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
if weather.state ~= "rain" then return end
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
local ppos = player:getpos()
|
local ppos = player:getpos()
|
||||||
|
|
||||||
-- Make sure player is not in a cave/house...
|
local rain_nearby = rain.add_short_range_particlespawner(player)
|
||||||
--if minetest.get_node_light(ppos, 0.5) ~= 15 then return end
|
local rain_distant = rain.add_long_range_particlespawner(player)
|
||||||
|
|
||||||
spawnerdef.minpos = addvectors(ppos, {x=-9, y=7, z=-9})
|
print(minetest.get_timeofday())
|
||||||
spawnerdef.maxpos = addvectors(ppos, {x= 9, y=7, z= 9})
|
if rain_nearby or rain_distant then
|
||||||
|
if weather.players[player:get_player_name()] == nil then
|
||||||
spawnerdef.minvel = {x=0, y= -40, z=0}
|
local player_name = player:get_player_name()
|
||||||
spawnerdef.maxvel = spawnerdef.minvel
|
local player_info = {}
|
||||||
spawnerdef.minacc = {x=0, y= 0, z=0}
|
player_info.sound_handler = minetest.sound_play("weather_rain", {
|
||||||
spawnerdef.maxacc = spawnerdef.minacc
|
object = player,
|
||||||
|
max_hear_distance = 2,
|
||||||
spawnerdef.playername = player:get_player_name()
|
loop = true,
|
||||||
|
})
|
||||||
minetest.add_particlespawner(spawnerdef)
|
player_info.sky_box = {player:get_sky()}
|
||||||
|
if (minetest.get_timeofday() < 0.8) then
|
||||||
|
player:set_sky({r=65, g=80, b=100}, "plain", nil)
|
||||||
|
else
|
||||||
|
player:set_sky({r=10, g=10, b=15}, "plain", nil)
|
||||||
|
end
|
||||||
|
weather.players[player_name] = player_info
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
106
weather/snow.lua
@ -1,74 +1,54 @@
|
|||||||
-- Snow
|
-- Snow
|
||||||
local spawnerdef = {
|
|
||||||
amount = 8,
|
|
||||||
time = 0.5,
|
|
||||||
minexptime = 3,
|
|
||||||
maxexptime = 15,
|
|
||||||
minsize = 0.8,
|
|
||||||
maxsize = 1.2,
|
|
||||||
collisiondetection = true,
|
|
||||||
}
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
if weather ~= "snow" then
|
if weather.state ~= "snow" then return end
|
||||||
return
|
|
||||||
end
|
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
local ppos = player:getpos()
|
local ppos = player:getpos()
|
||||||
|
|
||||||
-- Make sure player is not in a cave/house...
|
add_long_range_particlespawner(player)
|
||||||
--if minetest.get_node_light(ppos, 0.5) ~= 15 then return end
|
|
||||||
|
|
||||||
spawnerdef.minpos = addvectors(ppos, {x=-9, y=7, z=-9})
|
|
||||||
spawnerdef.maxpos = addvectors(ppos, {x= 9, y=7, z= 9})
|
|
||||||
|
|
||||||
spawnerdef.minvel = {x=0, y= -1, z=0}
|
|
||||||
spawnerdef.maxvel = spawnerdef.minvel
|
|
||||||
spawnerdef.minacc = {x=0, y= 0, z=0}
|
|
||||||
spawnerdef.maxacc = spawnerdef.minacc
|
|
||||||
|
|
||||||
spawnerdef.playername = player:get_player_name()
|
|
||||||
|
|
||||||
for _,i in ipairs({"", "2"}) do
|
|
||||||
spawnerdef.texture = "weather_snow"..i..".png"
|
|
||||||
minetest.add_particlespawner(spawnerdef)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--[[local snow_box =
|
function add_long_range_particlespawner(player)
|
||||||
{
|
local ppos = player:getpos()
|
||||||
type = "fixed",
|
local long_range_pos_min = {}
|
||||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}
|
long_range_pos_min.x = getRandomRange(ppos.x, -20)
|
||||||
}
|
long_range_pos_min.y = ppos.y + 10
|
||||||
|
long_range_pos_min.z = getRandomRange(ppos.z, -20)
|
||||||
|
|
||||||
-- Snow cover
|
if minetest.env:get_node_light(long_range_pos_min, 0.5) ~= 15 then return end
|
||||||
minetest.register_node("weather:snow_cover", {
|
|
||||||
tiles = {"weather_snow_cover.png"},
|
|
||||||
drawtype = "nodebox",
|
|
||||||
paramtype = "light",
|
|
||||||
node_box = snow_box,
|
|
||||||
selection_box = snow_box,
|
|
||||||
groups = {not_in_creative_inventory = 1, crumbly = 3, attached_node = 1},
|
|
||||||
drop = {}
|
|
||||||
})
|
|
||||||
|
|
||||||
--[ Enable this section if you have a very fast PC
|
local long_range_pos_max = {}
|
||||||
minetest.register_abm({
|
long_range_pos_max.x = getRandomRange(ppos.x, 20)
|
||||||
nodenames = {"group:crumbly", "group:snappy", "group:cracky", "group:choppy"},
|
long_range_pos_max.y = ppos.y + 10
|
||||||
neighbors = {"default:air"},
|
long_range_pos_max.z = getRandomRange(ppos.z, 20)
|
||||||
interval = 10.0,
|
|
||||||
chance = 80,
|
if minetest.env:get_node_light(long_range_pos_max, 0.5) ~= 15 then return end
|
||||||
action = function (pos, node, active_object_count, active_object_count_wider)
|
|
||||||
if weather == "snow" then
|
local random_texture = nil
|
||||||
if minetest.registered_nodes[node.name].drawtype == "normal"
|
if math.random() > 0.5 then
|
||||||
or minetest.registered_nodes[node.name].drawtype == "allfaces_optional" then
|
random_texture = "weather_snowflake1.png"
|
||||||
local np = addvectors(pos, {x=0, y=1, z=0})
|
else
|
||||||
if minetest.get_node_light(np, 0.5) == 15
|
random_texture = "weather_snowflake2.png"
|
||||||
and minetest.get_node(np).name == "air" then
|
|
||||||
minetest.add_node(np, {name="weather:snow_cover"})
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
minetest.add_particlespawner({
|
||||||
end
|
amount=30,
|
||||||
})
|
time=1.5,
|
||||||
]]
|
minpos=long_range_pos_min,
|
||||||
|
maxpos=long_range_pos_max,
|
||||||
|
minvel={x=-1, y=-2, z=-1},
|
||||||
|
maxvel={x=1, y=-7, z=1},
|
||||||
|
minacc={x=-1, y=-2, z=-1},
|
||||||
|
maxacc={x=1, y=-0.3, z=1},
|
||||||
|
minexptime=0.5,
|
||||||
|
maxexptime=1.5,
|
||||||
|
minsize=0.5,
|
||||||
|
maxsize=3,
|
||||||
|
collisiondetection=true,
|
||||||
|
vertical=false,
|
||||||
|
texture=random_texture,
|
||||||
|
player=player:get_player_name()})
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
BIN
weather/sounds/weather_rain.ogg
Normal file
Before Width: | Height: | Size: 101 B |
BIN
weather/textures/weather_raindrop.png
Normal file
After Width: | Height: | Size: 180 B |
Before Width: | Height: | Size: 106 B |
Before Width: | Height: | Size: 109 B |
BIN
weather/textures/weather_snowflake1.png
Normal file
After Width: | Height: | Size: 192 B |
BIN
weather/textures/weather_snowflake2.png
Normal file
After Width: | Height: | Size: 195 B |
Before Width: | Height: | Size: 647 B |