diff --git a/.buildpath b/.buildpath index a187add..c6a5b87 100644 --- a/.buildpath +++ b/.buildpath @@ -1,3 +1,4 @@ + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5e98cc7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: generic -sudo: false -addons: - apt: - packages: - - luarocks -before_install: - - luarocks install --local luacheck -env: - - CONFIG=.luacheckrc - - CONFIG=.luacheck_tidy -matrix: - exclude: - - name: "health check" - env: CONFIG=.luacheckrc - allow_failures: - - name: "beauty check" - env: CONFIG=.luacheck_tidy -script: -- $HOME/.luarocks/bin/luacheck --config $CONFIG . -notifications: - email: - on_failure: change \ No newline at end of file diff --git a/weather/api.lua b/weather/api.lua index 4af3c01..f95bc78 100644 --- a/weather/api.lua +++ b/weather/api.lua @@ -38,19 +38,21 @@ end local default_downfall = { --minimum starting position - min_pos = {x=-9, y=10, z=-9}, + min_pos = {x=-15, y=10, z=-15}, --maximum starting position - max_pos = {x=9, y=10, z=9}, + max_pos = {x=15, y=10, z=15}, --y falling speed falling_speed = 10, --number of textures spawned - amount = 10, + amount = 15, --the texture size size = 25, --whether lightning schould be enabled enable_lightning=false, --whether to damage the player - damage_player=false + damage_player=false, + --how much wind is needed to trigger the weather + min_wind = 0, } local default_damage = { @@ -73,7 +75,7 @@ function weather_mod.register_downfall(id,def) end set_defaults(ndef,default_downfall) --when to delete the particles - if not ndef.exptime then + if not ndef.exptime then ndef.exptime = ndef.max_pos.y / (math.sqrt(ndef.falling_acceleration) + ndef.falling_speed) end if ndef.damage_player then @@ -83,20 +85,23 @@ function weather_mod.register_downfall(id,def) weather_mod.registered_downfalls[name]=ndef end +function weather_mod.unregister_downfall(id) + weather_mod.registered_downfalls[id] = nil +end + if minetest.get_modpath("lightning") then --same as lightning.auto = false rawset(lightning,"auto",false) end -function weather_mod.handle_lightning() - if not minetest.get_modpath("lightning") then return end - local current_downfall = weather_mod.registered_downfalls[weather.type] - if not current_downfall then return end - rawset(lightning,"auto",current_downfall.enable_lightning) - if current_downfall.enable_lightning and math.random(1,2) == 1 then - local time = math.floor(math.random(lightning.interval_low/2,lightning.interval_low)) - minetest.after(time, lightning.strike) - end +function weather_mod.handle_lightning(current_weather) + if not minetest.get_modpath("lightning") then return end + if not current_weather then return end + rawset(lightning,"auto",current_weather.enable_lightning) + if current_weather.enable_lightning and math.random(1,2) == 1 then + local time = math.floor(math.random(lightning.interval_low/2,lightning.interval_low)) + minetest.after(time, lightning.strike) + end end local do_raycasts = minetest.is_yes(minetest.settings:get_bool('raycast_hitcheck')) @@ -132,52 +137,57 @@ local function handle_damage(damage,player, downfall_origin) end minetest.register_globalstep(function() - if weather.type=="none" then - for id,_ in pairs(weather_mod.registered_downfalls) do - if math.random(1, 50000) == 1 then - weather.wind = {} - weather.wind.x = math.random(0,10) - weather.wind.y = 0 - weather.wind.z = math.random(0,10) - weather.type = id - weather_mod.handle_lightning() - end - end - else - if math.random(1, 10000) == 1 then - weather.type = "none" - if minetest.get_modpath("lightning") then - rawset(lightning,"auto",false) - end - end - end - local current_downfall = weather_mod.registered_downfalls[weather.type] - if current_downfall==nil then return end - for _, player in ipairs(minetest.get_connected_players()) do - local ppos = player:getpos() + if math.random(1, 10000) == 1 then + weather.type = "none" + if minetest.get_modpath("lightning") then + rawset(lightning,"auto",false) + end + else + for id,w in pairs(weather_mod.registered_downfalls) do + if math.random(1, 50000) == 1 then + weather.wind = {} + weather.wind.x = math.random(0,10) + weather.wind.y = 0 + weather.wind.z = math.random(0,10) + if vector.length(weather.wind) >= w.min_wind then + weather.type = id + weather_mod.handle_lightning(w) + break + end + end + end + end - if ppos.y > 120 then return end + local current_downfall = weather_mod.registered_downfalls[weather.type] + if current_downfall==nil then return end + for _, player in ipairs(minetest.get_connected_players()) do + local ppos = player:getpos() - local wind_pos = vector.multiply(weather.wind,-1) + if ppos.y > 120 then return end - local minp = vector.add(vector.add(ppos, current_downfall.min_pos),wind_pos) - local maxp = vector.add(vector.add(ppos, current_downfall.max_pos),wind_pos) + local wind_pos = vector.multiply(weather.wind,-1) - local vel = {x=weather.wind.x,y=-current_downfall.falling_speed,z=weather.wind.z} - local acc = {x=0, y=0, z=0} + local minp = vector.add(vector.add(ppos, current_downfall.min_pos),wind_pos) + local maxp = vector.add(vector.add(ppos, current_downfall.max_pos),wind_pos) - local exp = current_downfall.exptime + local vel = {x=weather.wind.x,y=-current_downfall.falling_speed,z=weather.wind.z} + local acc = {x=0, y=0, z=0} - minetest.add_particlespawner({amount=current_downfall.amount, time=0.5, - minpos=minp, maxpos=maxp, - minvel=vel, maxvel=vel, - minacc=acc, maxacc=acc, - minexptime=exp, maxexptime=exp, - minsize=current_downfall.size, maxsize=current_downfall.size, - collisiondetection=true, collision_removal=true, - vertical=true, - texture=current_downfall.texture, player=player:get_player_name()}) - local downfall_origin = vector.divide(vector.add(minp,maxp),2) - handle_damage(current_downfall.damage_player,player,downfall_origin) - end + local exp = current_downfall.exptime + + minetest.add_particlespawner({ + amount=current_downfall.amount, time=0.5, + minpos=minp, maxpos=maxp, + minvel=vel, maxvel=vel, + minacc=acc, maxacc=acc, + minexptime=exp, maxexptime=exp, + minsize=current_downfall.size, maxsize=current_downfall.size, + collisiondetection=true, collision_removal=true, + vertical=true, + texture=current_downfall.texture, player=player:get_player_name() + }) + + local downfall_origin = vector.divide(vector.add(minp,maxp),2) + handle_damage(current_downfall.damage_player,player,downfall_origin) + end end) \ No newline at end of file diff --git a/weather/init.lua b/weather/init.lua index c757980..bf62d59 100644 --- a/weather/init.lua +++ b/weather/init.lua @@ -3,7 +3,7 @@ -- * snow -- * wind -assert(minetest.add_particlespawner, "You have some really old minetest...") +assert(minetest.add_particlespawner, "Weather doesn't work with this really old minetest.") weather_mod={ modpath=minetest.get_modpath("weather"), @@ -32,6 +32,7 @@ end) () dofile(weather_mod.modpath.."/api.lua") dofile(weather_mod.modpath.."/rain.lua") +dofile(weather_mod.modpath.."/sand.lua") dofile(weather_mod.modpath.."/snow.lua") dofile(weather_mod.modpath.."/command.lua") diff --git a/weather/rain.lua b/weather/rain.lua index 1a187bf..65dcdc1 100644 --- a/weather/rain.lua +++ b/weather/rain.lua @@ -1,7 +1,7 @@ -- Rain weather_mod.register_downfall("weather:rain",{ - min_pos = {x=-9, y=7, z=-9}, - max_pos = {x= 9, y=7, z= 9}, + min_pos = {x=-15, y=7, z=-15}, + max_pos = {x= 15, y=7, z= 15}, falling_speed=10, amount=25, exptime=0.8, @@ -9,3 +9,14 @@ weather_mod.register_downfall("weather:rain",{ texture="weather_rain.png", enable_lightning=true, }) + +weather_mod.register_downfall("weather:storm",{ + min_pos = {x = -15, y = 7, z = -15}, + max_pos = {x = 15, y = 7, z = 15}, + falling_speed = 10, + amount = 30, + exptime = 0.8, + size = 30, + texture = "weather_rain_dark.png", + enable_lightning = true, +}) diff --git a/weather/sand.lua b/weather/sand.lua new file mode 100644 index 0000000..e640676 --- /dev/null +++ b/weather/sand.lua @@ -0,0 +1,10 @@ +weather_mod.register_downfall("weather:sandstorm",{ + min_pos = {x=-20, y=0, z=-20}, + max_pos = {x= 20, y=2, z= 20}, + falling_speed=-1, + amount=20, + exptime=1, + size=25, + texture="weather_sand.png", + min_wind = 5, +}) diff --git a/weather/screenshot.5.png b/weather/screenshot.5.png new file mode 100644 index 0000000..87d096a Binary files /dev/null and b/weather/screenshot.5.png differ diff --git a/weather/snow.lua b/weather/snow.lua index 795c609..2abe5d2 100644 --- a/weather/snow.lua +++ b/weather/snow.lua @@ -1,12 +1,23 @@ -- Snow weather_mod.register_downfall("weather:snow",{ - min_pos = {x=-9, y=7, z=-9}, - max_pos = {x= 9, y=7, z= 9}, + min_pos = {x=-15, y=7, z=-15}, + max_pos = {x= 15, y=7, z= 15}, falling_speed=5, - amount=10, + amount=15, exptime=5, size=25, - texture="weather_snow.png" + texture="weather_snow.png", +}) + +weather_mod.register_downfall("weather:hail",{ + min_pos = {x=-15, y=7, z=-15}, + max_pos = {x= 15, y=7, z= 15}, + falling_speed=25, + amount=15, + exptime=0.8, + size=25, + texture="weather_hail.png", + enable_lightning = true, }) local snow_box = diff --git a/weather/textures/weather_hail.png b/weather/textures/weather_hail.png new file mode 100644 index 0000000..4fcfe70 Binary files /dev/null and b/weather/textures/weather_hail.png differ diff --git a/weather/textures/weather_rain_dark.png b/weather/textures/weather_rain_dark.png new file mode 100644 index 0000000..3829b36 Binary files /dev/null and b/weather/textures/weather_rain_dark.png differ diff --git a/weather/textures/weather_sand.png b/weather/textures/weather_sand.png new file mode 100644 index 0000000..148a04d Binary files /dev/null and b/weather/textures/weather_sand.png differ