Add open/close sound gains to the Doors API, balance sound levels (#2768)

This commit is contained in:
Paramat 2021-05-31 20:43:33 +01:00 committed by GitHub
parent 71ea0c65ea
commit ddebdeccb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 6 deletions

@ -225,6 +225,8 @@ The doors mod allows modders to register custom doors and trapdoors.
sounds = default.node_sound_wood_defaults(), -- optional
sound_open = sound play for open door, -- optional
sound_close = sound play for close door, -- optional
gain_open = 0.3, -- optional, defaults to 0.3
gain_close = 0.3, -- optional, defaults to 0.3
protected = false, -- If true, only placer can open the door (locked for others)
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
-- 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.
sounds = default.node_sound_wood_defaults(), -- optional
sound_open = sound play for open door, -- optional
sound_close = sound play for close door, -- optional
gain_open = 0.3, -- optional, defaults to 0.3
gain_close = 0.3, -- optional, defaults to 0.3
protected = false, -- If true, only placer can open the door (locked for others)
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
-- function containing the on_rightclick callback

@ -170,10 +170,10 @@ function doors.door_toggle(pos, node, clicker)
if state % 2 == 0 then
minetest.sound_play(def.door.sounds[1],
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
{pos = pos, gain = def.door.gains[1], max_hear_distance = 10}, true)
else
minetest.sound_play(def.door.sounds[2],
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
{pos = pos, gain = def.door.gains[2], max_hear_distance = 10}, true)
end
minetest.swap_node(pos, {
@ -364,12 +364,21 @@ function doors.register(name, def)
def.sound_close = "doors_door_close"
end
if not def.gain_open then
def.gain_open = 0.3
end
if not def.gain_close then
def.gain_close = 0.3
end
def.groups.not_in_creative_inventory = 1
def.groups.door = 1
def.drop = name
def.door = {
name = name,
sounds = { def.sound_close, def.sound_open },
sounds = {def.sound_close, def.sound_open},
gains = {def.gain_close, def.gain_open},
}
if not def.on_rightclick then
def.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
@ -461,6 +470,8 @@ doors.register("door_wood", {
description = S("Wooden Door"),
inventory_image = "doors_item_wood.png",
groups = {node = 1, choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
gain_open = 0.06,
gain_close = 0.13,
recipe = {
{"group:wood", "group:wood"},
{"group:wood", "group:wood"},
@ -477,6 +488,8 @@ doors.register("door_steel", {
sounds = default.node_sound_metal_defaults(),
sound_open = "doors_steel_door_open",
sound_close = "doors_steel_door_close",
gain_open = 0.2,
gain_close = 0.2,
recipe = {
{"default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot"},
@ -492,6 +505,8 @@ doors.register("door_glass", {
sounds = default.node_sound_glass_defaults(),
sound_open = "doors_glass_door_open",
sound_close = "doors_glass_door_close",
gain_open = 0.3,
gain_close = 0.25,
recipe = {
{"default:glass", "default:glass"},
{"default:glass", "default:glass"},
@ -507,6 +522,8 @@ doors.register("door_obsidian_glass", {
sounds = default.node_sound_glass_defaults(),
sound_open = "doors_glass_door_open",
sound_close = "doors_glass_door_close",
gain_open = 0.3,
gain_close = 0.25,
recipe = {
{"default:obsidian_glass", "default:obsidian_glass"},
{"default:obsidian_glass", "default:obsidian_glass"},
@ -553,12 +570,12 @@ function doors.trapdoor_toggle(pos, node, clicker)
if string.sub(node.name, -5) == "_open" then
minetest.sound_play(def.sound_close,
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
{pos = pos, gain = def.gain_close, max_hear_distance = 10}, true)
minetest.swap_node(pos, {name = string.sub(node.name, 1,
string.len(node.name) - 5), param1 = node.param1, param2 = node.param2})
else
minetest.sound_play(def.sound_open,
{pos = pos, gain = 0.3, max_hear_distance = 10}, true)
{pos = pos, gain = def.gain_open, max_hear_distance = 10}, true)
minetest.swap_node(pos, {name = node.name .. "_open",
param1 = node.param1, param2 = node.param2})
end
@ -641,6 +658,14 @@ function doors.register_trapdoor(name, def)
def.sound_close = "doors_door_close"
end
if not def.gain_open then
def.gain_open = 0.3
end
if not def.gain_close then
def.gain_close = 0.3
end
local def_opened = table.copy(def)
local def_closed = table.copy(def)
@ -694,6 +719,8 @@ doors.register_trapdoor("doors:trapdoor", {
wield_image = "doors_trapdoor.png",
tile_front = "doors_trapdoor.png",
tile_side = "doors_trapdoor_side.png",
gain_open = 0.06,
gain_close = 0.13,
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, door = 1},
})
@ -707,6 +734,8 @@ doors.register_trapdoor("doors:trapdoor_steel", {
sounds = default.node_sound_metal_defaults(),
sound_open = "doors_steel_door_open",
sound_close = "doors_steel_door_close",
gain_open = 0.2,
gain_close = 0.2,
groups = {cracky = 1, level = 2, door = 1},
})
@ -747,7 +776,7 @@ function doors.register_fencegate(name, def)
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local node_def = minetest.registered_nodes[node.name]
minetest.swap_node(pos, {name = node_def.gate, param2 = node.param2})
minetest.sound_play(node_def.sound, {pos = pos, gain = 0.3,
minetest.sound_play(node_def.sound, {pos = pos, gain = 0.15,
max_hear_distance = 8}, true)
return itemstack
end,

@ -227,6 +227,8 @@ if minetest.get_modpath("doors") then
sounds = default.node_sound_metal_defaults(),
sound_open = "xpanes_steel_bar_door_open",
sound_close = "xpanes_steel_bar_door_close",
gain_open = 0.15,
gain_close = 0.13,
recipe = {
{"xpanes:bar_flat", "xpanes:bar_flat"},
{"xpanes:bar_flat", "xpanes:bar_flat"},
@ -245,6 +247,8 @@ if minetest.get_modpath("doors") then
sounds = default.node_sound_metal_defaults(),
sound_open = "xpanes_steel_bar_door_open",
sound_close = "xpanes_steel_bar_door_close",
gain_open = 0.15,
gain_close = 0.13,
})
minetest.register_craft({