Rearranged and slightly rewrote node_hurt function. Also added documentation on it's functionality.

This commit is contained in:
Guy Liner 2022-01-04 10:31:09 -05:00 committed by bigboi_
parent 8527a63fdc
commit 6f681b548a
1 changed files with 27 additions and 19 deletions

View File

@ -780,8 +780,29 @@ local function jump_state_execution(self, dtime)
end
--Function that will damage mob if it touch nodes like magma blocks
function node_hurt(self, dtime, cur_pos)
--The timer causes an artifical delay or 'cooldown' when mobs are hurt
--The timer will count down by subtracting dtime from itself
--dtime is the amount of time that has passed between the previous
--tick and the current one.
self.damage_timer = self.damage_timer - dtime
--gets the current position of the mob
cur_pos['y'] = cur_pos['y'] - 1
-- If the block below the mob is a magma block it gets hurt every half a second
if minetest.get_node(cur_pos).name == 'mcl_nether:magma' and self.health > 0 and self.damage_timer <= 0 then
print(minetest.get_node(cur_pos).name)
-- If the mobs hp is greater than zero, it gets hurt.
mcl_util.deal_damage(self.object, 1, {type = "hot_floor"})
--pause_timer reset to 1
self.damage_timer = 1
end
end
--[[
___ ___ _ _ _
| \/ | (_) | | (_)
@ -794,27 +815,14 @@ ___ ___ _ _ _
]]--
--the main loop
--this function will be called on every single globalstep, for each invidivual
--this function will be called on every single tick, for each invidivual
--instance of a mob object
local timer = 0
function mobs.mob_step(self, dtime) timer = timer + dtime;
--gets the current position of the mob
function mobs.mob_step(self, dtime)
--pulls the mob's current position
local cur_pos = self.object:get_pos()
cur_pos['y'] = cur_pos['y'] - 1
print(timer)
-- If the block below the mob is a magma block it gets hurt every half a second
if minetest.get_node(cur_pos).name == 'mcl_nether:magma' and timer >= 0.5 then
print(minetest.get_node(cur_pos).name)
-- If the mobs hp is greater than zero, it gets hurt.
if self.health > 0 then
mcl_util.deal_damage(self.object, 1, {type = "hot_floor"})
timer = 0
end
end
--checks if the node is on a bad block
node_hurt(self,dtime, cur_pos)
--do not continue if non-existent
if not self or not self.object or not self.object:get_luaentity() then