forked from Mirrorlandia_minetest/digistuff
Make piston sounds configurable
This commit is contained in:
parent
6c299b2fe5
commit
8e65252826
1
README
1
README
@ -108,6 +108,7 @@ You can also send a command as a table. If so, the fields that can be used in th
|
|||||||
* action: "extend" or "retract"
|
* action: "extend" or "retract"
|
||||||
* max: The maximum number of nodes to push/pull, cannot be set higher than 16. Set to 0 (or omit) when retracting to perform a non-sticky retraction.
|
* max: The maximum number of nodes to push/pull, cannot be set higher than 16. Set to 0 (or omit) when retracting to perform a non-sticky retraction.
|
||||||
* allsticky: Pull a whole stack of nodes (like movestone), not just one.
|
* allsticky: Pull a whole stack of nodes (like movestone), not just one.
|
||||||
|
* sound: The sound to make. "mesecons" for the mesecons piston sounds, "digilines" for the digilines piston sounds (default), or "none" for no sounds at all.
|
||||||
|
|
||||||
How to use the digilines movestone:
|
How to use the digilines movestone:
|
||||||
Commands for this node are in the form of a table, with the field "command" set to the desired action, and other fields providing parameters.
|
Commands for this node are in the form of a table, with the field "command" set to the desired action, and other fields providing parameters.
|
||||||
|
20
piston.lua
20
piston.lua
@ -3,14 +3,18 @@ if not minetest.get_modpath("mesecons_mvps") then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local function extend(pos,node,max)
|
local function extend(pos,node,max,sound)
|
||||||
local meta = minetest.get_meta(pos):to_table()
|
local meta = minetest.get_meta(pos):to_table()
|
||||||
local facedir = minetest.facedir_to_dir(node.param2)
|
local facedir = minetest.facedir_to_dir(node.param2)
|
||||||
local actiondir = vector.multiply(facedir,-1)
|
local actiondir = vector.multiply(facedir,-1)
|
||||||
local ppos = vector.add(pos,actiondir)
|
local ppos = vector.add(pos,actiondir)
|
||||||
local success,stack,oldstack = mesecon.mvps_push(ppos,actiondir,max)
|
local success,stack,oldstack = mesecon.mvps_push(ppos,actiondir,max)
|
||||||
if not success then return end
|
if not success then return end
|
||||||
minetest.sound_play("digistuff_piston_extend",{pos = pos,max_hear_distance = 20,gain = 0.6})
|
if sound == "digilines" then
|
||||||
|
minetest.sound_play("digistuff_piston_extend",{pos = pos,max_hear_distance = 20,gain = 0.6})
|
||||||
|
elseif sound == "mesecons" then
|
||||||
|
minetest.sound_play("piston_extend",{pos = pos,max_hear_distance = 20,gain = 0.6})
|
||||||
|
end
|
||||||
minetest.swap_node(pos,{name = "digistuff:piston_ext",param2 = node.param2})
|
minetest.swap_node(pos,{name = "digistuff:piston_ext",param2 = node.param2})
|
||||||
minetest.swap_node(ppos,{name = "digistuff:piston_pusher",param2 = node.param2})
|
minetest.swap_node(ppos,{name = "digistuff:piston_pusher",param2 = node.param2})
|
||||||
mesecon.mvps_process_stack(stack)
|
mesecon.mvps_process_stack(stack)
|
||||||
@ -18,7 +22,7 @@ local function extend(pos,node,max)
|
|||||||
minetest.get_meta(pos):from_table(meta)
|
minetest.get_meta(pos):from_table(meta)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function retract(pos,node,max,allsticky)
|
local function retract(pos,node,max,allsticky,sound)
|
||||||
local facedir = minetest.facedir_to_dir(node.param2)
|
local facedir = minetest.facedir_to_dir(node.param2)
|
||||||
local actiondir = vector.multiply(facedir,-1)
|
local actiondir = vector.multiply(facedir,-1)
|
||||||
local ppos = vector.add(pos,actiondir)
|
local ppos = vector.add(pos,actiondir)
|
||||||
@ -26,7 +30,11 @@ local function retract(pos,node,max,allsticky)
|
|||||||
if minetest.get_node(ppos).name == "digistuff:piston_pusher" then
|
if minetest.get_node(ppos).name == "digistuff:piston_pusher" then
|
||||||
minetest.remove_node(ppos)
|
minetest.remove_node(ppos)
|
||||||
end
|
end
|
||||||
minetest.sound_play("digistuff_piston_retract",{pos = pos,max_hear_distance = 20,gain = 0.6})
|
if sound == "digilines" then
|
||||||
|
minetest.sound_play("digistuff_piston_retract",{pos = pos,max_hear_distance = 20,gain = 0.6})
|
||||||
|
elseif sound == "mesecons" then
|
||||||
|
minetest.sound_play("piston_retract",{pos = pos,max_hear_distance = 20,gain = 0.6})
|
||||||
|
end
|
||||||
minetest.check_for_falling(ppos)
|
minetest.check_for_falling(ppos)
|
||||||
if type(max) ~= "number" or max <= 0 then return end
|
if type(max) ~= "number" or max <= 0 then return end
|
||||||
local pullpos = vector.add(pos,vector.multiply(actiondir,2))
|
local pullpos = vector.add(pos,vector.multiply(actiondir,2))
|
||||||
@ -91,7 +99,7 @@ minetest.register_node("digistuff:piston", {
|
|||||||
if type(msg.max) == "number" then
|
if type(msg.max) == "number" then
|
||||||
max = math.max(0,math.min(16,math.floor(msg.max)))
|
max = math.max(0,math.min(16,math.floor(msg.max)))
|
||||||
end
|
end
|
||||||
extend(pos,node,max)
|
extend(pos,node,max,msg.sound or "digilines")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
@ -171,7 +179,7 @@ minetest.register_node("digistuff:piston_ext", {
|
|||||||
elseif msg.max == nil then
|
elseif msg.max == nil then
|
||||||
max = 0
|
max = 0
|
||||||
end
|
end
|
||||||
retract(pos,node,max,msg.allsticky)
|
retract(pos,node,max,msg.allsticky,msg.sound or "digilines")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user