Merge pull request 'Color modifier for punched mobs and fixing breaking velocity when punched' (#1626) from jordan4ibanez/MineClone2:mineclone5 into mineclone5

Reviewed-on: MineClone2/MineClone2#1626
This commit is contained in:
jordan4ibanez 2021-04-23 21:28:03 +00:00
commit a6dae8e5a8
2 changed files with 18 additions and 38 deletions

View File

@ -696,6 +696,13 @@ mobs.mob_step = function(self, dtime)
return false
end
--color modifier which coincides with the pause_timer
if self.old_health and self.health < self.old_health then
self.object:set_texture_mod("^[colorize:red:120")
end
self.old_health = self.health
--do death logic (animation, poof, explosion, etc)
if self.health <= 0 then
@ -724,8 +731,9 @@ mobs.mob_step = function(self, dtime)
if self.pause_timer > 0 then
self.pause_timer = self.pause_timer - dtime
--perfectly reset pause_timer
if self.pause_timer < 0 then
if self.pause_timer <= 0 then
self.pause_timer = 0
self.object:set_texture_mod("")
end
end
--this overrides internal lua collision detection
@ -783,8 +791,9 @@ mobs.mob_step = function(self, dtime)
end
--perfectly reset pause_timer
if self.pause_timer < 0 then
if self.pause_timer <= 0 then
self.pause_timer = 0
self.object:set_texture_mod("")
end
--stop projectile mobs from being completely disabled while stunned

View File

@ -187,35 +187,14 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
-- only play hit sound and show blood effects if damage is 1 or over; lower to 0.1 to ensure armor works appropriately.
if damage >= 0.1 then
-- weapon sounds
--this doesn't work right for nodes
--[[
if weapon:get_definition().sounds ~= nil then
local s = math_random(1, #weapon:get_definition().sounds)
minetest_sound_play(weapon:get_definition().sounds[s], {
object = self.object, --hitter,
max_hear_distance = 16
}, true)
else
]]--
minetest_sound_play("default_punch", {
object = self.object,
max_hear_distance = 16
}, true)
--end
--damage_effect(self, damage)
-- do damage
self.health = self.health - damage
-- skip future functions if dead, except alerting others
--if check_for_death(self, "hit", {type = "punch", puncher = hitter}) then
-- die = true
--end
-- knock back effect
local velocity = self.object:get_velocity()
@ -244,27 +223,19 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
multiplier = knockback_enchant + 1 --(starts from 1, 1 would be no change)
end
if self.hostile then
multiplier = multiplier + 2
end
local luaentity
--[[ --why does this multiply it again???
if hitter then
luaentity = hitter:get_luaentity()
end
if hitter and is_player then
local wielditem = hitter:get_wielded_item()
kb = kb + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback")
elseif luaentity and luaentity._knockback then
kb = kb + luaentity._knockback
end
]]--
dir = vector_multiply(dir,multiplier)
dir.y = up
--add velocity breaks momentum - use set velocity
self.object:set_velocity(dir)
--add the velocity
self.object:add_velocity(dir)
--0.4 seconds until you can hurt the mob again
self.pause_timer = 0.4