From d26eb2d5a3b33ef111bcf27d7f5b34bfee0d8438 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Tue, 24 Sep 2024 07:00:03 -0500 Subject: [PATCH] Add hook to allow piercing enchantment to be implemented --- mods/ITEMS/vl_projectile/api.md | 5 ++++- mods/ITEMS/vl_projectile/init.lua | 12 ++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/vl_projectile/api.md b/mods/ITEMS/vl_projectile/api.md index da0dbcfc5..b77099cad 100644 --- a/mods/ITEMS/vl_projectile/api.md +++ b/mods/ITEMS/vl_projectile/api.md @@ -17,7 +17,10 @@ Arguments: * `damages_players`: if true, the projectile will deal damage to players. * `damage_groups`: damage group information to use for `punch()`. May be a function of type `function(projectile, entity_def, projectile_def, obj)` that returns dynamic damange group information. - * `allow_punching`: will the projectile punch entities it collides with. May be a function of type `function(projectile, entity_def, projectile_def, obj)`. + * `allow_punching`: will the projectile punch entities it collides with. May be either a boolean or a function of type `function(projectile, entity_def, projectile_def, obj)`. + * `survive_collision`: will the projectile surive collisions. May be either a boolean or a fnction of type `function(projectile, entity_def, projectile_def, type, ...)`. + * If `type` is "node" then the additional parameters `node, node_def` will be provided. + * If `type` is "entity" then the additional parameter `objet` will be provided. * `behaviors`: a list of behavior callbacks that define the projectile's behavior. This mod provides the following behaviors: `vl_projectiles.collides_with_solids`, `vl_projectiles.collides_with_entities` and `vl_projectiles.raycast_collides_with_entities` * `sounds`: sounds for this projectile. All fields take a table with three parameters corresponding to the diff --git a/mods/ITEMS/vl_projectile/init.lua b/mods/ITEMS/vl_projectile/init.lua index 0569e954f..3174c192b 100644 --- a/mods/ITEMS/vl_projectile/init.lua +++ b/mods/ITEMS/vl_projectile/init.lua @@ -240,7 +240,11 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def) end -- Normally objects should be removed on collision with solids - if not projectile_def.survive_collision then + local survive_collision = projectile_def.survive_collision + if type(survive_collision) == "function" then + survive_collision = survive_collision(self, entity_def, projectile_def, "node", node, node_def) + end + if not survive_collision then self._removed = true self.object:remove() end @@ -326,7 +330,11 @@ local function handle_entity_collision(self, entity_def, projectile_def, object) end -- Normally objects should be removed on collision with entities - if not projectile_def.survive_collision then + local survive_collision = projectile_def.survive_collision + if type(survive_collision) == "function" then + survive_collision = survive_collision(self, entity_def, projectile_def, "entity", object) + end + if not survive_collision then self._removed = true self.object:remove() end