Mobs now shoot mcl_bows:arrow_entity

This commit is contained in:
Wuzzy 2019-12-09 09:29:19 +01:00
parent 7471836c2d
commit 8a2e6d434d
5 changed files with 33 additions and 13 deletions

View File

@ -2350,23 +2350,33 @@ local do_states = function(self, dtime)
p.y = p.y + (self.collisionbox[2] + self.collisionbox[5]) / 2 p.y = p.y + (self.collisionbox[2] + self.collisionbox[5]) / 2
-- Shoot arrow
if minetest.registered_entities[self.arrow] then if minetest.registered_entities[self.arrow] then
local obj = minetest.add_entity(p, self.arrow) local arrow, ent
local ent = obj:get_luaentity() local v = 1
local amount = (vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) ^ 0.5 if not self.shoot_arrow then
local v = ent.velocity or 1 -- or set to default arrow = minetest.add_entity(p, self.arrow)
ent = arrow:get_luaentity()
if ent.velocity then
v = ent.velocity
end
ent.switch = 1 ent.switch = 1
ent.owner_id = tostring(self.object) -- add unique owner id to arrow 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
-- offset makes shoot aim accurate -- offset makes shoot aim accurate
vec.y = vec.y + self.shoot_offset vec.y = vec.y + self.shoot_offset
vec.x = vec.x * (v / amount) vec.x = vec.x * (v / amount)
vec.y = vec.y * (v / amount) vec.y = vec.y * (v / amount)
vec.z = vec.z * (v / amount) vec.z = vec.z * (v / amount)
if self.shoot_arrow then
obj:set_velocity(vec) vec = vector.normalize(vec)
self:shoot_arrow(p, vec)
else
arrow:set_velocity(vec)
end
end end
end end
end end
@ -3217,6 +3227,7 @@ minetest.register_entity(name, {
can_despawn = can_despawn, can_despawn = can_despawn,
child = def.child or false, child = def.child or false,
texture_mods = {}, texture_mods = {},
shoot_arrow = def.shoot_arrow,
-- End of MCL2 extensions -- End of MCL2 extensions
on_spawn = def.on_spawn, on_spawn = def.on_spawn,

View File

@ -226,6 +226,9 @@ functions needed for the mob to work properly which contains the following:
spawning fails due to space requirements spawning fails due to space requirements
'glow' same as in entity definition 'glow' same as in entity definition
'child' if true, spawn mob as child '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 Node Replacement

View File

@ -78,7 +78,10 @@ local skeleton = {
view_range = 16, view_range = 16,
fear_height = 4, fear_height = 4,
attack_type = "dogshoot", 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_interval = 2.5,
shoot_offset = 1, shoot_offset = 1,
dogshoot_switch = 1, dogshoot_switch = 1,

View File

@ -9,8 +9,11 @@ mobs:register_mob("mobs_mc:illusioner", {
type = "monster", type = "monster",
attack_type = "shoot", attack_type = "shoot",
shoot_interval = 0.5, shoot_interval = 0.5,
arrow = "mobs_mc:arrow_entity",
shoot_offset = 1.5, 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_min = 32,
hp_max = 32, hp_max = 32,
collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.94, 0.3}, collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.94, 0.3},

View File

@ -49,7 +49,7 @@ mcl_bows.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter, power, damag
le._damage = damage le._damage = damage
le._startpos = pos le._startpos = pos
minetest.sound_play("mcl_bows_bow_shoot", {pos=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 if obj:get_luaentity().player == "" then
obj:get_luaentity().player = shooter obj:get_luaentity().player = shooter
end end