forked from MineClone5/MineClone5
Fully implement zombie pigmen
This commit is contained in:
parent
964ce9ccf7
commit
6bd279255c
|
@ -3,10 +3,13 @@ local minetest_dir_to_yaw = minetest.dir_to_yaw
|
|||
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
||||
local minetest_get_node = minetest.get_node
|
||||
local minetest_get_item_group = minetest.get_item_group
|
||||
local minetest_get_objects_inside_radius = minetest.get_objects_inside_radius
|
||||
|
||||
local vector_new = vector.new
|
||||
local vector_multiply = vector.multiply
|
||||
|
||||
local table_copy = table.copy
|
||||
|
||||
-- default function when mobs are blown up with TNT
|
||||
local do_tnt = function(obj, damage)
|
||||
|
||||
|
@ -110,3 +113,56 @@ mobs.jump_check = function(self,dtime)
|
|||
--nothing to jump over
|
||||
return(0)
|
||||
end
|
||||
|
||||
-- a helper function to quickly turn neutral passive mobs hostile
|
||||
local turn_hostile = function(self,detected_mob)
|
||||
--drop in variables for attacking (stops crash)
|
||||
detected_mob.punch_timer = 0
|
||||
--set to hostile
|
||||
detected_mob.hostile = true
|
||||
--hostile_cooldown timer is initialized here
|
||||
detected_mob.hostile_cooldown_timer = detected_mob.hostile_cooldown
|
||||
--set target to the same
|
||||
detected_mob.attacking = self.attacking
|
||||
end
|
||||
|
||||
--allow hostile mobs to signal to other mobs
|
||||
--to switch from neutal passive to neutral hostile
|
||||
mobs.group_attack_initialization = function(self)
|
||||
|
||||
--get basic data
|
||||
local friends_list = table_copy(self.group_attack)
|
||||
local objects_in_area = minetest_get_objects_inside_radius(self.object:get_pos(), self.view_range)
|
||||
|
||||
--get the player's name
|
||||
local name = self.attacking:get_player_name()
|
||||
|
||||
--re-use local variable
|
||||
local detected_mob
|
||||
|
||||
--run through mobs in viewing distance
|
||||
for _,object in pairs(objects_in_area) do
|
||||
if object and object:get_luaentity() then
|
||||
detected_mob = object:get_luaentity()
|
||||
-- only alert members of same mob or friends
|
||||
if detected_mob._cmi_is_mob and detected_mob.state ~= "attack" and detected_mob.owner ~= name then
|
||||
if detected_mob.name == self.name then
|
||||
turn_hostile(self,detected_mob)
|
||||
elseif type(detected_mob.group_attack) == "table" then
|
||||
for _,id in pairs(self.group_attack) do
|
||||
if detected_mob.name == id then
|
||||
turn_hostile(self,detected_mob)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--THIS NEEDS TO BE RE-IMPLEMENTED AS A GLOBAL HIT IN MOB_PUNCH!!
|
||||
-- have owned mobs attack player threat
|
||||
--if obj.owner == name and obj.owner_loyal then
|
||||
-- do_attack(obj, self.object)
|
||||
--end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -32,6 +32,7 @@ local on_rightclick_prefix = function(self, clicker)
|
|||
return false
|
||||
end
|
||||
|
||||
-- I have no idea what this does
|
||||
mobs.create_mob_on_rightclick = function(on_rightclick)
|
||||
return function(self, clicker)
|
||||
local stop = on_rightclick_prefix(self, clicker)
|
||||
|
@ -41,13 +42,25 @@ mobs.create_mob_on_rightclick = function(on_rightclick)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
-- deal damage and effects when mob punched
|
||||
mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
||||
|
||||
--neutral passive mobs switch to neutral hostile
|
||||
if self.neutral then
|
||||
|
||||
--drop in variables for attacking (stops crash)
|
||||
self.attacking = hitter
|
||||
self.punch_timer = 0
|
||||
|
||||
self.hostile = true
|
||||
--hostile_cooldown timer is initialized here
|
||||
self.hostile_cooldown_timer = self.hostile_cooldown
|
||||
|
||||
--initialize the group attack (check for other mobs in area, make them neutral hostile)
|
||||
if self.group_attack then
|
||||
mobs.group_attack_initialization(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue