mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-26 12:31:05 +01:00
Implement ability to hurt mobs
This commit is contained in:
parent
45790c0be0
commit
f9a7144b65
2 changed files with 59 additions and 42 deletions
|
@ -650,23 +650,30 @@ mobs.mob_step = function(self, dtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.pause_timer > 0 then
|
||||||
--jump only (like slimes)
|
self.pause_timer = self.pause_timer - dtime
|
||||||
if self.jump_only then
|
--don't break eye contact
|
||||||
jump_state_switch(self, dtime)
|
if self.hostile and self.attacking then
|
||||||
jump_state_execution(self, dtime)
|
mobs.set_yaw_while_attacking(self)
|
||||||
--swimming
|
end
|
||||||
elseif self.swim then
|
|
||||||
swim_state_switch(self, dtime)
|
|
||||||
swim_state_execution(self, dtime)
|
|
||||||
--flying
|
|
||||||
elseif self.fly then
|
|
||||||
fly_state_switch(self, dtime)
|
|
||||||
fly_state_execution(self,dtime)
|
|
||||||
--regular mobs that walk around
|
|
||||||
else
|
else
|
||||||
land_state_switch(self, dtime)
|
--jump only (like slimes)
|
||||||
land_state_execution(self,dtime)
|
if self.jump_only then
|
||||||
|
jump_state_switch(self, dtime)
|
||||||
|
jump_state_execution(self, dtime)
|
||||||
|
--swimming
|
||||||
|
elseif self.swim then
|
||||||
|
swim_state_switch(self, dtime)
|
||||||
|
swim_state_execution(self, dtime)
|
||||||
|
--flying
|
||||||
|
elseif self.fly then
|
||||||
|
fly_state_switch(self, dtime)
|
||||||
|
fly_state_execution(self,dtime)
|
||||||
|
--regular mobs that walk around
|
||||||
|
else
|
||||||
|
land_state_switch(self, dtime)
|
||||||
|
land_state_execution(self,dtime)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
local minetest_after = minetest.after
|
local minetest_after = minetest.after
|
||||||
local minetest_sound_play = minetest.sound_play
|
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,8 +151,8 @@ 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 ...
|
||||||
minetest_after(0, function(name)
|
minetest_after(0, function(name)
|
||||||
|
@ -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 a new issue