diff --git a/.luacheckrc b/.luacheckrc index 2364e1d..3c31033 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -10,6 +10,9 @@ read_globals = { -- Minetest "minetest", - "vector", "ItemStack" + "vector", "ItemStack", + + -- mods + "digilines" } diff --git a/depends.txt b/depends.txt deleted file mode 100644 index dd64597..0000000 --- a/depends.txt +++ /dev/null @@ -1,7 +0,0 @@ -default? -doors? -horror? -mesecons? -technic? -ambience? -mobs_monster? diff --git a/digiline.lua b/digiline.lua new file mode 100644 index 0000000..5262090 --- /dev/null +++ b/digiline.lua @@ -0,0 +1,42 @@ + +soundblock.digiline_rules = { + -- digilines.rules.default + {x= 1,y= 0,z= 0},{x=-1,y= 0,z= 0}, -- along x side + {x= 0,y= 0,z= 1},{x= 0,y= 0,z=-1}, -- along z side + {x= 1,y= 1,z= 0},{x=-1,y= 1,z= 0}, -- 1 node above along x diagonal + {x= 0,y= 1,z= 1},{x= 0,y= 1,z=-1}, -- 1 node above along z diagonal + {x= 1,y=-1,z= 0},{x=-1,y=-1,z= 0}, -- 1 node below along x diagonal + {x= 0,y=-1,z= 1},{x= 0,y=-1,z=-1}, -- 1 node below along z diagonal + {x= 0,y= 1,z= 0},{x= 0,y=-1,z= 0}, -- along y above and below +} + +function soundblock.digiline_effector(pos, _, channel, msg) + local msgt = type(msg) + if msgt ~= "table" then + return + end + + if channel ~= "soundblock" then + return + end + + if msg.command == "play" then + -- default position + + local playpos = pos + if msg.pos then + -- relative position offset + playpos = vector.add(pos, { + x = tonumber(msg.pos.x) or 0, + y = tonumber(msg.pos.y) or 0, + z = tonumber(msg.pos.z) or 0 + }) + end + + minetest.sound_play(msg.name, { + pos = playpos, + gain = math.min(10, tonumber(msg.gain) or 1), + max_hear_distance = math.min(32, tonumber(msg.hear_distance) or 10) + }) + end +end diff --git a/init.lua b/init.lua index 47a93e5..d7ebb2c 100644 --- a/init.lua +++ b/init.lua @@ -6,6 +6,7 @@ soundblock = { local MP = minetest.get_modpath("soundblock") dofile(MP.."/api.lua") dofile(MP.."/form.lua") +dofile(MP.."/digiline.lua") dofile(MP.."/soundblock.lua") dofile(MP.."/recipe.lua") diff --git a/mod.conf b/mod.conf new file mode 100644 index 0000000..f46032a --- /dev/null +++ b/mod.conf @@ -0,0 +1,3 @@ +name = soundblock +description = Soundblock +optional_depends = default, doors, horror, mesecons, technic, ambience, mobs_monster, digilines diff --git a/readme.md b/readme.md index 3190e44..48b0a9f 100644 --- a/readme.md +++ b/readme.md @@ -25,7 +25,22 @@ soundblocks.register({ ``` +# Digiline api +``lua +if event.type == "program" then + digiline_send("soundblock", { + command = "play", + name = "default_grass_footstep.1.ogg", + -- relative position (optional) + pos = { x=0, y=10, z=0 }, + -- gain, defaults to 1 + gain = 1, + -- max_hear_distance, defaults to 10 + hear_distance = 32 + }) +end +``` # License diff --git a/soundblock.lua b/soundblock.lua index 065454d..f9e8908 100644 --- a/soundblock.lua +++ b/soundblock.lua @@ -115,5 +115,16 @@ minetest.register_node("soundblock:block", { } }, + digiline = { + receptor = { + rules = soundblock.digiline_rules, + action = function() end + }, + effector = { + rules = soundblock.digiline_rules, + action = soundblock.digiline_effector + } + }, + on_rightclick = soundblock.showform })