From da4aa9bc35abd3e4ee28d8678fdad7a2613c6423 Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 18 Jul 2022 01:51:21 +0200 Subject: [PATCH 1/3] improve crying obsidian visuals --- mods/ITEMS/mcl_core/functions.lua | 67 +++++++++---------------------- 1 file changed, 18 insertions(+), 49 deletions(-) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index c56ae51c3..c9caf9423 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -1702,41 +1702,14 @@ end -- Obsidian crying -local crobby_psdef = { - amount = 1, - time = 0.9, --everything longer than 1 is a coord exploit - minvel = vector.new(0,-2,0), - maxvel = vector.new(0,-0.5,0), - minacc = vector.new(0,-10,0), - maxacc = vector.new(0,-8,0), - minexptime = 1, - maxexptime = 6, - minsize = 1.5, - maxsize = 2, - collisiondetection = true, - collision_removal = true, - object_collision = true, - vertical = true, - texture = "mcl_core_crying_obsidian_tear.png", -} -local crobby_psdef2 = { - amount = 1, - time = 0.9, --everything longer than 1 is a coord exploit - minvel = vector.new(0,-0.01,0), - maxvel = vector.new(0,-0.005,0), - minacc = vector.new(0,-0.1,0), - maxacc = vector.new(0,-0.01,0), - minexptime = 2, - maxexptime = 3, - minsize = 0.3, - maxsize = 0.6, - collisiondetection = true, - collision_removal = true, - object_collision = true, - vertical = true, - texture = "mcl_core_crying_obsidian_tear.png", +local crobby_particle = { + velocity = vector.new(0,0,0), + size = math.random(1.3,2.5), + texture = "mcl_core_crying_obsidian_tear.png", + collision_removal = false, } + minetest.register_abm({ label = "Obsidian cries", nodenames = {"mcl_core:crying_obsidian"}, @@ -1744,22 +1717,18 @@ minetest.register_abm({ chance = 10, action = function(pos, node) minetest.after(math.random(0.1,1.5),function() - crobby_psdef.minpos = vector.offset(pos,-0.6,-0.51,-0.6) - crobby_psdef.maxpos = vector.offset(pos,0.6,0.51,0.6) - minetest.add_particlespawner(crobby_psdef) - crobby_psdef2.minpos = vector.offset(pos,-0.51,-0.51,-0.51) - crobby_psdef2.maxpos = vector.offset(pos,-0.5,0.51,-0.5) - minetest.add_particlespawner(crobby_psdef2) - crobby_psdef2.minpos = vector.offset(pos,0.51,-0.51,-0.51) - crobby_psdef2.maxpos = vector.offset(pos,0.5,0.51,-0.5) - minetest.add_particlespawner(crobby_psdef2) - crobby_psdef2.minpos = vector.offset(pos,0.51,-0.51,0.51) - crobby_psdef2.maxpos = vector.offset(pos,0.5,0.51,0.5) - minetest.add_particlespawner(crobby_psdef2) - crobby_psdef2.minpos = vector.offset(pos,-0.51,-0.51,0.51) - crobby_psdef2.maxpos = vector.offset(pos,-0.5,0.51,0.5) - minetest.add_particlespawner(crobby_psdef2) - + local pt = table.copy(crobby_particle) + pt.acceleration = vector.new(0,0,0) + pt.collisiondetection = false + pt.expirationtime = math.random(0.5,1.5) + pt.pos = vector.offset(pos,math.random(-0.5,0.5),-0.51,math.random(-0.5,0.5)) + minetest.add_particle(pt) + minetest.after(pt.expirationtime,function() + pt.acceleration = vector.new(0,-9,0) + pt.collisiondetection = true + pt.expirationtime = math.random(1.2,4.5) + minetest.add_particle(pt) + end) end) end }) From 0298cecbcda94c2d1a5380d1cf286bb4365b1a4b Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 18 Jul 2022 04:56:20 +0200 Subject: [PATCH 2/3] change dripping entities to particles --- mods/ENTITIES/mcl_dripping/init.lua | 71 +++++++++++------------------ 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/mods/ENTITIES/mcl_dripping/init.lua b/mods/ENTITIES/mcl_dripping/init.lua index 57ba7ecfe..5d4d8fa49 100644 --- a/mods/ENTITIES/mcl_dripping/init.lua +++ b/mods/ENTITIES/mcl_dripping/init.lua @@ -1,51 +1,16 @@ -- Dripping Water Mod -- by kddekadenz +-- License of code, textures & sounds: CC0 local math = math --- License of code, textures & sounds: CC0 - local function register_drop(liquid, glow, sound, nodes) - minetest.register_entity("mcl_dripping:drop_" .. liquid, { - hp_max = 1, - physical = true, - collide_with_objects = false, - collisionbox = {-0.01, 0.01, -0.01, 0.01, 0.01, 0.01}, - glow = glow, - pointable = false, - visual = "sprite", - visual_size = {x = 0.1, y = 0.1}, - textures = {""}, - spritediv = {x = 1, y = 1}, - initial_sprite_basepos = {x = 0, y = 0}, - static_save = false, - _dropped = false, - on_activate = function(self) - self.object:set_properties({ - textures = {"[combine:2x2:" .. -math.random(1, 16) .. "," .. -math.random(1, 16) .. "=default_" .. liquid .. "_source_animated.png"} - }) - end, - on_step = function(self, dtime) - 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) - end - if k < 3 then - self.object:remove() - end - end - end, - }) + + local pdef = { + velocity = vector.new(0,0,0), + collision_removal = false, + } + minetest.register_abm({ label = "Create drops", nodenames = nodes, @@ -55,12 +20,28 @@ local function register_drop(liquid, glow, sound, nodes) action = function(pos) if minetest.get_item_group(minetest.get_node(vector.offset(pos, 0, 1, 0)).name, liquid) ~= 0 and minetest.get_node(vector.offset(pos, 0, -1, 0)).name == "air" then - local x, z = math.random(-45, 45) / 100, math.random(-45, 45) / 100 - minetest.add_entity(vector.offset(pos, x, -0.520, z), "mcl_dripping:drop_" .. liquid) + minetest.after(math.random(0.1,1.5),function() + local pt = table.copy(pdef) + 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 = math.random(9.5,28.5) + + pt.texture="[combine:2x2:" .. -math.random(1, 16) .. "," .. -math.random(1, 16) .. "=default_" .. liquid .. "_source_animated.png" + minetest.add_particle(pt) + minetest.after(pt.expirationtime,function() + pt.acceleration = vector.new(0,-5,0) + pt.collisiondetection = true + pt.expirationtime = math.random(6.2,17.5) + minetest.add_particle(pt) + minetest.sound_play({name = "drippingwater_" .. sound .. "drip"}, {pos = ownpos, gain = 0.5, max_hear_distance = 8}, true) + end) + end) end end, }) end register_drop("water", 1, "", {"group:opaque", "group:leaves"}) -register_drop("lava", math.max(7, minetest.registered_nodes["mcl_core:lava_source"].light_source - 3), "lava", {"group:opaque"}) \ No newline at end of file +register_drop("lava", math.max(7, minetest.registered_nodes["mcl_core:lava_source"].light_source - 3), "lava", {"group:opaque"}) From d89ef0581f126e6dbece16760b61f238d78bd7af Mon Sep 17 00:00:00 2001 From: cora Date: Mon, 18 Jul 2022 06:10:38 +0200 Subject: [PATCH 3/3] Optimize ABMs --- mods/ENTITIES/mcl_dripping/init.lua | 64 ++++++++++++++++------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/mods/ENTITIES/mcl_dripping/init.lua b/mods/ENTITIES/mcl_dripping/init.lua index 5d4d8fa49..96bc0b839 100644 --- a/mods/ENTITIES/mcl_dripping/init.lua +++ b/mods/ENTITIES/mcl_dripping/init.lua @@ -3,45 +3,53 @@ -- License of code, textures & sounds: CC0 local math = math - -local function register_drop(liquid, glow, sound, nodes) - - local pdef = { +local function make_drop(pos,liquid,sound,interval) + local pt = { velocity = vector.new(0,0,0), collision_removal = false, } + 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 + 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) + minetest.sound_play({name = "drippingwater_" .. sound .. "drip"}, {pos = ownpos, gain = 0.5, max_hear_distance = 8}, true) + end) + end) +end + +local function register_drop(liquid, glow, sound, nodes, interval, chance) minetest.register_abm({ label = "Create drops", nodenames = nodes, neighbors = {"group:" .. liquid}, - interval = 2, - chance = 22, + interval = interval, + chance = chance, action = function(pos) - if minetest.get_item_group(minetest.get_node(vector.offset(pos, 0, 1, 0)).name, liquid) ~= 0 - and minetest.get_node(vector.offset(pos, 0, -1, 0)).name == "air" then - minetest.after(math.random(0.1,1.5),function() - local pt = table.copy(pdef) - 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 = math.random(9.5,28.5) - - pt.texture="[combine:2x2:" .. -math.random(1, 16) .. "," .. -math.random(1, 16) .. "=default_" .. liquid .. "_source_animated.png" - minetest.add_particle(pt) - minetest.after(pt.expirationtime,function() - pt.acceleration = vector.new(0,-5,0) - pt.collisiondetection = true - pt.expirationtime = math.random(6.2,17.5) - minetest.add_particle(pt) - minetest.sound_play({name = "drippingwater_" .. sound .. "drip"}, {pos = ownpos, gain = 0.5, max_hear_distance = 8}, true) - end) - end) + 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 end end, }) end -register_drop("water", 1, "", {"group:opaque", "group:leaves"}) -register_drop("lava", math.max(7, minetest.registered_nodes["mcl_core:lava_source"].light_source - 3), "lava", {"group:opaque"}) +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)