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

102 lines
3.0 KiB
Lua
Raw Normal View History

2021-11-12 18:49:27 +01:00
-- Dripping Water Mod
-- by kddekadenz
2022-07-18 04:56:20 +02:00
-- License of code, textures & sounds: CC0
2017-01-06 02:45:04 +01:00
2021-05-25 00:54:12 +02:00
local math = math
2022-10-24 23:38:51 +02:00
mcl_dripping = {}
---@param pos Vector
---@param liquid string
---@param sound SimpleSoundSpec
---@param interval integer
---@param texture string
local function make_drop(pos, liquid, sound, interval, texture)
2022-07-18 06:10:38 +02:00
local pt = {
2022-10-24 23:38:51 +02:00
velocity = vector.zero(),
2022-07-18 04:56:20 +02:00
collision_removal = false,
}
2022-10-24 23:38:51 +02:00
2022-07-18 06:10:38 +02:00
local t = math.random() + math.random(1, interval)
2022-10-24 23:38:51 +02:00
minetest.after(t, function()
2022-07-18 06:10:38 +02:00
local x, z = math.random(-45, 45) / 100, math.random(-45, 45) / 100
2022-10-24 23:38:51 +02:00
pt.pos = vector.offset(pos, x, -0.52, z)
pt.acceleration = vector.zero()
2022-07-18 06:10:38 +02:00
pt.collisiondetection = false
pt.expirationtime = t
2022-07-18 04:56:20 +02:00
2022-10-24 23:38:51 +02:00
pt.texture = "[combine:2x2:" ..
-math.random(1, 16) .. "," .. -math.random(1, 16) .. "=" .. texture
2022-07-18 06:10:38 +02:00
minetest.add_particle(pt)
2022-10-24 23:38:51 +02:00
minetest.after(t, function()
pt.acceleration = vector.new(0, -5, 0)
2022-07-18 06:10:38 +02:00
pt.collisiondetection = true
2022-10-24 23:38:51 +02:00
pt.expirationtime = math.random() + math.random(1, interval / 2)
2022-07-18 06:10:38 +02:00
minetest.add_particle(pt)
2022-10-24 23:38:51 +02:00
minetest.sound_play(sound, { pos = pos, gain = 0.5, max_hear_distance = 8 },
true)
2022-07-18 06:10:38 +02:00
end)
end)
end
2022-10-24 23:38:51 +02:00
---@class mcl_dripping_drop_definition
---@field liquid string The group the liquid's nodes belong to
---@field texture string The texture used (particles will take a random 2x2 area of it)
---@field light integer Define particle glow, ranges from `0` to `minetest.LIGHT_MAX`
---@field nodes string[] The nodes (or node group) the particles will spawn under
---@field interval integer The interval for the ABM to run
---@field chance integer The chance of the ABM
---@field sound SimpleSoundSpec The sound that will be played then the particle detaches from the roof
---@param def mcl_dripping_drop_definition
function mcl_dripping.register_drop(def)
2021-11-12 18:49:27 +01:00
minetest.register_abm({
label = "Create drops",
2022-10-24 23:38:51 +02:00
nodenames = def.nodes,
neighbors = { "group:" .. def.liquid },
interval = def.interval,
chance = def.chance,
2021-11-12 18:49:27 +01:00
action = function(pos)
2022-11-02 13:02:52 +01:00
local below = minetest.get_node(vector.offset(pos,0,-1,0)).name
if below ~= "air" then return end
2022-10-24 23:38:51 +02:00
local r = math.ceil(def.interval / 20)
local nn = minetest.find_nodes_in_area(vector.offset(pos, -r, 0, -r), vector.offset(pos, r, 0, r), def.nodes)
2022-07-18 06:10:38 +02:00
--start a bunch of particle cycles to be able to get away
--with longer abm cycles
table.shuffle(nn)
2022-10-24 23:38:51 +02:00
for i = 1, math.random(#nn) do
2022-11-02 13:02:52 +01:00
if minetest.get_item_group(minetest.get_node(vector.offset(nn[i], 0, 1, 0)).name, def.liquid) ~= 0 then
2022-10-24 23:38:51 +02:00
make_drop(nn[i], def.liquid, def.sound, def.interval, def.texture)
2022-07-18 06:10:38 +02:00
end
2021-11-12 18:49:27 +01:00
end
end,
})
end
2017-01-06 02:45:04 +01:00
2022-10-24 23:38:51 +02:00
mcl_dripping.register_drop({
liquid = "water",
texture = "default_water_source_animated.png",
light = 1,
nodes = { "group:opaque", "group:leaves" },
sound = "drippingwater_drip",
2022-11-02 13:02:52 +01:00
interval = 60.3,
2022-10-24 23:38:51 +02:00
chance = 10,
})
mcl_dripping.register_drop({
liquid = "lava",
texture = "default_lava_source_animated.png",
light = math.max(7, minetest.registered_nodes["mcl_core:lava_source"].light_source - 3),
nodes = { "group:opaque" },
sound = "drippingwater_lavadrip",
2022-11-02 13:02:52 +01:00
interval = 110.1,
2022-10-24 23:38:51 +02:00
chance = 10,
})