1
0
Fork 0

Re-enable mob punching (broken)

This commit is contained in:
jordan4ibanez 2021-04-22 19:12:02 -04:00
parent 31a791c33b
commit 45790c0be0
2 changed files with 26 additions and 92 deletions

View File

@ -120,7 +120,7 @@ end
-- creative check -- creative check
function mobs.is_creative(name) function mobs.is_creative(name)
return minetest.is_creative_enabled(name) return minetest_is_creative_enabled(name)
end end

View File

@ -1,4 +1,9 @@
local minetest_after = minetest.after
local minetest_sound_play = minetest.sound_play
local math_floor = math.floor local math_floor = math.floor
local math_min = math.min
local vector_direction = vector.direction local vector_direction = vector.direction
mobs.feed_tame = function(self) mobs.feed_tame = function(self)
@ -65,34 +70,24 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
end end
--[[
-- custom punch function -- custom punch function
if self.do_punch then if self.do_punch then
-- when false skip going any further -- when false skip going any further
if self.do_punch(self, hitter, tflp, tool_capabilities, dir) == false then if self.do_punch(self, hitter, tflp, tool_capabilities, dir) == false then
return return
end end
end end
-- error checking when mod profiling is enabled -- error checking when mod profiling is enabled
if not tool_capabilities then if not tool_capabilities then
minetest.log("warning", "[mobs] Mod profiling enabled, damage not enabled") minetest.log("warning", "[mobs_mc] Mod profiling enabled, damage not enabled")
return return
end end
local is_player = hitter:is_player() local is_player = hitter:is_player()
if is_player then
-- is mob protected?
if self.protected and minetest_is_protected(self.object:get_pos(), hitter:get_player_name()) then
return
end
-- set/update 'drop xp' timestamp if hitted by player
self.xp_timestamp = minetest_get_us_time()
end
-- punch interval -- punch interval
local weapon = hitter:get_wielded_item() local weapon = hitter:get_wielded_item()
@ -113,10 +108,6 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
tflp = 0.2 tflp = 0.2
end end
if use_cmi then
damage = cmi.calculate_damage(self.object, hitter, tflp, tool_capabilities, dir)
else
for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do
tmp = tflp / (tool_capabilities.full_punch_interval or 1.4) tmp = tflp / (tool_capabilities.full_punch_interval or 1.4)
@ -130,7 +121,6 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
damage = damage + (tool_capabilities.damage_groups[group] or 0) damage = damage + (tool_capabilities.damage_groups[group] or 0)
* tmp * ((armor[group] or 0) / 100.0) * tmp * ((armor[group] or 0) / 100.0)
end end
end
if weapon then if weapon then
local fire_aspect_level = mcl_enchanting.get_enchantment(weapon, "fire_aspect") local fire_aspect_level = mcl_enchanting.get_enchantment(weapon, "fire_aspect")
@ -141,9 +131,7 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
-- check for tool immunity or special damage -- check for tool immunity or special damage
for n = 1, #self.immune_to do for n = 1, #self.immune_to do
if self.immune_to[n][1] == weapon:get_name() then if self.immune_to[n][1] == weapon:get_name() then
damage = self.immune_to[n][2] or 0 damage = self.immune_to[n][2] or 0
break break
end end
@ -155,21 +143,14 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
return return
end end
if use_cmi then
local cancel = cmi.notify_punch(self.object, hitter, tflp, tool_capabilities, dir, damage)
if cancel then return end
end
if tool_capabilities then if tool_capabilities then
punch_interval = tool_capabilities.full_punch_interval or 1.4 punch_interval = tool_capabilities.full_punch_interval or 1.4
end end
-- 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)
if minetest_is_creative_enabled("") ~= true --minetest_is_creative_enabled("") ~= true removed for now
and 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)
@ -207,15 +188,15 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
}, true) }, true)
end end
damage_effect(self, damage) --damage_effect(self, damage)
-- do damage -- do damage
self.health = self.health - damage self.health = self.health - damage
-- skip future functions if dead, except alerting others -- skip future functions if dead, except alerting others
if check_for_death(self, "hit", {type = "punch", puncher = hitter}) then --if check_for_death(self, "hit", {type = "punch", puncher = hitter}) then
die = true -- die = true
end --end
-- knock back effect (only on full punch) -- knock back effect (only on full punch)
if not die if not die
@ -266,6 +247,7 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
end -- END if damage end -- END if damage
-- if skittish then run away -- if skittish then run away
--[[
if not die and self.runaway == true and self.state ~= "flop" then if not die and self.runaway == true and self.state ~= "flop" then
local lp = hitter:get_pos() local lp = hitter:get_pos()
@ -288,54 +270,6 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
self.following = nil self.following = nil
end end
local name = hitter:get_player_name() or ""
-- attack puncher and call other mobs for help
if self.passive == false
and self.state ~= "flop"
and (self.child == false or self.type == "monster")
and hitter:get_player_name() ~= self.owner
and not mobs.invis[ name ] then
if not die then
-- attack whoever punched mob
self.state = ""
do_attack(self, hitter)
end
-- alert others to the attack
local objs = minetest_get_objects_inside_radius(hitter:get_pos(), self.view_range)
local obj = nil
for n = 1, #objs do
obj = objs[n]:get_luaentity()
if obj then
-- only alert members of same mob or friends
if obj.group_attack
and obj.state ~= "attack"
and obj.owner ~= name then
if obj.name == self.name then
do_attack(obj, hitter)
elseif type(obj.group_attack) == "table" then
for i=1, #obj.group_attack do
if obj.name == obj.group_attack[i] then
do_attack(obj, hitter)
break
end
end
end
end
-- have owned mobs attack player threat
if obj.owner == name and obj.owner_loyal then
do_attack(obj, self.object)
end
end
end
end
]]-- ]]--
end end