Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
local sounds = {}
--[[
for _, nodes in pairs(minetest.registered_nodes) do
for elem, val in pairs(nodes) do
if elem == "sounds" then
for _, spec in pairs(val) do
if not sounds[spec.name] and
spec.name ~= "" then
if not spec.gain then
spec.gain = 0.5
end
sounds[spec.name] = spec
end
end
end
end
end
for k, v in pairs(minetest.registered_entities) do
for kk, vv in pairs(v) do
if kk == "sounds" then
for kkk, vvv in pairs(vv) do
if type(vvv) == "string" then
if not sounds[vvv] and
sounds[vvv] ~= "" then
sounds[vvv] = {name = vvv, gain = 0.5}
end
end
end
end
end
end
local extra_sounds = {
"warps_whoosh",
"tnt_ignite",
"tnt_explode",
"tnt_gunpower_burning",
"fire_flint_and_steel",
"fire_extinguish_flame",
"item_drop_pickup",
"catching_breath",
"fire_fire",
"xdecor_enchanting",
"xdecor_boiling_water.ogg",
"default_punch",
"mobs_swing",
"mobs_spell",
"default_dig_oddly_breakable_by_hand",
"default_dug_node",
"runfast_eat",
"player_damage",
"doors_door_open",
"doors_door_close",
"default_chest_open",
"default_chest_close",
"crops_watercan_entering",
"crops_watercan_splash_small",
"crops_watercan_splash_quiet",
"crops_flies",
"crops_watercan_splash_big",
"crops_watercan_watering",
}
for i = 1, #extra_sounds do
local n = extra_sounds[i]
if not sounds[n] then
sounds[n] = {name = extra_sounds[i], gain = 0.5}
end
end
--]]
sounds = {"phit"}
print(dump(sounds))
local ps = function(pos)
if math.random() < 0.8 then
return
end
local s = -1
if math.random() > 0.5 then
s = 1
end
minetest.add_particle({
pos = {
x = math.random() * s + pos.x,
y = math.random() * s + pos.y,
z = math.random() * s + pos.z
},
velocity = {
x = math.random() * s,
y = math.random() * s,
z = math.random() * s
},
acceleration = {
x = math.random() * s,
y = math.random() * s,
z = math.random() * s
},
expirationtime = 1,
size = 2,
texture = "xdecor_glyph" .. math.random(1, 18) .. ".png",
})
end
minetest.register_entity("dcbl:sound_traveller", {
visual = "sprite",
visual_size = {x = 0.75, y = 0.75},
collisionbox = {0},
physical = false,
textures = {"default_mese_crystal.png"},
on_activate = function(self, staticdata, dtime_s)
self.pos = self.object:get_pos()
end,
on_step = function(self, dtime)
ps(self.pos)
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
end,
on_death = function(self, killer)
end,
on_rightclick = function(self, clicker)
end,
get_staticdata = function(self)
end,
})
dcbl.gs = function(player, s, p)
local gain = math.random()
if gain > 0.67 then
gain = 0.67
end
local pitch = math.random()
local play = minetest.sound_play
local seq = {}
for k, v in pairs(sounds) do
if math.random() < 0.2 then
minetest.after(math.random(), function()
local idx = #seq + 1
local fade = math.random(1)
local p_pos = player:get_pos()
if not p_pos then
return
end
local jitter = function(j, p)
local r = math.random()
local s = j * -1
if r > 0.5 then
s = j * 1
if math.random() > r then
return p + (1 * s)
else
return p - (1 * s)
end
elseif math.random() < r then
return p + (1 * s)
else
return p - (1 * s)
end
end
p_pos.x = jitter(math.random(), p_pos.x)
p_pos.y = jitter(math.random(), p_pos.y)
p_pos.z = jitter(math.random(), p_pos.z)
local object = minetest.add_entity(p_pos,
"dcbl:sound_traveller", "")
local o_pos = object:get_pos()
local d = vector.direction(p_pos, o_pos)
d.x = jitter(math.random(), d.x)
d.y = jitter(math.random(), d.y)
d.z = jitter(math.random(), d.z)
object:set_velocity(d)
object:set_acceleration(d)
seq[idx] = play(v, {
gain = gain,
pitch = pitch,
fade = fade,
object = object
})
-- TODO Sound adjustments.
minetest.after(math.random(), function()
object:remove()
end)
print("Starting " .. seq[idx])
if fade == 1 then
minetest.sound_fade(seq[idx], 0.1, gain)
end
end)
end
end
minetest.after(math.random(), function()
for idx = 1, #seq do
minetest.after(math.random(), function()
print("Stopping " .. seq[idx])
minetest.sound_fade(seq[idx], -0.1, 0.0)
minetest.after(math.random(), function()
minetest.sound_stop(seq[idx])
end)
end)
end
dcbl.gs(player)
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.