mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-12 12:43:15 +01:00
Add _vl_projectile.can_punch() to mob API and move hard-coded entity behavior from arrow to rover code
This commit is contained in:
parent
d2523dcb02
commit
429b55b9c6
@ -265,6 +265,8 @@ functions needed for the mob to work properly which contains the following:
|
|||||||
'attack_frequency' Attack frequency in seconds. If unset, this defaults to 1. Implemented for melee only atm.
|
'attack_frequency' Attack frequency in seconds. If unset, this defaults to 1. Implemented for melee only atm.
|
||||||
|
|
||||||
mobs:gopath(self,target,callback_arrived) pathfind a way to target and run callback on arrival
|
mobs:gopath(self,target,callback_arrived) pathfind a way to target and run callback on arrival
|
||||||
|
'_vl_projectile' Table with Projectile API behaviors. Current members are:
|
||||||
|
'can_punch(self, projectile_luaentity)' return 'false' from this function to prevent the provided projectile from colliding with the mob
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -286,6 +286,7 @@ function mcl_mobs.register_mob(name, def)
|
|||||||
noyaw = def.noyaw or false,
|
noyaw = def.noyaw or false,
|
||||||
particlespawners = def.particlespawners,
|
particlespawners = def.particlespawners,
|
||||||
spawn_check = def.spawn_check,
|
spawn_check = def.spawn_check,
|
||||||
|
_vl_projectile = def._vl_projectile,
|
||||||
-- End of MCL2 extensions
|
-- End of MCL2 extensions
|
||||||
on_spawn = def.on_spawn,
|
on_spawn = def.on_spawn,
|
||||||
on_blast = def.on_blast or function(self,damage)
|
on_blast = def.on_blast or function(self,damage)
|
||||||
|
@ -147,6 +147,9 @@ mcl_mobs.register_mob("mobs_mc:rover", {
|
|||||||
max = 1,
|
max = 1,
|
||||||
looting = "common"},
|
looting = "common"},
|
||||||
},
|
},
|
||||||
|
_vl_projectile = {
|
||||||
|
can_punch = function() return false end
|
||||||
|
},
|
||||||
animation = select_rover_animation("normal"),
|
animation = select_rover_animation("normal"),
|
||||||
_taken_node = "",
|
_taken_node = "",
|
||||||
can_spawn = function(pos)
|
can_spawn = function(pos)
|
||||||
|
@ -87,12 +87,6 @@ local arrow_entity = {
|
|||||||
vl_projectile.collides_with_solids,
|
vl_projectile.collides_with_solids,
|
||||||
vl_projectile.raycast_collides_with_entities,
|
vl_projectile.raycast_collides_with_entities,
|
||||||
},
|
},
|
||||||
allow_punching = function(self, entity_def, projectile_def, object)
|
|
||||||
local lua = object:get_luaentity()
|
|
||||||
if lua and lua.name == "mobs_mc:rover" then return false end
|
|
||||||
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
sounds = {
|
sounds = {
|
||||||
on_entity_collision = function(self, _, _, _, obj)
|
on_entity_collision = function(self, _, _, _, obj)
|
||||||
if obj:is_player() then
|
if obj:is_player() then
|
||||||
|
@ -469,6 +469,12 @@ local function handle_entity_collision(self, entity_def, projectile_def, object)
|
|||||||
local dir = vector.normalize(self.object:get_velocity())
|
local dir = vector.normalize(self.object:get_velocity())
|
||||||
local object_lua = object:get_luaentity()
|
local object_lua = object:get_luaentity()
|
||||||
|
|
||||||
|
-- Allow entities to selectively prevent being hit
|
||||||
|
local entity_hook = object_lua and object_lua._vl_projectile and object_lua._vl_projectile.can_punch
|
||||||
|
if entity_hook and entity_hook(object_lua, self) == false then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Normally objects should be removed on collision with entities
|
-- Normally objects should be removed on collision with entities
|
||||||
local survive_collision = projectile_def.survive_collision
|
local survive_collision = projectile_def.survive_collision
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user