forked from VoxeLibre/VoxeLibre
Merge pull request 'Change dripping entities to particles' (#2457) from dripping_particles into master
Reviewed-on: MineClone2/MineClone2#2457 Reviewed-by: MysticTempest <mystictempest@noreply.git.minetest.land>
This commit is contained in:
commit
169a43ab08
|
@ -1,66 +1,55 @@
|
||||||
-- Dripping Water Mod
|
-- Dripping Water Mod
|
||||||
-- by kddekadenz
|
-- by kddekadenz
|
||||||
|
|
||||||
local math = math
|
|
||||||
|
|
||||||
-- License of code, textures & sounds: CC0
|
-- License of code, textures & sounds: CC0
|
||||||
|
|
||||||
local function register_drop(liquid, glow, sound, nodes)
|
local math = math
|
||||||
minetest.register_entity("mcl_dripping:drop_" .. liquid, {
|
local function make_drop(pos,liquid,sound,interval)
|
||||||
hp_max = 1,
|
local pt = {
|
||||||
physical = true,
|
velocity = vector.new(0,0,0),
|
||||||
collide_with_objects = false,
|
collision_removal = false,
|
||||||
collisionbox = {-0.01, 0.01, -0.01, 0.01, 0.01, 0.01},
|
}
|
||||||
glow = glow,
|
local t = math.random() + math.random(1, interval)
|
||||||
pointable = false,
|
minetest.after(t,function()
|
||||||
visual = "sprite",
|
local x, z = math.random(-45, 45) / 100, math.random(-45, 45) / 100
|
||||||
visual_size = {x = 0.1, y = 0.1},
|
pt.pos = vector.offset(pos,x,-0.52,z)
|
||||||
textures = {""},
|
pt.acceleration = vector.new(0,0,0)
|
||||||
spritediv = {x = 1, y = 1},
|
pt.collisiondetection = false
|
||||||
initial_sprite_basepos = {x = 0, y = 0},
|
pt.expirationtime = t
|
||||||
static_save = false,
|
|
||||||
_dropped = false,
|
pt.texture="[combine:2x2:" .. -math.random(1, 16) .. "," .. -math.random(1, 16) .. "=default_" .. liquid .. "_source_animated.png"
|
||||||
on_activate = function(self)
|
minetest.add_particle(pt)
|
||||||
self.object:set_properties({
|
minetest.after(t,function()
|
||||||
textures = {"[combine:2x2:" .. -math.random(1, 16) .. "," .. -math.random(1, 16) .. "=default_" .. liquid .. "_source_animated.png"}
|
pt.acceleration = vector.new(0,-5,0)
|
||||||
})
|
pt.collisiondetection = true
|
||||||
end,
|
pt.expirationtime = math.random() + math.random(1, interval/2)
|
||||||
on_step = function(self, dtime)
|
minetest.add_particle(pt)
|
||||||
local k = math.random(1, 222)
|
|
||||||
local ownpos = self.object:get_pos()
|
|
||||||
if k == 1 then
|
|
||||||
self.object:set_acceleration(vector.new(0, -5, 0))
|
|
||||||
end
|
|
||||||
if minetest.get_node(vector.offset(ownpos, 0, 0.5, 0)).name == "air" then
|
|
||||||
self.object:set_acceleration(vector.new(0, -5, 0))
|
|
||||||
end
|
|
||||||
if minetest.get_node(vector.offset(ownpos, 0, -0.1, 0)).name ~= "air" then
|
|
||||||
local ent = self.object:get_luaentity()
|
|
||||||
if not ent._dropped then
|
|
||||||
ent._dropped = true
|
|
||||||
minetest.sound_play({name = "drippingwater_" .. sound .. "drip"}, {pos = ownpos, gain = 0.5, max_hear_distance = 8}, true)
|
minetest.sound_play({name = "drippingwater_" .. sound .. "drip"}, {pos = ownpos, gain = 0.5, max_hear_distance = 8}, true)
|
||||||
end
|
end)
|
||||||
if k < 3 then
|
end)
|
||||||
self.object:remove()
|
end
|
||||||
end
|
|
||||||
end
|
local function register_drop(liquid, glow, sound, nodes, interval, chance)
|
||||||
end,
|
|
||||||
})
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
label = "Create drops",
|
label = "Create drops",
|
||||||
nodenames = nodes,
|
nodenames = nodes,
|
||||||
neighbors = {"group:" .. liquid},
|
neighbors = {"group:" .. liquid},
|
||||||
interval = 2,
|
interval = interval,
|
||||||
chance = 22,
|
chance = chance,
|
||||||
action = function(pos)
|
action = function(pos)
|
||||||
if minetest.get_item_group(minetest.get_node(vector.offset(pos, 0, 1, 0)).name, liquid) ~= 0
|
local r = math.ceil(interval / 20)
|
||||||
and minetest.get_node(vector.offset(pos, 0, -1, 0)).name == "air" then
|
local nn=minetest.find_nodes_in_area(vector.offset(pos,-r,0,-r),vector.offset(pos,r,0,r),nodes)
|
||||||
local x, z = math.random(-45, 45) / 100, math.random(-45, 45) / 100
|
--start a bunch of particle cycles to be able to get away
|
||||||
minetest.add_entity(vector.offset(pos, x, -0.520, z), "mcl_dripping:drop_" .. liquid)
|
--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
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
register_drop("water", 1, "", {"group:opaque", "group:leaves"})
|
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"})
|
register_drop("lava", math.max(7, minetest.registered_nodes["mcl_core:lava_source"].light_source - 3), "lava", {"group:opaque"},60,10)
|
||||||
|
|
Loading…
Reference in New Issue