From 55c8f4cb849c3f76d4a6890bad7e76f1cba42158 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 7 Sep 2024 21:26:37 -0500 Subject: [PATCH] Fix splash potions, fix crash when projectiles hit unknown nodes --- mods/ITEMS/mcl_potions/splash.lua | 52 +++++++++++++++++-------------- mods/ITEMS/vl_projectile/init.lua | 2 +- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/mods/ITEMS/mcl_potions/splash.lua b/mods/ITEMS/mcl_potions/splash.lua index 35120e16d..a8e1c73a4 100644 --- a/mods/ITEMS/mcl_potions/splash.lua +++ b/mods/ITEMS/mcl_potions/splash.lua @@ -112,30 +112,13 @@ function mcl_potions.register_splash(name, descr, color, def) }) end - vl_projectile.register(id.."_flying",{ - textures = {splash_image(color)}, - hp_max = 1, - visual_size = {x=w/2,y=w/2}, - collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1}, - _vl_projectile = { - behaviors = { - vl_projectile.collides_with_entities, - vl_projectile.collides_with_solids, - }, - on_collide_with_solid = function(self, pos, node) - make_particles(pos) - - if node.name == "mcl_target:target_off" then - mcl_target.hit(pos, 0.4) -- 4 redstone ticks - end - end, - on_collide_with_entity = function(self, pos, obj) - make_particles(pos) - - -- Make sure the potion can interact with this object - local entity = obj:get_luaentity() - if not obj:is_player() and not (entity and entity.is_mob) then return end + function splash_effects(self, pos, def, range) + make_particles(pos) + for _,obj in pairs(minetest.get_objects_inside_radius(pos, range)) do + -- Make sure the potion can interact with this object + local entity = obj:get_luaentity() + if obj:is_player() or entity and entity.is_mob then local potency = self._potency or 0 local plus = self._plus or 0 @@ -182,6 +165,29 @@ function mcl_potions.register_splash(name, descr, color, def) def.custom_effect(obj, power, plus) end end + end + end + end + + vl_projectile.register(id.."_flying",{ + textures = {splash_image(color)}, + hp_max = 1, + visual_size = {x=w/2,y=w/2}, + collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1}, + _vl_projectile = { + behaviors = { + vl_projectile.collides_with_entities, + vl_projectile.collides_with_solids, + }, + on_collide_with_solid = function(self, pos, node) + splash_effects(self, pos, def, 4) + + if node.name == "mcl_target:target_off" then + mcl_target.hit(pos, 0.4) -- 4 redstone ticks + end + end, + on_collide_with_entity = function(self, pos, obj) + splash_effects(self, pos, def, 4) end, sounds = { on_collision = {"mcl_potions_breaking_glass", {max_hear_distance = 16, gain = 1}, true}, diff --git a/mods/ITEMS/vl_projectile/init.lua b/mods/ITEMS/vl_projectile/init.lua index 10449619d..79da4e953 100644 --- a/mods/ITEMS/vl_projectile/init.lua +++ b/mods/ITEMS/vl_projectile/init.lua @@ -216,7 +216,7 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def) hook(self, pos, node, node_def) -- Call node collided hook - local hook = (node_def._vl_projectile or {}).on_collide or no_op + local hook = ((node_def and node_def._vl_projectile) or {}).on_collide or no_op hook(self, pos, node, node_def) -- Play sounds