mirror of
https://git.minetest.land/Mineclonia/Mineclonia.git
synced 2024-11-24 11:15:12 +00:00
Mobs now shoot mcl_bows:arrow_entity
This commit is contained in:
parent
7471836c2d
commit
8a2e6d434d
5 changed files with 33 additions and 13 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue