diff --git a/mods/ENTITIES/mcl_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index 06e92c7ee..bf903ded0 100644 --- a/mods/ENTITIES/mcl_mobs/api.txt +++ b/mods/ENTITIES/mcl_mobs/api.txt @@ -265,6 +265,8 @@ functions needed for the mob to work properly which contains the following: 'attack_frequency' Attack frequency in seconds. If unset, this defaults to 1. Implemented for melee only atm. mobs:gopath(self,target,callback_arrived) pathfind a way to target and run callback on arrival + '_vl_projectile' Table with Projectile API behaviors. Current members are: + 'can_punch(self, projectile_luaentity)' return 'false' from this function to prevent the provided projectile from colliding with the mob diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index 62db6a7f8..ccb7eaade 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -286,6 +286,7 @@ function mcl_mobs.register_mob(name, def) noyaw = def.noyaw or false, particlespawners = def.particlespawners, spawn_check = def.spawn_check, + _vl_projectile = def._vl_projectile, -- End of MCL2 extensions on_spawn = def.on_spawn, on_blast = def.on_blast or function(self,damage) diff --git a/mods/ENTITIES/mobs_mc/rover.lua b/mods/ENTITIES/mobs_mc/rover.lua index 3a07f2d36..a16ee8c38 100644 --- a/mods/ENTITIES/mobs_mc/rover.lua +++ b/mods/ENTITIES/mobs_mc/rover.lua @@ -147,6 +147,9 @@ mcl_mobs.register_mob("mobs_mc:rover", { max = 1, looting = "common"}, }, + _vl_projectile = { + can_punch = function() return false end + }, animation = select_rover_animation("normal"), _taken_node = "", can_spawn = function(pos) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 3a42b0103..14ada2d98 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -87,12 +87,6 @@ local arrow_entity = { vl_projectile.collides_with_solids, vl_projectile.raycast_collides_with_entities, }, - allow_punching = function(self, entity_def, projectile_def, object) - local lua = object:get_luaentity() - if lua and lua.name == "mobs_mc:rover" then return false end - - return true - end, sounds = { on_entity_collision = function(self, _, _, _, obj) if obj:is_player() then diff --git a/mods/ITEMS/vl_projectile/init.lua b/mods/ITEMS/vl_projectile/init.lua index 25c4a8ba9..9dd9bbcb5 100644 --- a/mods/ITEMS/vl_projectile/init.lua +++ b/mods/ITEMS/vl_projectile/init.lua @@ -469,6 +469,12 @@ local function handle_entity_collision(self, entity_def, projectile_def, object) local dir = vector.normalize(self.object:get_velocity()) local object_lua = object:get_luaentity() + -- Allow entities to selectively prevent being hit + local entity_hook = object_lua and object_lua._vl_projectile and object_lua._vl_projectile.can_punch + if entity_hook and entity_hook(object_lua, self) == false then + return + end + -- Normally objects should be removed on collision with entities local survive_collision = projectile_def.survive_collision