diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index a7ee8b279..b9b67078d 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -2350,23 +2350,33 @@ local do_states = function(self, dtime) p.y = p.y + (self.collisionbox[2] + self.collisionbox[5]) / 2 + -- Shoot arrow if minetest.registered_entities[self.arrow] then - local obj = minetest.add_entity(p, self.arrow) - local ent = obj:get_luaentity() + local arrow, ent + local v = 1 + if not self.shoot_arrow then + arrow = minetest.add_entity(p, self.arrow) + ent = arrow:get_luaentity() + if ent.velocity then + v = ent.velocity + end + ent.switch = 1 + ent.owner_id = tostring(self.object) -- add unique owner id to arrow + end + local amount = (vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) ^ 0.5 - local v = ent.velocity or 1 -- or set to default - - ent.switch = 1 - ent.owner_id = tostring(self.object) -- add unique owner id to arrow - - -- offset makes shoot aim accurate + -- offset makes shoot aim accurate vec.y = vec.y + self.shoot_offset vec.x = vec.x * (v / amount) vec.y = vec.y * (v / amount) vec.z = vec.z * (v / amount) - - obj:set_velocity(vec) + if self.shoot_arrow then + vec = vector.normalize(vec) + self:shoot_arrow(p, vec) + else + arrow:set_velocity(vec) + end end end end @@ -3217,6 +3227,7 @@ minetest.register_entity(name, { can_despawn = can_despawn, child = def.child or false, texture_mods = {}, + shoot_arrow = def.shoot_arrow, -- End of MCL2 extensions on_spawn = def.on_spawn, diff --git a/mods/ENTITIES/mcl_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index 3321b3e74..0430bbc00 100644 --- a/mods/ENTITIES/mcl_mobs/api.txt +++ b/mods/ENTITIES/mcl_mobs/api.txt @@ -226,6 +226,9 @@ functions needed for the mob to work properly which contains the following: spawning fails due to space requirements 'glow' same as in entity definition 'child' if true, spawn mob as child + 'shoot_arrow(self, pos, dir)' function that is called when mob wants to shoot an arrow. + You can spawn your own arrow here. pos is mob position, + dir is mob's aiming direction Node Replacement diff --git a/mods/ENTITIES/mobs_mc/skeleton+stray.lua b/mods/ENTITIES/mobs_mc/skeleton+stray.lua index 04d402d8d..bb0b8d2e0 100644 --- a/mods/ENTITIES/mobs_mc/skeleton+stray.lua +++ b/mods/ENTITIES/mobs_mc/skeleton+stray.lua @@ -78,7 +78,10 @@ local skeleton = { view_range = 16, fear_height = 4, attack_type = "dogshoot", - arrow = "mobs_mc:arrow_entity", + arrow = "mcl_bows:arrow_entity", + shoot_arrow = function(self, pos, dir) + mcl_bows.shoot_arrow("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object) + end, shoot_interval = 2.5, shoot_offset = 1, dogshoot_switch = 1, diff --git a/mods/ENTITIES/mobs_mc/villager_illusioner.lua b/mods/ENTITIES/mobs_mc/villager_illusioner.lua index fe3efa8a8..82ce54a14 100644 --- a/mods/ENTITIES/mobs_mc/villager_illusioner.lua +++ b/mods/ENTITIES/mobs_mc/villager_illusioner.lua @@ -9,8 +9,11 @@ mobs:register_mob("mobs_mc:illusioner", { type = "monster", attack_type = "shoot", shoot_interval = 0.5, - arrow = "mobs_mc:arrow_entity", shoot_offset = 1.5, + arrow = "mcl_bows:arrow_entity", + shoot_arrow = function(self, pos, dir) + mcl_bows.shoot_arrow("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object) + end, hp_min = 32, hp_max = 32, collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.94, 0.3}, diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 543c573d5..4f39331d2 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -49,7 +49,7 @@ mcl_bows.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter, power, damag le._damage = damage le._startpos = pos minetest.sound_play("mcl_bows_bow_shoot", {pos=pos}) - if shooter ~= nil then + if shooter ~= nil and shooter:is_player() then if obj:get_luaentity().player == "" then obj:get_luaentity().player = shooter end