mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-11 02:31:05 +01:00
Cactus damage cleanup, drop redundant conditions (#4625)
Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4625 Reviewed-by: Mikita Wiśniewski <rudzik8@protonmail.com> Co-authored-by: kno10 <erich.schubert@gmail.com> Co-committed-by: kno10 <erich.schubert@gmail.com>
This commit is contained in:
parent
fb4a6b0e7b
commit
d85febdb15
2 changed files with 60 additions and 94 deletions
|
@ -692,30 +692,22 @@ function mob_class:do_env_damage()
|
||||||
local nodef3 = minetest.registered_nodes[self.standing_under]
|
local nodef3 = minetest.registered_nodes[self.standing_under]
|
||||||
|
|
||||||
-- rain
|
-- rain
|
||||||
if self.rain_damage > 0 then
|
if self.rain_damage > 0 and mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) then
|
||||||
if mcl_weather.rain.raining and mcl_weather.is_outdoor(pos) then
|
|
||||||
self.health = self.health - self.rain_damage
|
self.health = self.health - self.rain_damage
|
||||||
|
if self:check_for_death("rain", {type = "environment", pos = pos, node = self.standing_in}) then
|
||||||
if self:check_for_death("rain", {type = "environment",
|
|
||||||
pos = pos, node = self.standing_in}) then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
pos.y = pos.y + 1 -- for particle effect position
|
pos.y = pos.y + 1 -- for particle effect position
|
||||||
|
|
||||||
-- water damage
|
-- water damage
|
||||||
if self.water_damage > 0 and nodef.groups.water then
|
if self.water_damage > 0 and nodef.groups.water then
|
||||||
if self.water_damage ~= 0 then
|
|
||||||
self.health = self.health - self.water_damage
|
self.health = self.health - self.water_damage
|
||||||
mcl_mobs.effect(pos, 5, "mcl_particles_smoke.png", nil, nil, 1, nil)
|
mcl_mobs.effect(pos, 5, "mcl_particles_smoke.png", nil, nil, 1, nil)
|
||||||
|
if self:check_for_death("water", {type = "environment", pos = pos, node = self.standing_in}) then
|
||||||
if self:check_for_death("water", {type = "environment",
|
|
||||||
pos = pos, node = self.standing_in}) then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
|
||||||
elseif self.lava_damage > 0 and (nodef.groups.lava) then
|
elseif self.lava_damage > 0 and (nodef.groups.lava) then
|
||||||
-- lava damage
|
-- lava damage
|
||||||
if self.lava_damage ~= 0 then
|
if self.lava_damage ~= 0 then
|
||||||
|
@ -730,91 +722,69 @@ function mob_class:do_env_damage()
|
||||||
end
|
end
|
||||||
elseif self.fire_damage > 0 and (nodef2.groups.fire) then
|
elseif self.fire_damage > 0 and (nodef2.groups.fire) then
|
||||||
-- magma damage
|
-- magma damage
|
||||||
if self.fire_damage ~= 0 then
|
|
||||||
self.health = self.health - self.fire_damage
|
self.health = self.health - self.fire_damage
|
||||||
|
if self:check_for_death("fire", {type = "environment", pos = pos, node = self.standing_in}) then
|
||||||
if self:check_for_death("fire", {type = "environment",
|
|
||||||
pos = pos, node = self.standing_in}) then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
|
||||||
elseif self.fire_damage > 0 and (nodef.groups.fire) then
|
elseif self.fire_damage > 0 and (nodef.groups.fire) then
|
||||||
-- fire damage
|
-- fire damage
|
||||||
if self.fire_damage ~= 0 then
|
|
||||||
self.health = self.health - self.fire_damage
|
self.health = self.health - self.fire_damage
|
||||||
mcl_mobs.effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
|
mcl_mobs.effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil)
|
||||||
mcl_burning.set_on_fire(self.object, 5)
|
mcl_burning.set_on_fire(self.object, 5)
|
||||||
|
if self:check_for_death("fire", {type = "environment", pos = pos, node = self.standing_in}) then
|
||||||
if self:check_for_death("fire", {type = "environment",
|
|
||||||
pos = pos, node = self.standing_in}) then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
|
||||||
elseif nodef.damage_per_second ~= 0 and not nodef.groups.lava and not nodef.groups.fire then
|
elseif nodef.damage_per_second ~= 0 and not nodef.groups.lava and not nodef.groups.fire then
|
||||||
-- damage_per_second node check
|
-- damage_per_second node check
|
||||||
self.health = self.health - nodef.damage_per_second
|
self.health = self.health - nodef.damage_per_second
|
||||||
mcl_mobs.effect(pos, 5, "mcl_particles_smoke.png")
|
mcl_mobs.effect(pos, 5, "mcl_particles_smoke.png")
|
||||||
|
if self:check_for_death("dps", {type = "environment", pos = pos, node = self.standing_in}) then
|
||||||
if self:check_for_death("dps", {type = "environment",
|
|
||||||
pos = pos, node = self.standing_in}) then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Cactus damage
|
-- Cactus damage
|
||||||
local near = minetest.find_node_near(pos, 1, "mcl_core:cactus", true)
|
if self.standing_on == "mcl_core:cactus" or self.standing_in == "mcl_core:cactus" or self.standing_under == "mcl_core:cactus" then
|
||||||
if not near and near ~= nil then
|
self:damage_mob("cactus", 2)
|
||||||
near = find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus", true)
|
if self:check_for_death("cactus", {type = "environment", pos = pos, node = self.standing_in}) then
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
local near = minetest.find_node_near(pos, 1, "mcl_core:cactus")
|
||||||
if near then
|
if near then
|
||||||
-- is mob touching the cactus?
|
-- is mob touching the cactus?
|
||||||
local dist = vector.distance(pos, near)
|
local dist = vector.distance(pos, near)
|
||||||
local dist_feet = vector.distance({x=pos.x, y=pos.y-1, z=pos.z}, near)
|
local threshold = 1.04 -- small mobs
|
||||||
local large_mob = false
|
-- medium mobs
|
||||||
local medium_mob = false
|
if self.name == "mobs_mc:spider" or
|
||||||
if self.name == "mobs_mc:ender_dragon" or
|
self.name == "mobs_mc:iron_golem" or
|
||||||
self.name == "mobs_mc:ghast" or
|
|
||||||
self.name == "mobs_mc:guardian_elder" or
|
|
||||||
self.name == "mobs_mc:slime_big" or
|
|
||||||
self.name == "mobs_mc:magma_cube_big" or
|
|
||||||
self.name == "mobs_mc:wither" then
|
|
||||||
|
|
||||||
large_mob = true
|
|
||||||
elseif self.name == "mobs_mc:hoglin" or
|
|
||||||
self.name == "mobs_mc:zoglin" or
|
|
||||||
self.name == "mobs_mc:horse" or
|
self.name == "mobs_mc:horse" or
|
||||||
self.name == "mobs_mc:skeleton_horse" or
|
|
||||||
self.name == "mobs_mc:zombie_horse" or
|
|
||||||
self.name == "mobs_mc:donkey" or
|
self.name == "mobs_mc:donkey" or
|
||||||
self.name == "mobs_mc:mule" or
|
self.name == "mobs_mc:mule" or
|
||||||
self.name == "mobs_mc:iron_golem" or
|
|
||||||
self.name == "mobs_mc:polar_bear" or
|
self.name == "mobs_mc:polar_bear" or
|
||||||
self.name == "mobs_mc:spider" or
|
|
||||||
self.name == "mobs_mc:cave_spider" or
|
self.name == "mobs_mc:cave_spider" or
|
||||||
self.name == "mobs_mc:strider" then
|
self.name == "mobs_mc:skeleton_horse" or
|
||||||
|
self.name == "mobs_mc:zombie_horse" or
|
||||||
medium_mob = true
|
self.name == "mobs_mc:strider" or
|
||||||
|
self.name == "mobs_mc:hoglin" or
|
||||||
|
self.name == "mobs_mc:zoglin" then
|
||||||
|
threshold = 1.165
|
||||||
|
elseif self.name == "mobs_mc:slime_big" or
|
||||||
|
self.name == "mobs_mc:magma_cube_big" or
|
||||||
|
self.name == "mobs_mc:ghast" or
|
||||||
|
self.name == "mobs_mc:guardian_elder" or
|
||||||
|
self.name == "mobs_mc:wither" or
|
||||||
|
self.name == "mobs_mc:ender_dragon" then
|
||||||
|
threshold = 1.25
|
||||||
end
|
end
|
||||||
if (not large_mob and not medium_mob and (dist < 1.03 or dist_feet < 1.6)) or (medium_mob and (dist < 1.165 or dist_feet < 1.73)) or (large_mob and (dist < 1.25 or dist_feet < 1.9)) then
|
if dist < threshold then
|
||||||
if self.health ~= 0 then
|
|
||||||
self:damage_mob("cactus", 2)
|
self:damage_mob("cactus", 2)
|
||||||
|
if self:check_for_death("cactus", {type = "environment", pos = pos, node = self.standing_in}) then
|
||||||
if self:check_for_death("cactus", {type = "environment",
|
|
||||||
pos = pos, node = self.standing_in}) then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- is mob standing on the cactus?
|
|
||||||
if self.standing_on == "mcl_core:cactus" or self.standing_in == "mcl_core:cactus" or self.standing_under == "mcl_core:cactus" then
|
|
||||||
self:damage_mob("cactus", 2)
|
|
||||||
|
|
||||||
if self:check_for_death("cactus", {type = "environment",
|
|
||||||
pos = pos, node = self.standing_in}) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Drowning damage
|
-- Drowning damage
|
||||||
if self.breath_max ~= -1 then
|
if self.breath_max ~= -1 then
|
||||||
|
|
|
@ -560,22 +560,18 @@ minetest.register_globalstep(function(dtime)
|
||||||
and (node_head ~= "ignore")
|
and (node_head ~= "ignore")
|
||||||
-- Check privilege, too
|
-- Check privilege, too
|
||||||
and (not check_player_privs(name, {noclip = true})) then
|
and (not check_player_privs(name, {noclip = true})) then
|
||||||
if player:get_hp() > 0 then
|
|
||||||
mcl_util.deal_damage(player, 1, {type = "in_wall"})
|
mcl_util.deal_damage(player, 1, {type = "in_wall"})
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- Am I near a cactus?
|
-- Am I near a cactus?
|
||||||
|
if node_stand == "mcl_core:cactus" or node_feet == "mcl_core:cactus" or node_head == "mcl_core:cactus" then
|
||||||
|
mcl_util.deal_damage(player, 1, {type = "cactus"})
|
||||||
|
else
|
||||||
local near = find_node_near(pos, 1, "mcl_core:cactus")
|
local near = find_node_near(pos, 1, "mcl_core:cactus")
|
||||||
if not near then
|
|
||||||
near = find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus")
|
|
||||||
end
|
|
||||||
if near then
|
if near then
|
||||||
-- Am I touching the cactus? If so, it hurts
|
-- Am I touching the cactus? If so, it hurts
|
||||||
local dist = vector.distance(pos, near)
|
local dist = vector.distance(pos, near)
|
||||||
local dist_feet = vector.distance({x=pos.x, y=pos.y-1, z=pos.z}, near)
|
if dist < 1.1 then
|
||||||
if dist < 1.1 or dist_feet < 1.1 then
|
|
||||||
if player:get_hp() > 0 then
|
|
||||||
mcl_util.deal_damage(player, 1, {type = "cactus"})
|
mcl_util.deal_damage(player, 1, {type = "cactus"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue