From f5079f15680583a824bca0d4a069af5321780343 Mon Sep 17 00:00:00 2001 From: cora Date: Wed, 15 Nov 2023 18:59:46 +0100 Subject: [PATCH] Add an option for mob arrows to be "homing" --- mods/ENTITIES/mcl_mobs/combat.lua | 3 +++ mods/ENTITIES/mcl_mobs/init.lua | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index 4396f3265..c7f8d3e84 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -1231,6 +1231,9 @@ function mob_class:do_states_attack (dtime) -- important for mcl_shields ent._shooter = self.object ent._saved_shooter_pos = self.object:get_pos() + if ent.homing then + ent._target = self.attack + end end local amount = (vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) ^ 0.5 diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index b0fc73d6e..69bd7ebf4 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -350,6 +350,7 @@ function mcl_mobs.register_arrow(name, def) hit_node = def.hit_node, hit_mob = def.hit_mob, hit_object = def.hit_object, + homing = def.homing, drop = def.drop or false, -- drops arrow as registered item when true collisionbox = {0, 0, 0, 0, 0, 0}, -- remove box around arrows timer = 0, @@ -422,6 +423,17 @@ function mcl_mobs.register_arrow(name, def) end end + if self.homing and self._target then + local p = self._target:get_pos() + if p then + if minetest.line_of_sight(self.object:get_pos(), p) then + self.object:set_velocity(vector.direction(self.object:get_pos(), p) * self.velocity) + end + else + self.target = nil + end + end + if self.hit_player or self.hit_mob or self.hit_object then for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do