1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-10-31 23:40:39 +01:00

if mob jumps against wall 4 times then turn, moved back to old line_of_sight function

This commit is contained in:
TenPlus1 2018-11-01 09:49:15 +00:00
parent e545cc80f4
commit 71669d3c59
2 changed files with 91 additions and 3 deletions

91
api.lua
View File

@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = { mobs = {
mod = "redo", mod = "redo",
version = "20181005", version = "20181101",
intllib = S, intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {}, invis = minetest.global_exists("invisibility") and invisibility or {},
} }
@ -255,9 +255,80 @@ function mobs:set_animation(self, anim)
end end
-- check line of sight (by BrunoMine, tweaked by Astrobe) -- check line of sight (BrunoMine)
local line_of_sight = function(self, pos1, pos2, stepsize) local line_of_sight = function(self, pos1, pos2, stepsize)
stepsize = stepsize or 1
local s, pos = minetest.line_of_sight(pos1, pos2, stepsize)
-- normal walking and flying mobs can see you through air
if s == true then
return true
end
-- New pos1 to be analyzed
local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z}
local r, pos = minetest.line_of_sight(npos1, pos2, stepsize)
-- Checks the return
if r == true then return true end
-- Nodename found
local nn = minetest.get_node(pos).name
-- Target Distance (td) to travel
local td = get_distance(pos1, pos2)
-- Actual Distance (ad) traveled
local ad = 0
-- It continues to advance in the line of sight in search of a real
-- obstruction which counts as 'normal' nodebox.
while minetest.registered_nodes[nn]
and (minetest.registered_nodes[nn].walkable == false) do
-- or minetest.registered_nodes[nn].drawtype == "nodebox") do
-- Check if you can still move forward
if td < ad + stepsize then
return true -- Reached the target
end
-- Moves the analyzed pos
local d = get_distance(pos1, pos2)
npos1.x = ((pos2.x - pos1.x) / d * stepsize) + pos1.x
npos1.y = ((pos2.y - pos1.y) / d * stepsize) + pos1.y
npos1.z = ((pos2.z - pos1.z) / d * stepsize) + pos1.z
-- NaN checks
if d == 0
or npos1.x ~= npos1.x
or npos1.y ~= npos1.y
or npos1.z ~= npos1.z then
return false
end
ad = ad + stepsize
-- scan again
r, pos = minetest.line_of_sight(npos1, pos2, stepsize)
if r == true then return true end
-- New Nodename found
nn = minetest.get_node(pos).name
end
return false
end
-- check line of sight (by BrunoMine, tweaked by Astrobe)
local NEW_line_of_sight = function(self, pos1, pos2, stepsize)
if not pos1 or not pos2 then return end if not pos1 or not pos2 then return end
stepsize = stepsize or 1 stepsize = stepsize or 1
@ -794,6 +865,22 @@ local do_jump = function(self)
self.facing_fence = true self.facing_fence = true
end end
-- if we jumped against a block/wall 4 times then turn
if self.object:get_velocity().x ~= 0
and self.object:get_velocity().z ~= 0 then
self.jump_count = (self.jump_count or 0) + 1
if self.jump_count == 4 then
local yaw = self.object:get_yaw() or 0
yaw = set_yaw(self, yaw + 1.35, 8)
self.jump_count = 0
end
end
return true return true
end end

View File

@ -126,7 +126,8 @@ functions needed for the mob to work properly which contains the following:
'pathfinding' set to 1 for mobs to use pathfinder feature to locate 'pathfinding' set to 1 for mobs to use pathfinder feature to locate
player, set to 2 so they can build/break also (only player, set to 2 so they can build/break also (only
works with dogfight attack and when 'mobs_griefing' works with dogfight attack and when 'mobs_griefing'
in minetest.conf is not false). in minetest.conf is not false). Adding {unbreakable=1}
to node groups stops them being broken by mobs.
'immune_to' is a table that holds specific damage when being hit by 'immune_to' is a table that holds specific damage when being hit by
certain items e.g. certain items e.g.
{"default:sword_wood", 0} -- causes no damage. {"default:sword_wood", 0} -- causes no damage.