forked from VoxeLibre/VoxeLibre
Compare commits
8 Commits
master
...
magma-orig
Author | SHA1 | Date |
---|---|---|
Guy Liner | dab470c37d | |
GuyLiner | de6bde0027 | |
Guy Liner | 26c7b1a5d1 | |
Guy Liner | 6f681b548a | |
Guy Liner | 8527a63fdc | |
Guy Liner | f4ff86257f | |
Guy Liner | 15c2565f14 | |
Guy Liner | 69ddb61a7e |
|
@ -151,7 +151,12 @@ mobs.spawning_mobs = {}
|
|||
|
||||
|
||||
|
||||
-- register mob entity
|
||||
-- This method registers a mob entity, The internal logic of the function is basically
|
||||
-- to account for collision boxes and then account for the world difficulty.
|
||||
-- After that, the minetest.register_entity method is called.
|
||||
-- An object called 'def' is sent to the method, which contains all of
|
||||
-- the possible attributes that a mob entity can have.
|
||||
|
||||
function mobs:register_mob(name, def)
|
||||
|
||||
local collisionbox = def.collisionbox or {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25}
|
||||
|
@ -174,6 +179,7 @@ function mobs:register_mob(name, def)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_entity(name, {
|
||||
description = def.description,
|
||||
use_texture_alpha = def.use_texture_alpha,
|
||||
|
@ -243,6 +249,7 @@ function mobs:register_mob(name, def)
|
|||
env_damage_timer = 0,
|
||||
tamed = false,
|
||||
pause_timer = 0,
|
||||
damage_timer = 0, --for determining damage cooldown aka brief immunity
|
||||
gotten = false,
|
||||
reach = def.reach or 3,
|
||||
htimer = 0,
|
||||
|
@ -408,6 +415,7 @@ function mobs:register_mob(name, def)
|
|||
|
||||
on_step = mobs.mob_step,
|
||||
|
||||
|
||||
--do_punch = def.do_punch,
|
||||
|
||||
on_punch = mobs.mob_punch,
|
||||
|
@ -430,6 +438,7 @@ function mobs:register_mob(name, def)
|
|||
--harmed_by_heal = def.harmed_by_heal,
|
||||
})
|
||||
|
||||
|
||||
if minetest_get_modpath("doc_identifier") then
|
||||
doc.sub.identifier.register_object(name, "basics", "mobs")
|
||||
end
|
||||
|
|
|
@ -780,8 +780,26 @@ 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
|
||||
|
||||
--This gets the coords of the node below 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
|
||||
-- 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,7 +812,14 @@ ___ ___ _ _ _
|
|||
]]--
|
||||
|
||||
--the main loop
|
||||
--this function will be called on every single tick, for each invidivual
|
||||
--instance of a mob object
|
||||
function mobs.mob_step(self, dtime)
|
||||
--pulls the mob's current position
|
||||
local cur_pos = self.object:get_pos()
|
||||
|
||||
--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
|
||||
|
@ -831,17 +856,28 @@ function mobs.mob_step(self, dtime)
|
|||
end
|
||||
|
||||
--color modifier which coincides with the pause_timer
|
||||
|
||||
--If self.old_health exists and self.health is less than self.old_health this will run
|
||||
if self.old_health and self.health < self.old_health then
|
||||
self.object:set_texture_mod("^[colorize:red:120")
|
||||
--fix double death sound
|
||||
if self.health > 0 then
|
||||
mobs.play_sound(self,"damage")
|
||||
end
|
||||
|
||||
--Basically here to make sure there is no way that the mob will get stuck
|
||||
--on the colorized red texture
|
||||
elseif self.health >= 0 then
|
||||
self.object:set_texture_mod("^[colorize:red:0")
|
||||
end
|
||||
|
||||
--Set the old_heath to the new health to make sure on the next loop
|
||||
--iteration things are evaluated correctly
|
||||
self.old_health = self.health
|
||||
|
||||
--do death logic (animation, poof, explosion, etc)
|
||||
if self.health <= 0 or self.dead then
|
||||
self.object:set_texture_mod("^[colorize:red:120")
|
||||
--play death sound once
|
||||
if not self.played_death_sound then
|
||||
self.dead = true
|
||||
|
|
|
@ -202,7 +202,7 @@ mobs.node_ok = function(pos, fallback)
|
|||
end
|
||||
|
||||
|
||||
--a teleport functoin
|
||||
--a teleport function
|
||||
mobs.teleport = function(self, target)
|
||||
if self.do_teleport then
|
||||
if self.do_teleport(self, target) == false then
|
||||
|
@ -247,4 +247,4 @@ mobs.calculate_fall_damage = function(self)
|
|||
self.health = self.health - damage
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue