Skip to content

Commit ddebdec

Browse files
authoredMay 31, 2021
Add open/close sound gains to the Doors API, balance sound levels (#2768)
1 parent 71ea0c6 commit ddebdec

File tree

3 files changed

+43
-6
lines changed

3 files changed

+43
-6
lines changed
 

Diff for: ‎game_api.txt

+4
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ The doors mod allows modders to register custom doors and trapdoors.
225225
sounds = default.node_sound_wood_defaults(), -- optional
226226
sound_open = sound play for open door, -- optional
227227
sound_close = sound play for close door, -- optional
228+
gain_open = 0.3, -- optional, defaults to 0.3
229+
gain_close = 0.3, -- optional, defaults to 0.3
228230
protected = false, -- If true, only placer can open the door (locked for others)
229231
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
230232
-- optional function containing the on_rightclick callback, defaults to a doors.door_toggle-wrapper
@@ -244,6 +246,8 @@ The doors mod allows modders to register custom doors and trapdoors.
244246
sounds = default.node_sound_wood_defaults(), -- optional
245247
sound_open = sound play for open door, -- optional
246248
sound_close = sound play for close door, -- optional
249+
gain_open = 0.3, -- optional, defaults to 0.3
250+
gain_close = 0.3, -- optional, defaults to 0.3
247251
protected = false, -- If true, only placer can open the door (locked for others)
248252
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
249253
-- function containing the on_rightclick callback

Diff for: ‎mods/doors/init.lua

+35-6
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ function doors.door_toggle(pos, node, clicker)
170170

171171
if state % 2 == 0 then
172172
minetest.sound_play(def.door.sounds[1],
173-
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
173+
{pos = pos, gain = def.door.gains[1], max_hear_distance = 10}, true)
174174
else
175175
minetest.sound_play(def.door.sounds[2],
176-
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
176+
{pos = pos, gain = def.door.gains[2], max_hear_distance = 10}, true)
177177
end
178178

179179
minetest.swap_node(pos, {
@@ -364,12 +364,21 @@ function doors.register(name, def)
364364
def.sound_close = "doors_door_close"
365365
end
366366

367+
if not def.gain_open then
368+
def.gain_open = 0.3
369+
end
370+
371+
if not def.gain_close then
372+
def.gain_close = 0.3
373+
end
374+
367375
def.groups.not_in_creative_inventory = 1
368376
def.groups.door = 1
369377
def.drop = name
370378
def.door = {
371379
name = name,
372-
sounds = { def.sound_close, def.sound_open },
380+
sounds = {def.sound_close, def.sound_open},
381+
gains = {def.gain_close, def.gain_open},
373382
}
374383
if not def.on_rightclick then
375384
def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
@@ -461,6 +470,8 @@ doors.register("door_wood", {
461470
description = S("Wooden Door"),
462471
inventory_image = "doors_item_wood.png",
463472
groups = {node = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
473+
gain_open = 0.06,
474+
gain_close = 0.13,
464475
recipe = {
465476
{"group:wood", "group:wood"},
466477
{"group:wood", "group:wood"},
@@ -477,6 +488,8 @@ doors.register("door_steel", {
477488
sounds = default.node_sound_metal_defaults(),
478489
sound_open = "doors_steel_door_open",
479490
sound_close = "doors_steel_door_close",
491+
gain_open = 0.2,
492+
gain_close = 0.2,
480493
recipe = {
481494
{"default:steel_ingot", "default:steel_ingot"},
482495
{"default:steel_ingot", "default:steel_ingot"},
@@ -492,6 +505,8 @@ doors.register("door_glass", {
492505
sounds = default.node_sound_glass_defaults(),
493506
sound_open = "doors_glass_door_open",
494507
sound_close = "doors_glass_door_close",
508+
gain_open = 0.3,
509+
gain_close = 0.25,
495510
recipe = {
496511
{"default:glass", "default:glass"},
497512
{"default:glass", "default:glass"},
@@ -507,6 +522,8 @@ doors.register("door_obsidian_glass", {
507522
sounds = default.node_sound_glass_defaults(),
508523
sound_open = "doors_glass_door_open",
509524
sound_close = "doors_glass_door_close",
525+
gain_open = 0.3,
526+
gain_close = 0.25,
510527
recipe = {
511528
{"default:obsidian_glass", "default:obsidian_glass"},
512529
{"default:obsidian_glass", "default:obsidian_glass"},
@@ -553,12 +570,12 @@ function doors.trapdoor_toggle(pos, node, clicker)
553570

554571
if string.sub(node.name, -5) == "_open" then
555572
minetest.sound_play(def.sound_close,
556-
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
573+
{pos = pos, gain = def.gain_close, max_hear_distance = 10}, true)
557574
minetest.swap_node(pos, {name = string.sub(node.name, 1,
558575
string.len(node.name) - 5), param1 = node.param1, param2 = node.param2})
559576
else
560577
minetest.sound_play(def.sound_open,
561-
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
578+
{pos = pos, gain = def.gain_open, max_hear_distance = 10}, true)
562579
minetest.swap_node(pos, {name = node.name .. "_open",
563580
param1 = node.param1, param2 = node.param2})
564581
end
@@ -641,6 +658,14 @@ function doors.register_trapdoor(name, def)
641658
def.sound_close = "doors_door_close"
642659
end
643660

661+
if not def.gain_open then
662+
def.gain_open = 0.3
663+
end
664+
665+
if not def.gain_close then
666+
def.gain_close = 0.3
667+
end
668+
644669
local def_opened = table.copy(def)
645670
local def_closed = table.copy(def)
646671

@@ -694,6 +719,8 @@ doors.register_trapdoor("doors:trapdoor", {
694719
wield_image = "doors_trapdoor.png",
695720
tile_front = "doors_trapdoor.png",
696721
tile_side = "doors_trapdoor_side.png",
722+
gain_open = 0.06,
723+
gain_close = 0.13,
697724
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, door = 1},
698725
})
699726

@@ -707,6 +734,8 @@ doors.register_trapdoor("doors:trapdoor_steel", {
707734
sounds = default.node_sound_metal_defaults(),
708735
sound_open = "doors_steel_door_open",
709736
sound_close = "doors_steel_door_close",
737+
gain_open = 0.2,
738+
gain_close = 0.2,
710739
groups = {cracky = 1, level = 2, door = 1},
711740
})
712741

@@ -747,7 +776,7 @@ function doors.register_fencegate(name, def)
747776
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
748777
local node_def = minetest.registered_nodes[node.name]
749778
minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2})
750-
minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3,
779+
minetest.sound_play(node_def.sound, {pos = pos, gain = 0.15,
751780
max_hear_distance = 8}, true)
752781
return itemstack
753782
end,

Diff for: ‎mods/xpanes/init.lua

+4
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ if minetest.get_modpath("doors") then
227227
sounds = default.node_sound_metal_defaults(),
228228
sound_open = "xpanes_steel_bar_door_open",
229229
sound_close = "xpanes_steel_bar_door_close",
230+
gain_open = 0.15,
231+
gain_close = 0.13,
230232
recipe = {
231233
{"xpanes:bar_flat", "xpanes:bar_flat"},
232234
{"xpanes:bar_flat", "xpanes:bar_flat"},
@@ -245,6 +247,8 @@ if minetest.get_modpath("doors") then
245247
sounds = default.node_sound_metal_defaults(),
246248
sound_open = "xpanes_steel_bar_door_open",
247249
sound_close = "xpanes_steel_bar_door_close",
250+
gain_open = 0.15,
251+
gain_close = 0.13,
248252
})
249253

250254
minetest.register_craft({

0 commit comments

Comments
 (0)
Please sign in to comment.