Update env_sounds, weather and add game_commands

master
CasimirKaPazi 2022-01-09 01:16:39 +01:00
parent deee23424f
commit b15899bcac
25 changed files with 223 additions and 34 deletions

View File

@ -11,3 +11,7 @@ Authors of media (sounds)
Yuval (CC0 1.0)
https://freesound.org/people/Yuval/sounds/197023/
env_sounds_water.*.ogg
Halion (CC0 1.0)
https://freesound.org/people/Halion/sounds/17785/
env_sounds_lava.*.ogg

View File

@ -1,11 +1,41 @@
-- Parameters
local radius = 8 -- Water node search radius around player
-- Node search radius around player
local radius = 8
-- End of parameters
local allsounds = {
["env_sounds_water"] = {
trigger = {"default:water_flowing", "default:river_water_flowing"},
base_volume = 0.04,
max_volume = 0.4,
per_node = 0.004,
},
["env_sounds_lava"] = {
trigger = {"default:lava_source", "default:lava_flowing"},
base_volume = 0,
max_volume = 0.6,
per_node = {
["default:lava_source"] = 0.008,
["default:lava_flowing"] = 0.002,
},
},
}
if minetest.settings:get_bool("river_source_sounds") then
table.insert(allsounds["env_sounds_water"].trigger,
"default:river_water_source")
end
local river_source_sounds = minetest.settings:get_bool("river_source_sounds")
-- Cache the union of all trigger nodes
local cache_triggers = {}
for sound, def in pairs(allsounds) do
for _, name in ipairs(def.trigger) do
table.insert(cache_triggers, name)
end
end
-- Update sound for player
@ -13,39 +43,57 @@ local river_source_sounds = minetest.settings:get_bool("river_source_sounds")
local function update_sound(player)
local player_name = player:get_player_name()
local ppos = player:get_pos()
ppos = vector.add(ppos, player:get_properties().eye_height)
local areamin = vector.subtract(ppos, radius)
local areamax = vector.add(ppos, radius)
local water_nodes = {"default:water_flowing", "default:river_water_flowing"}
if river_source_sounds then
table.insert(water_nodes, "default:river_water_source")
end
local wpos, _ = minetest.find_nodes_in_area(areamin, areamax, water_nodes)
local waters = #wpos
if waters == 0 then
local pos = minetest.find_nodes_in_area(areamin, areamax, cache_triggers, true)
if next(pos) == nil then -- If table empty
return
end
for sound, def in pairs(allsounds) do
-- Find average position
local posav = {0, 0, 0}
local count = 0
for _, name in ipairs(def.trigger) do
if pos[name] then
for _, p in ipairs(pos[name]) do
posav[1] = posav[1] + p.x
posav[2] = posav[2] + p.y
posav[3] = posav[3] + p.z
end
count = count + #pos[name]
end
end
-- Find average position of water positions
local wposav = vector.new()
for _, pos in ipairs(wpos) do
wposav.x = wposav.x + pos.x
wposav.y = wposav.y + pos.y
wposav.z = wposav.z + pos.z
if count > 0 then
posav = vector.new(posav[1] / count, posav[2] / count,
posav[3] / count)
-- Calculate gain
local gain = def.base_volume
if type(def.per_node) == 'table' then
for name, multiplier in pairs(def.per_node) do
if pos[name] then
gain = gain + #pos[name] * multiplier
end
end
else
gain = gain + count * def.per_node
end
gain = math.min(gain, def.max_volume)
minetest.sound_play(sound, {
pos = posav,
to_player = player_name,
gain = gain,
}, true)
end
end
wposav = vector.divide(wposav, waters)
minetest.sound_play(
"env_sounds_water",
{
pos = wposav,
to_player = player_name,
gain = math.min(0.04 + waters * 0.004, 0.4),
}
)
end
-- Update sound 'on joinplayer'
-- Update sound when player joins
minetest.register_on_joinplayer(function(player)
update_sound(player)

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,7 @@
Minetest Game mod: game_commands
================================
See license.txt for license information.
Authors of source code
----------------------
rubenwardy (MIT)

View File

@ -0,0 +1,31 @@
-- game_commands/init.lua
-- Load support for MT game translation.
local S = minetest.get_translator("game_commands")
minetest.register_chatcommand("respawn", { -- Better not name that command "kill me"
description = S("Respawn"),
func = function(name)
local player = minetest.get_player_by_name(name)
if player then
if minetest.settings:get_bool("enable_damage") then
player:set_hp(0)
return true
else
for _, callback in pairs(minetest.registered_on_respawnplayers) do
if callback(player) then
return true
end
end
-- There doesn't seem to be a way to get a default spawn pos
-- from the lua API
return false, S("No static_spawnpoint defined")
end
else
-- Show error message if used when not logged in, eg: from IRC mod
return false, S("You need to be online to respawn!")
end
end
})

View File

@ -0,0 +1,24 @@
License of source code
----------------------
The MIT License (MIT)
Copyright (C) 2017-2018 rubenwardy <rubenwardy@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
For more details:
https://opensource.org/licenses/MIT

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Selbstmord begehen, um zu Respawnen
No static_spawnpoint defined=Kein static_spawnpoint definiert
You need to be online to be killed!=Sie müssen online sein, um getötet zu werden!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Ĉesigu vi mem por renaski
No static_spawnpoint defined=Ne estas difina static_spawnpoint
You need to be online to be killed!=Vi devas esti onlina por ĉesigi!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Suicídate para reaparecer
No static_spawnpoint defined=No se ha definido un punto de aparición
You need to be online to be killed!=¡Necesitas estar en línea para que te maten!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Se suicider pour réapparaître
No static_spawnpoint defined=Pas de point d'apparition défini
You need to be online to be killed!=Vous devez être en ligne pour être tué !

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Bunuh diri untuk bangkit kembali
No static_spawnpoint defined=Tiada static_spawnpoint (titik bangkit statis) yang diatur
You need to be online to be killed!=Anda harus daring untuk dibunuh!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Ucciditi per ricomparire
No static_spawnpoint defined=Nessuno static_spawnpoint definito
You need to be online to be killed!=Devi essere in linea per essere ucciso!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=リセットしてリスポーンします
No static_spawnpoint defined=static_spawnpoint が設定されていません
You need to be online to be killed!=リセットするにはオンラインである必要があります

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=.i ro nu do catra do cu tadji pa nu do tolcanci
No static_spawnpoint defined=.i no da ckaji lo me la'o zoi.static_spawnpoint.zoi
You need to be online to be killed!=.i lo nu samjo'e cu sarcu lo nu do se catra

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Bunuh diri anda untuk lahir semula
No static_spawnpoint defined=Tiada titik permulaan statik (tetapan static_spawnpoint) ditakrifkan
You need to be online to be killed!=Anda mesti berada dalam talian untuk dibunuh!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Mate-se para reaparecer
No static_spawnpoint defined=Nenhum ponto de reaparecer estático definido
You need to be online to be killed!=Você precisa estar online para ser morto!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Убейте себя, чтобы возродиться
No static_spawnpoint defined=static_spawnpoint не определён
You need to be online to be killed!=Вы должны быть онлайн, чтобы убить себя!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Döda dig själv för att respawna
No static_spawnpoint defined=Ingen static_spawnpoint definierat
You need to be online to be killed!=Du måsta vara online för att bli dödad!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=Samovražda pre znovuzrodenie
No static_spawnpoint defined=Nie je definované stále miesto znovuzrodenia
You need to be online to be killed!=Musíš byť online, aby si mohol byť zabitý!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=自杀并重生
No static_spawnpoint defined=static_spawnpoint 未定义
You need to be online to be killed!=您需要在线才能被杀死!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=殺死自己並重生
No static_spawnpoint defined=static_spawnpoint 未定義
You need to be online to be killed!=您需要在線才能被殺死!

View File

@ -0,0 +1,4 @@
# textdomain: game_commands
Kill yourself to respawn=
No static_spawnpoint defined=
You need to be online to be killed!=

View File

@ -0,0 +1,2 @@
name = game_commands
description = Minetest Game mod: game_commands

View File

@ -82,18 +82,27 @@ local function update_clouds()
nobj_speedx = nobj_speedx or minetest.get_perlin(np_speedx)
nobj_speedz = nobj_speedz or minetest.get_perlin(np_speedz)
local n_density = nobj_density:get_2d({x = time, y = 0})
local n_thickness = nobj_thickness:get_2d({x = time, y = 0})
local n_speedx = nobj_speedx:get_2d({x = time, y = 0})
local n_speedz = nobj_speedz:get_2d({x = time, y = 0})
local n_density = nobj_density:get_2d({x = time, y = 0}) -- 0 to 1
local n_thickness = nobj_thickness:get_2d({x = time, y = 0}) -- 0 to 1
local n_speedx = nobj_speedx:get_2d({x = time, y = 0}) -- -1 to 1
local n_speedz = nobj_speedz:get_2d({x = time, y = 0}) -- -1 to 1
for _, player in ipairs(minetest.get_connected_players()) do
local humid = minetest.get_humidity(player:get_pos())
-- Fallback to mid-value 50 for very old worlds
local humid = minetest.get_humidity(player:get_pos()) or 50
-- Default and classic density value is 0.4, make this happen
-- at humidity midvalue 50 when n_density is at midvalue 0.5.
-- density_max = 0.25 at humid = 0.
-- density_max = 0.8 at humid = 50.
-- density_max = 1.35 at humid = 100.
local density_max = 0.8 + ((humid - 50) / 50) * 0.55
player:set_clouds({
density = rangelim(humid / 100, 0.25, 1.0) * n_density,
-- Range limit density_max to always have occasional
-- small scattered clouds at extreme low humidity.
density = rangelim(density_max, 0.2, 1.0) * n_density,
thickness = math.max(math.floor(
rangelim(32 * humid / 100, 8, 32) * n_thickness
), 1),
), 2),
speed = {x = n_speedx * 4, z = n_speedz * 4},
})
end