mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-01-26 00:50:21 +01:00
added new line_of_sight that uses raycasting when mt5.0 is found (thanks Astrobe)
This commit is contained in:
parent
ddbd403285
commit
392974e835
46
api.lua
46
api.lua
@ -6,7 +6,7 @@ local use_cmi = minetest.global_exists("cmi")
|
|||||||
|
|
||||||
mobs = {
|
mobs = {
|
||||||
mod = "redo",
|
mod = "redo",
|
||||||
version = "20190430",
|
version = "20190508",
|
||||||
intllib = S,
|
intllib = S,
|
||||||
invis = minetest.global_exists("invisibility") and invisibility or {},
|
invis = minetest.global_exists("invisibility") and invisibility or {},
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- check line of sight (BrunoMine)
|
-- check line of sight (BrunoMine)
|
||||||
function mob_class:line_of_sight(pos1, pos2, stepsize)
|
local line_of_sight = function(self, pos1, pos2, stepsize)
|
||||||
|
|
||||||
stepsize = stepsize or 1
|
stepsize = stepsize or 1
|
||||||
|
|
||||||
@ -401,7 +401,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- check line of sight (by BrunoMine, tweaked by Astrobe)
|
-- check line of sight (by BrunoMine, tweaked by Astrobe)
|
||||||
function mob_class:NEW_line_of_sight(pos1, pos2, stepsize)
|
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
|
||||||
|
|
||||||
@ -447,10 +447,46 @@ function mob_class:NEW_line_of_sight(pos1, pos2, stepsize)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- check line of sight using raycasting (thanks Astrobe)
|
||||||
|
local ray_line_of_sight = function(self, pos1, pos2)
|
||||||
|
|
||||||
|
local ray = minetest.raycast(pos1, pos2, true, false)
|
||||||
|
local thing = ray:next()
|
||||||
|
|
||||||
|
while thing do
|
||||||
|
|
||||||
|
if thing.type == "object"
|
||||||
|
and thing.ref ~= self.object
|
||||||
|
and not thing.ref:is_player() then return false end
|
||||||
|
|
||||||
|
if thing.type == "node" then
|
||||||
|
|
||||||
|
local name = minetest.get_node(thing.under).name
|
||||||
|
|
||||||
|
if minetest.registered_items[name].walkable then return false end
|
||||||
|
end
|
||||||
|
|
||||||
|
thing = ray:next()
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- detect if using minetest 5.0 by searching for permafrost node
|
||||||
|
local is_50 = minetest.registered_nodes["default:permafrost"]
|
||||||
|
|
||||||
|
function mob_class:line_of_sight(pos1, pos2, stepsize)
|
||||||
|
|
||||||
|
if is_50 then -- only use if minetest 5.0 is detected
|
||||||
|
return ray_line_of_sight(self, pos1, pos2)
|
||||||
|
end
|
||||||
|
|
||||||
|
return line_of_sight(self, pos1, pos2, stepsize)
|
||||||
|
end
|
||||||
|
|
||||||
-- global function
|
-- global function
|
||||||
function mobs:line_of_sight(entity, pos1, pos2, stepsize)
|
function mobs:line_of_sight(entity, pos1, pos2, stepsize)
|
||||||
|
return mob_class.line_of_sight(pos1, pos2, stepsize)
|
||||||
return mob_class.line_of_sight(entity, pos1, pos2, stepsize)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
6
api.txt
6
api.txt
@ -576,7 +576,7 @@ Certain variables need to be set before using the above functions:
|
|||||||
'self.driver_scale' sets driver scale for mobs larger than {x=1, y=1}
|
'self.driver_scale' sets driver scale for mobs larger than {x=1, y=1}
|
||||||
|
|
||||||
|
|
||||||
mobs:line_of_sight(self, pos1, pos2, stepsize)
|
mobs:line_of_sight(self, pos1, pos2, stepsize) [DEPRECATED]
|
||||||
|
|
||||||
This function is for use within the mobs definition for special use cases and
|
This function is for use within the mobs definition for special use cases and
|
||||||
returns true if a mob can see the player or victim.
|
returns true if a mob can see the player or victim.
|
||||||
@ -586,6 +586,10 @@ returns true if a mob can see the player or victim.
|
|||||||
'pos2' position of vistim or player
|
'pos2' position of vistim or player
|
||||||
'stepsize' usually set to 1
|
'stepsize' usually set to 1
|
||||||
|
|
||||||
|
Use this instead:
|
||||||
|
|
||||||
|
mob_class:line_of_sight(pos1, pos2, stepsize)
|
||||||
|
|
||||||
|
|
||||||
External Settings for "minetest.conf"
|
External Settings for "minetest.conf"
|
||||||
------------------------------------
|
------------------------------------
|
||||||
|
@ -23,6 +23,7 @@ Lucky Blocks: 9
|
|||||||
|
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
|
- 1.50 - Added new line_of_sight function that uses raycasting if mt5.0 is found (thanks Astrobe)
|
||||||
- 1.49- Added mobs:force_capture(self, player) function, api functions now use metatables thanks to bell07
|
- 1.49- Added mobs:force_capture(self, player) function, api functions now use metatables thanks to bell07
|
||||||
- 1.48- Add mobs:set_velocity(self, velocity) global function
|
- 1.48- Add mobs:set_velocity(self, velocity) global function
|
||||||
- 1.47- Mob damage changes, min and max light level for damage added, ignition sources checked for lava damage
|
- 1.47- Mob damage changes, min and max light level for damage added, ignition sources checked for lava damage
|
||||||
|
Loading…
Reference in New Issue
Block a user