Skip to content

Commit

Permalink
Add open/close sound gains to the Doors API, balance sound levels (#2768
Browse files Browse the repository at this point in the history
)
  • Loading branch information
paramat committed May 31, 2021
1 parent 71ea0c6 commit ddebdec
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
4 changes: 4 additions & 0 deletions game_api.txt
Expand Up @@ -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
Expand All @@ -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
Expand Down
41 changes: 35 additions & 6 deletions mods/doors/init.lua
Expand Up @@ -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, {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand All @@ -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"},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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},
})

Expand All @@ -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},
})

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions mods/xpanes/init.lua
Expand Up @@ -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"},
Expand All @@ -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({
Expand Down

0 comments on commit ddebdec

Please sign in to comment.