1
0
Fork 0
MineClone2/mods/ENTITIES/mcl_dripping/init.lua

56 lines
2.0 KiB
Lua
Raw Normal View History

2021-11-12 17:49:27 +00:00
-- Dripping Water Mod
-- by kddekadenz
2022-07-18 02:56:20 +00:00
-- License of code, textures & sounds: CC0
2017-01-06 01:45:04 +00:00
2021-05-24 22:54:12 +00:00
local math = math
2022-07-18 04:10:38 +00:00
local function make_drop(pos,liquid,sound,interval)
local pt = {
2022-07-18 02:56:20 +00:00
velocity = vector.new(0,0,0),
collision_removal = false,
}
2022-07-18 04:10:38 +00:00
local t = math.random() + math.random(1, interval)
minetest.after(t,function()
local x, z = math.random(-45, 45) / 100, math.random(-45, 45) / 100
pt.pos = vector.offset(pos,x,-0.52,z)
pt.acceleration = vector.new(0,0,0)
pt.collisiondetection = false
pt.expirationtime = t
2022-07-18 02:56:20 +00:00
2022-07-18 04:10:38 +00:00
pt.texture="[combine:2x2:" .. -math.random(1, 16) .. "," .. -math.random(1, 16) .. "=default_" .. liquid .. "_source_animated.png"
minetest.add_particle(pt)
minetest.after(t,function()
pt.acceleration = vector.new(0,-5,0)
pt.collisiondetection = true
pt.expirationtime = math.random() + math.random(1, interval/2)
minetest.add_particle(pt)
2022-07-20 10:27:29 +00:00
minetest.sound_play({name = "drippingwater_" .. sound .. "drip"}, {pos = pos, gain = 0.5, max_hear_distance = 8}, true)
2022-07-18 04:10:38 +00:00
end)
end)
end
local function register_drop(liquid, glow, sound, nodes, interval, chance)
2021-11-12 17:49:27 +00:00
minetest.register_abm({
label = "Create drops",
nodenames = nodes,
neighbors = {"group:" .. liquid},
2022-07-18 04:10:38 +00:00
interval = interval,
chance = chance,
2021-11-12 17:49:27 +00:00
action = function(pos)
2022-07-18 04:10:38 +00:00
local r = math.ceil(interval / 20)
local nn=minetest.find_nodes_in_area(vector.offset(pos,-r,0,-r),vector.offset(pos,r,0,r),nodes)
--start a bunch of particle cycles to be able to get away
--with longer abm cycles
table.shuffle(nn)
for i=1,math.random(#nn) do
if minetest.get_item_group(minetest.get_node(vector.offset(nn[i], 0, 1, 0)).name, liquid) ~= 0
and minetest.get_node(vector.offset(nn[i], 0, -1, 0)).name == "air" then
make_drop(nn[i],liquid,sound,interval)
end
2021-11-12 17:49:27 +00:00
end
end,
})
end
2017-01-06 01:45:04 +00:00
2022-07-18 04:10:38 +00:00
register_drop("water", 1, "", {"group:opaque", "group:leaves"},60,10)
register_drop("lava", math.max(7, minetest.registered_nodes["mcl_core:lava_source"].light_source - 3), "lava", {"group:opaque"},60,10)