1
0
Fork 0

Allow to set gain of fence gate sounds

This commit is contained in:
Wuzzy 2017-02-23 15:41:46 +01:00
parent bfbb6d145e
commit 24a69977f0
2 changed files with 16 additions and 9 deletions

View File

@ -18,7 +18,7 @@ The full itemstring of the new fence node.
Notes: Fences will always have the group `fence=1`. They will always connect to solid nodes (group `solid=1`). Notes: Fences will always have the group `fence=1`. They will always connect to solid nodes (group `solid=1`).
## `mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups, sounds, sound_open, sound_close)` ## `mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close)`
Adds a fence gate without crafting recipe. This will create 2 nodes. Adds a fence gate without crafting recipe. This will create 2 nodes.
### Parameters ### Parameters
@ -29,6 +29,8 @@ Adds a fence gate without crafting recipe. This will create 2 nodes.
* `sounds`: Node sound table for the fence gate * `sounds`: Node sound table for the fence gate
* `sound_open`: Sound to play when opening fence gate (optional, default is wooden sound) * `sound_open`: Sound to play when opening fence gate (optional, default is wooden sound)
* `sound_close`: Sound to play when closing fence gate (optional, default is wooden sound) * `sound_close`: Sound to play when closing fence gate (optional, default is wooden sound)
* `sound_gain_open`: Gain (0.0-1.0) of the opening fence gate sound (optional, default is 0.3)
* `sound_gain_close`: Gain (0.0-1.0) of the closing fence gate sound (optional, default is 0.3)
Notes: Fence gates will always have the group `fence_gate=1`. The open fence gate will always have the group `not_in_creative_inventory=1`. Notes: Fence gates will always have the group `fence_gate=1`. The open fence gate will always have the group `not_in_creative_inventory=1`.
@ -38,7 +40,7 @@ This function returns 2 values, in the following order:
1. Itemstring of the closed fence gate 1. Itemstring of the closed fence gate
2. Itemstring of the open fence gate 2. Itemstring of the open fence gate
## `mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture, groups, connects_to, sounds, sound_open, sound_close)` ## `mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture, groups, connects_to, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close)`
Registers a fence and fence gate. This is basically a combination of the two functions above. This is the recommended way to add a fence / fence gate pair. Registers a fence and fence gate. This is basically a combination of the two functions above. This is the recommended way to add a fence / fence gate pair.
This will register 3 nodes in total without crafting recipes. This will register 3 nodes in total without crafting recipes.
@ -51,6 +53,8 @@ This will register 3 nodes in total without crafting recipes.
* `sounds`: Node sound table for the fence and the fence gate * `sounds`: Node sound table for the fence and the fence gate
* `sound_open`: Sound to play when opening fence gate (optional, default is wooden sound) * `sound_open`: Sound to play when opening fence gate (optional, default is wooden sound)
* `sound_close`: Sound to play when closing fence gate (optional, default is wooden sound) * `sound_close`: Sound to play when closing fence gate (optional, default is wooden sound)
* `sound_gain_open`: Gain (0.0-1.0) of the opening fence gate sound (optional, default is 0.3)
* `sound_gain_close`: Gain (0.0-1.0) of the closing fence gate sound (optional, default is 0.3)
### Return value ### Return value
This function returns 3 values, in this order: This function returns 3 values, in this order:

View File

@ -64,7 +64,7 @@ mcl_fences.register_fence = function(id, fence_name, texture, groups, connects_t
return fence_id return fence_id
end end
mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups, sounds, sound_open, sound_close, sound_gain) mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close)
local meta2 local meta2
local state2 = 0 local state2 = 0
@ -80,8 +80,11 @@ mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups,
if not sound_close then if not sound_close then
sound_close = "doors_fencegate_close" sound_close = "doors_fencegate_close"
end end
if not sound_gain then if not sound_gain_open then
sound_gain = 0.3 sound_gain_open = 0.3
end
if not sound_gain_close then
sound_gain_close = 0.3
end end
local function punch_gate(pos, node) local function punch_gate(pos, node)
meta2 = minetest.get_meta(pos) meta2 = minetest.get_meta(pos)
@ -89,11 +92,11 @@ mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups,
local tmp_node2 local tmp_node2
if state2 == 1 then if state2 == 1 then
state2 = 0 state2 = 0
minetest.sound_play(sound_close, {gain = 0.5, max_hear_distance = 10}) minetest.sound_play(sound_close, {gain = sound_gain_close, max_hear_distance = 10})
tmp_node2 = {name=gate_id, param1=node.param1, param2=node.param2} tmp_node2 = {name=gate_id, param1=node.param1, param2=node.param2}
else else
state2 = 1 state2 = 1
minetest.sound_play(sound_open, {gain = 0.5, max_hear_distance = 10}) minetest.sound_play(sound_open, {gain = sound_gain_open, max_hear_distance = 10})
tmp_node2 = {name=open_gate_id, param1=node.param1, param2=node.param2} tmp_node2 = {name=open_gate_id, param1=node.param1, param2=node.param2}
end end
update_gate(pos, tmp_node2) update_gate(pos, tmp_node2)
@ -207,9 +210,9 @@ mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups,
return gate_id, open_gate_id return gate_id, open_gate_id
end end
mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture, groups, connects_to, sounds, sound_open, sound_close) mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture, groups, connects_to, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close)
local fence_id = mcl_fences.register_fence(id, fence_name, texture, groups, connects_to, sounds) local fence_id = mcl_fences.register_fence(id, fence_name, texture, groups, connects_to, sounds)
local gate_id, open_gate_id = mcl_fences.register_fence_gate(id, fence_gate_name, texture, groups, sounds, sound_open, sound_close) local gate_id, open_gate_id = mcl_fences.register_fence_gate(id, fence_gate_name, texture, groups, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close)
return fence_id, gate_id, open_gate_id return fence_id, gate_id, open_gate_id
end end