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
|
||||
privs = {weather = true},
|
||||
func = function(name, param)
|
||||
weather = param
|
||||
weather.state = param
|
||||
save_weather()
|
||||
end
|
||||
})
|
||||
|
@ -1,47 +1,61 @@
|
||||
-- Weather:
|
||||
-- * rain
|
||||
-- * 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)
|
||||
return {x=v1.x+v2.x, y=v1.y+v2.y, z=v1.z+v2.z}
|
||||
weather = {
|
||||
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
|
||||
|
||||
save_weather = function ()
|
||||
local file = io.open(minetest.get_worldpath().."/weather", "w+")
|
||||
file:write(weather)
|
||||
file:close()
|
||||
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+")
|
||||
file:write(weather.state)
|
||||
file:close()
|
||||
end
|
||||
|
||||
read_weather = function ()
|
||||
local file = io.open(minetest.get_worldpath().."/weather", "r")
|
||||
if not file then return end
|
||||
local readweather = file:read()
|
||||
file:close()
|
||||
return readweather
|
||||
local file = io.open(minetest.get_worldpath().."/weather", "r")
|
||||
if not file then return end
|
||||
local readweather = file:read()
|
||||
file:close()
|
||||
return readweather
|
||||
end
|
||||
|
||||
weather = read_weather()
|
||||
weather.state = read_weather()
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if weather == "rain"
|
||||
or weather == "snow" then
|
||||
if math.random(1, 10000) == 1 then
|
||||
weather = "none"
|
||||
save_weather()
|
||||
end
|
||||
else
|
||||
local ran = math.random(1, 5000000)
|
||||
if ran == 1 then
|
||||
weather = "rain"
|
||||
save_weather()
|
||||
elseif ran == 2 then
|
||||
weather = "snow"
|
||||
save_weather()
|
||||
end
|
||||
end
|
||||
if weather.state == "rain" or weather.state == "snow" then
|
||||
if math.random(1, 10000) == 1 then
|
||||
weather.state = "none"
|
||||
save_weather()
|
||||
end
|
||||
else
|
||||
if math.random(1, 50000) == 1 then
|
||||
weather.state = "rain"
|
||||
save_weather()
|
||||
end
|
||||
if math.random(1, 50000) == 2 then
|
||||
weather.state = "snow"
|
||||
save_weather()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
dofile(minetest.get_modpath("weather").."/rain.lua")
|
||||
|
154
weather/rain.lua
@ -1,35 +1,133 @@
|
||||
-- Rain
|
||||
local spawnerdef = {
|
||||
amount = 25,
|
||||
time = 0.5,
|
||||
minexptime = 0.8,
|
||||
maxexptime = 0.8,
|
||||
minsize = 0.8,
|
||||
maxsize = 1.2,
|
||||
collisiondetection = true,
|
||||
vertical = true,
|
||||
texture = "weather_rain.png",
|
||||
}
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if weather ~= "rain" then
|
||||
return
|
||||
end
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local ppos = player:getpos()
|
||||
|
||||
-- Make sure player is not in a cave/house...
|
||||
--if minetest.get_node_light(ppos, 0.5) ~= 15 then return end
|
||||
function getRandomRange(offset, range)
|
||||
if range < 0 then
|
||||
return offset + math.random() + math.random(range, 0)
|
||||
elseif range > 0 then
|
||||
return offset + math.random() + math.random(0, range)
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
spawnerdef.minpos = addvectors(ppos, {x=-9, y=7, z=-9})
|
||||
spawnerdef.maxpos = addvectors(ppos, {x= 9, y=7, z= 9})
|
||||
rain = {}
|
||||
|
||||
spawnerdef.minvel = {x=0, y= -40, z=0}
|
||||
spawnerdef.maxvel = spawnerdef.minvel
|
||||
spawnerdef.minacc = {x=0, y= 0, z=0}
|
||||
spawnerdef.maxacc = spawnerdef.minacc
|
||||
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)
|
||||
|
||||
spawnerdef.playername = player:get_player_name()
|
||||
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)
|
||||
|
||||
minetest.add_particlespawner(spawnerdef)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if weather.state ~= "rain" then return end
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local ppos = player:getpos()
|
||||
|
||||
local rain_nearby = rain.add_short_range_particlespawner(player)
|
||||
local rain_distant = rain.add_long_range_particlespawner(player)
|
||||
|
||||
print(minetest.get_timeofday())
|
||||
if rain_nearby or rain_distant then
|
||||
if weather.players[player:get_player_name()] == nil then
|
||||
local player_name = player:get_player_name()
|
||||
local player_info = {}
|
||||
player_info.sound_handler = minetest.sound_play("weather_rain", {
|
||||
object = player,
|
||||
max_hear_distance = 2,
|
||||
loop = true,
|
||||
})
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
114
weather/snow.lua
@ -1,74 +1,54 @@
|
||||
-- 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)
|
||||
if weather ~= "snow" then
|
||||
return
|
||||
end
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local ppos = player:getpos()
|
||||
if weather.state ~= "snow" then return end
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local ppos = player:getpos()
|
||||
|
||||
-- Make sure player is not in a cave/house...
|
||||
--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
|
||||
add_long_range_particlespawner(player)
|
||||
end
|
||||
end)
|
||||
|
||||
--[[local snow_box =
|
||||
{
|
||||
type = "fixed",
|
||||
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4, 0.5}
|
||||
}
|
||||
function add_long_range_particlespawner(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 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 end
|
||||
|
||||
local random_texture = nil
|
||||
if math.random() > 0.5 then
|
||||
random_texture = "weather_snowflake1.png"
|
||||
else
|
||||
random_texture = "weather_snowflake2.png"
|
||||
end
|
||||
|
||||
minetest.add_particlespawner({
|
||||
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
|
||||
|
||||
-- Snow cover
|
||||
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
|
||||
minetest.register_abm({
|
||||
nodenames = {"group:crumbly", "group:snappy", "group:cracky", "group:choppy"},
|
||||
neighbors = {"default:air"},
|
||||
interval = 10.0,
|
||||
chance = 80,
|
||||
action = function (pos, node, active_object_count, active_object_count_wider)
|
||||
if weather == "snow" then
|
||||
if minetest.registered_nodes[node.name].drawtype == "normal"
|
||||
or minetest.registered_nodes[node.name].drawtype == "allfaces_optional" then
|
||||
local np = addvectors(pos, {x=0, y=1, z=0})
|
||||
if minetest.get_node_light(np, 0.5) == 15
|
||||
and minetest.get_node(np).name == "air" then
|
||||
minetest.add_node(np, {name="weather:snow_cover"})
|
||||
end
|
||||
end
|
||||
end
|
||||
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 |