From 296e746fab05043e6ece1fd20084383a8f5844a0 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 22 Feb 2017 03:57:12 +0100 Subject: [PATCH] Allow to use custom fence gate sounds --- mods/ITEMS/mcl_fences/API.md | 8 ++++++-- mods/ITEMS/mcl_fences/init.lua | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/mods/ITEMS/mcl_fences/API.md b/mods/ITEMS/mcl_fences/API.md index 93cfc492f..8867e4c34 100644 --- a/mods/ITEMS/mcl_fences/API.md +++ b/mods/ITEMS/mcl_fences/API.md @@ -19,7 +19,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`). -## `mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, gate_image, groups, connects_to, sounds)` +## `mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, gate_image, groups, connects_to, sounds, sound_open, sound_close)` Adds a fence gate without crafting recipe. This will create 2 nodes. ### Parameters @@ -30,6 +30,8 @@ Adds a fence gate without crafting recipe. This will create 2 nodes. * `groups`: Table of groups to which the fence gate belongs to * `connects_to`: Table of nodes (itemstrings) to which the fence will connect to. Use `group:` for all members of the group `` * `sounds`: Node sound table for the fence gate +* `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) 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`. @@ -39,7 +41,7 @@ This function returns 2 values, in the following order: 1. Itemstring of the closed fence gate 2. Itemstring of the open fence gate -## `mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture, fence_image, gate_image, groups, connects_to, sounds)` +## `mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture, fence_image, gate_image, groups, connects_to, sounds, sound_open, sound_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. This will register 3 nodes in total without crafting recipes. @@ -52,6 +54,8 @@ This will register 3 nodes in total without crafting recipes. * `groups`: Table of groups to which the fence and fence gate belong to * `connects_to`: Table of nodes (itemstrings) to which the fence and fence gate will connect to. Use `group:` for all members of the group `` * `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_close`: Sound to play when closing fence gate (optional, default is wooden sound) ### Return value This function returns 3 values, in this order: diff --git a/mods/ITEMS/mcl_fences/init.lua b/mods/ITEMS/mcl_fences/init.lua index e852dc875..2ed07e69a 100644 --- a/mods/ITEMS/mcl_fences/init.lua +++ b/mods/ITEMS/mcl_fences/init.lua @@ -64,7 +64,7 @@ mcl_fences.register_fence = function(id, fence_name, texture, fence_image, group return fence_id end -mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, gate_image, groups, connects_to, sounds) +mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, gate_image, groups, connects_to, sounds, sound_open, sound_close, sound_gain) local meta2 local state2 = 0 @@ -74,17 +74,26 @@ mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, gate_ima local gate_id = minetest.get_current_modname()..":"..id.."_gate" local open_gate_id = gate_id .. "_open" + if not sound_open then + sound_open = "doors_fencegate_open" + end + if not sound_close then + sound_close = "doors_fencegate_close" + end + if not sound_gain then + sound_gain = 0.3 + end local function punch_gate(pos, node) meta2 = minetest.get_meta(pos) state2 = meta2:get_int("state") local tmp_node2 if state2 == 1 then state2 = 0 - minetest.sound_play("doors_fencegate_close", {gain = 0.3, max_hear_distance = 10}) + minetest.sound_play(sound_close, {gain = 0.5, max_hear_distance = 10}) tmp_node2 = {name=gate_id, param1=node.param1, param2=node.param2} else state2 = 1 - minetest.sound_play("doors_fencegate_open", {gain = 0.3, max_hear_distance = 10}) + minetest.sound_play(sound_open, {gain = 0.5, max_hear_distance = 10}) tmp_node2 = {name=open_gate_id, param1=node.param1, param2=node.param2} end update_gate(pos, tmp_node2) @@ -202,9 +211,9 @@ mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, gate_ima return gate_id, open_gate_id end -mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture, fence_image, gate_image, groups, connects_to, sounds) +mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture, fence_image, gate_image, groups, connects_to, sounds, sound_open, sound_close) local fence_id = mcl_fences.register_fence(id, fence_name, texture, fence_image, groups, connects_to, sounds) - local gate_id, open_gate_id = mcl_fences.register_fence_gate(id, fence_gate_name, texture, gate_image, groups, connects_to, sounds) + local gate_id, open_gate_id = mcl_fences.register_fence_gate(id, fence_gate_name, texture, gate_image, groups, connects_to, sounds, sound_open, sound_close) return fence_id, gate_id, open_gate_id end