forked from VoxeLibre/VoxeLibre
Implement ability to hurt mobs
This commit is contained in:
parent
45790c0be0
commit
f9a7144b65
|
@ -650,7 +650,13 @@ mobs.mob_step = function(self, dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.pause_timer > 0 then
|
||||||
|
self.pause_timer = self.pause_timer - dtime
|
||||||
|
--don't break eye contact
|
||||||
|
if self.hostile and self.attacking then
|
||||||
|
mobs.set_yaw_while_attacking(self)
|
||||||
|
end
|
||||||
|
else
|
||||||
--jump only (like slimes)
|
--jump only (like slimes)
|
||||||
if self.jump_only then
|
if self.jump_only then
|
||||||
jump_state_switch(self, dtime)
|
jump_state_switch(self, dtime)
|
||||||
|
@ -668,6 +674,7 @@ mobs.mob_step = function(self, dtime)
|
||||||
land_state_switch(self, dtime)
|
land_state_switch(self, dtime)
|
||||||
land_state_execution(self,dtime)
|
land_state_execution(self,dtime)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,10 @@ local minetest_sound_play = minetest.sound_play
|
||||||
|
|
||||||
local math_floor = math.floor
|
local math_floor = math.floor
|
||||||
local math_min = math.min
|
local math_min = math.min
|
||||||
|
local math_random = math.random
|
||||||
|
|
||||||
local vector_direction = vector.direction
|
local vector_direction = vector.direction
|
||||||
|
local vector_multiply = vector.multiply
|
||||||
|
|
||||||
mobs.feed_tame = function(self)
|
mobs.feed_tame = function(self)
|
||||||
return nil
|
return nil
|
||||||
|
@ -149,7 +151,7 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
||||||
|
|
||||||
-- add weapon wear manually
|
-- add weapon wear manually
|
||||||
-- Required because we have custom health handling ("health" property)
|
-- Required because we have custom health handling ("health" property)
|
||||||
--minetest_is_creative_enabled("") ~= true removed for now
|
--minetest_is_creative_enabled("") ~= true --removed for now
|
||||||
if tool_capabilities then
|
if tool_capabilities then
|
||||||
if tool_capabilities.punch_attack_uses then
|
if tool_capabilities.punch_attack_uses then
|
||||||
-- Without this delay, the wear does not work. Quite hacky ...
|
-- Without this delay, the wear does not work. Quite hacky ...
|
||||||
|
@ -199,33 +201,39 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
||||||
--end
|
--end
|
||||||
|
|
||||||
-- knock back effect (only on full punch)
|
-- knock back effect (only on full punch)
|
||||||
if not die
|
if tflp >= punch_interval then
|
||||||
and self.knock_back
|
|
||||||
and tflp >= punch_interval then
|
|
||||||
|
|
||||||
local v = self.object:get_velocity()
|
local velocity = self.object:get_velocity()
|
||||||
local r = 1.4 - math_min(punch_interval, 1.4)
|
|
||||||
local kb = r * 2.0
|
--2d direction
|
||||||
local up = 2
|
local pos1 = self.object:get_pos()
|
||||||
|
pos1.y = 0
|
||||||
|
local pos2 = hitter:get_pos()
|
||||||
|
pos2.y = 0
|
||||||
|
|
||||||
|
local dir = vector.direction(pos2,pos1)
|
||||||
|
|
||||||
|
local up = 3
|
||||||
|
|
||||||
-- if already in air then dont go up anymore when hit
|
-- if already in air then dont go up anymore when hit
|
||||||
if v.y ~= 0
|
if velocity.y ~= 0 then
|
||||||
or self.fly then
|
|
||||||
up = 0
|
up = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- direction error check
|
|
||||||
dir = dir or {x = 0, y = 0, z = 0}
|
--0.75 for perfect distance to not be too easy, and not be too hard
|
||||||
|
local multiplier = 0.75
|
||||||
|
|
||||||
-- check if tool already has specific knockback value
|
-- check if tool already has specific knockback value
|
||||||
if tool_capabilities.damage_groups["knockback"] then
|
local knockback_enchant = mcl_enchanting.get_enchantment(hitter:get_wielded_item(), "knockback")
|
||||||
kb = tool_capabilities.damage_groups["knockback"]
|
if knockback_enchant and knockback_enchant > 0 then
|
||||||
else
|
multiplier = knockback_enchant + 1 --(starts from 1, 1 would be no change)
|
||||||
kb = kb * 1.5
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local luaentity
|
local luaentity
|
||||||
|
|
||||||
|
--[[ --why does this multiply it again???
|
||||||
if hitter then
|
if hitter then
|
||||||
luaentity = hitter:get_luaentity()
|
luaentity = hitter:get_luaentity()
|
||||||
end
|
end
|
||||||
|
@ -235,14 +243,16 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
||||||
elseif luaentity and luaentity._knockback then
|
elseif luaentity and luaentity._knockback then
|
||||||
kb = kb + luaentity._knockback
|
kb = kb + luaentity._knockback
|
||||||
end
|
end
|
||||||
|
]]--
|
||||||
|
|
||||||
self.object:set_velocity({
|
dir = vector_multiply(dir,multiplier)
|
||||||
x = dir.x * kb,
|
|
||||||
y = dir.y * kb + up * 2,
|
|
||||||
z = dir.z * kb
|
|
||||||
})
|
|
||||||
|
|
||||||
self.pause_timer = 0.25
|
dir.y = up
|
||||||
|
|
||||||
|
--add velocity breaks momentum - use set velocity
|
||||||
|
self.object:set_velocity(dir)
|
||||||
|
|
||||||
|
self.pause_timer = 0.4
|
||||||
end
|
end
|
||||||
end -- END if damage
|
end -- END if damage
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue