From aea5c6f7bedbf3776758a61ee870e249cf0e70d5 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Tue, 16 Jan 2024 14:55:40 +0000 Subject: [PATCH 1/6] Make cactus be able to damage mobs --- mods/ITEMS/mcl_core/nodes_cactuscane.lua | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/mods/ITEMS/mcl_core/nodes_cactuscane.lua b/mods/ITEMS/mcl_core/nodes_cactuscane.lua index 79b440f61..d7abdfdf7 100644 --- a/mods/ITEMS/mcl_core/nodes_cactuscane.lua +++ b/mods/ITEMS/mcl_core/nodes_cactuscane.lua @@ -136,3 +136,40 @@ minetest.register_node("mcl_core:reeds", { _mcl_blast_resistance = 0, _mcl_hardness = 0, }) + +local function cactus_damage_check(obj) + -- where am I? + local pos = obj:get_pos() + if pos then + -- Am I near a cactus? + local near = minetest.find_node_near(pos, 1, "mcl_core:cactus") + if not near and near ~= nil then + near = find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus") + end + if near then + -- Am I touching the cactus? If so, it hurts + 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 or dist_feet < 1.1 then + if obj:get_hp() > 0 then + mcl_util.deal_damage(obj, 1, {type = "cactus"}) + end + end + end + end +end + +local etime = 0 +minetest.register_globalstep(function(dtime) + etime = dtime + etime + if etime < 0.5 then return end + etime = 0 + --for _,pl in pairs(minetest.get_connected_players()) do + --cactus_damage_check(pl) -- Another player cactus damage check code is in mcl_playerplus + --end + for _,ent in pairs(minetest.luaentities) do + if ent.is_mob then + cactus_damage_check(ent.object) + end + end +end) \ No newline at end of file From d37840e022b11a0deefc798eb0d1197f4917dccf Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Tue, 16 Jan 2024 18:53:40 +0000 Subject: [PATCH 2/6] Comment out cactus mob damage logic in preperation to move code logic to /mcl_mobs/physics.lua --- mods/ITEMS/mcl_core/nodes_cactuscane.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_cactuscane.lua b/mods/ITEMS/mcl_core/nodes_cactuscane.lua index d7abdfdf7..7f5f18966 100644 --- a/mods/ITEMS/mcl_core/nodes_cactuscane.lua +++ b/mods/ITEMS/mcl_core/nodes_cactuscane.lua @@ -137,20 +137,22 @@ minetest.register_node("mcl_core:reeds", { _mcl_hardness = 0, }) -local function cactus_damage_check(obj) +-- Moved cactus mob damage logic to /ENTITIES/mcl_mobs/physics.lua +--[[ +local function cactus_damage_check(obj, is_mob) -- where am I? local pos = obj:get_pos() if pos then -- Am I near a cactus? - local near = minetest.find_node_near(pos, 1, "mcl_core:cactus") + local near = minetest.find_node_near(pos, 1, "mcl_core:cactus", true) if not near and near ~= nil then - near = find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus") + near = find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus", true) end if near then -- Am I touching the cactus? If so, it hurts 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 or dist_feet < 1.1 then + if dist < 1.1 or dist_feet < 1.1 or (is_mob and (dist < 1.25 or dist_feet < 1.9)) then if obj:get_hp() > 0 then mcl_util.deal_damage(obj, 1, {type = "cactus"}) end @@ -169,7 +171,8 @@ minetest.register_globalstep(function(dtime) --end for _,ent in pairs(minetest.luaentities) do if ent.is_mob then - cactus_damage_check(ent.object) + cactus_damage_check(ent.object, true) end end -end) \ No newline at end of file +end) +]] \ No newline at end of file From 434bb33f72fab6883063fb6d946a4d4e3da76087 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Tue, 16 Jan 2024 18:58:38 +0000 Subject: [PATCH 3/6] Add mob cactus damage logic to /mcl_mobs/physics.lua --- mods/ENTITIES/mcl_mobs/physics.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 64bcfa822..3ca6b6122 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -761,6 +761,36 @@ function mob_class:do_env_damage() end end + -- Cactus damage + local near = minetest.find_node_near(pos, 1, "mcl_core:cactus", true) + if not near and near ~= nil then + near = find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus", true) + end + if near then + -- is mob touching the cactus? + 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.25 or dist_feet < 1.9 then + if self.health ~= 0 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 + 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 if self.breath_max ~= -1 then local drowning = false From d41d29be58c8b69797e8e615e852f85d5173e00f Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Thu, 18 Jan 2024 16:33:15 +0000 Subject: [PATCH 4/6] Add distinction between regular sized mobs and large mobs in the cactus mob damage area reach --- mods/ENTITIES/mcl_mobs/physics.lua | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 3ca6b6122..071e96631 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -770,7 +770,29 @@ function mob_class:do_env_damage() -- is mob touching the cactus? 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.25 or dist_feet < 1.9 then + local large_mob = false + if self.name == "mobs_mc:ender_dragon" or + self.name == "mobs_mc:ghast" or + self.name == "mobs_mc:guardian_elder" or + self.name == "mobs_mc:hoglin" or + self.name == "mobs_mc:zoglin" 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:mule" or + self.name == "mobs_mc:iron_golem" or + self.name == "mobs_mc:polar_bear" or + self.name == "mobs_mc:slime_big" or + self.name == "mobs_mc:magma_cube_big" or + self.name == "mobs_mc:spider" or + self.name == "mobs_mc:cave_spider" or + self.name == "mobs_mc:strider" or + self.name == "mobs_mc:wither" then + + large_mob = true + end + if (not large_mob and (dist < 1.03 or dist_feet < 1.6)) or (large_mob and (1.25 or dist_feet < 1.9)) then if self.health ~= 0 then self:damage_mob("cactus", 2) From b645a2ab673ca868f7b7680f8e461bfa86c27fc2 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sun, 21 Jan 2024 09:09:15 +0000 Subject: [PATCH 5/6] Remove commented out cactus mob damage code --- mods/ITEMS/mcl_core/nodes_cactuscane.lua | 42 +----------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/mods/ITEMS/mcl_core/nodes_cactuscane.lua b/mods/ITEMS/mcl_core/nodes_cactuscane.lua index 7f5f18966..805385124 100644 --- a/mods/ITEMS/mcl_core/nodes_cactuscane.lua +++ b/mods/ITEMS/mcl_core/nodes_cactuscane.lua @@ -135,44 +135,4 @@ minetest.register_node("mcl_core:reeds", { end, _mcl_blast_resistance = 0, _mcl_hardness = 0, -}) - --- Moved cactus mob damage logic to /ENTITIES/mcl_mobs/physics.lua ---[[ -local function cactus_damage_check(obj, is_mob) - -- where am I? - local pos = obj:get_pos() - if pos then - -- Am I near a cactus? - local near = minetest.find_node_near(pos, 1, "mcl_core:cactus", true) - if not near and near ~= nil then - near = find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, "mcl_core:cactus", true) - end - if near then - -- Am I touching the cactus? If so, it hurts - 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 or dist_feet < 1.1 or (is_mob and (dist < 1.25 or dist_feet < 1.9)) then - if obj:get_hp() > 0 then - mcl_util.deal_damage(obj, 1, {type = "cactus"}) - end - end - end - end -end - -local etime = 0 -minetest.register_globalstep(function(dtime) - etime = dtime + etime - if etime < 0.5 then return end - etime = 0 - --for _,pl in pairs(minetest.get_connected_players()) do - --cactus_damage_check(pl) -- Another player cactus damage check code is in mcl_playerplus - --end - for _,ent in pairs(minetest.luaentities) do - if ent.is_mob then - cactus_damage_check(ent.object, true) - end - end -end) -]] \ No newline at end of file +}) \ No newline at end of file From aa4f8ba6ccac8821dbf0ea48d4d0aca0f4d89941 Mon Sep 17 00:00:00 2001 From: Eliy21 Date: Sun, 21 Jan 2024 09:17:15 +0000 Subject: [PATCH 6/6] Add medium size mob distinction in the cactus mob damage area reach code --- mods/ENTITIES/mcl_mobs/physics.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 071e96631..705b22dbb 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -771,10 +771,16 @@ function mob_class:do_env_damage() local dist = vector.distance(pos, near) local dist_feet = vector.distance({x=pos.x, y=pos.y-1, z=pos.z}, near) local large_mob = false + local medium_mob = false if self.name == "mobs_mc:ender_dragon" or self.name == "mobs_mc:ghast" or self.name == "mobs_mc:guardian_elder" or - self.name == "mobs_mc:hoglin" 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:skeleton_horse" or @@ -783,16 +789,13 @@ function mob_class:do_env_damage() self.name == "mobs_mc:mule" or self.name == "mobs_mc:iron_golem" or self.name == "mobs_mc:polar_bear" or - self.name == "mobs_mc:slime_big" or - self.name == "mobs_mc:magma_cube_big" or self.name == "mobs_mc:spider" or self.name == "mobs_mc:cave_spider" or - self.name == "mobs_mc:strider" or - self.name == "mobs_mc:wither" then + self.name == "mobs_mc:strider" then - large_mob = true + medium_mob = true end - if (not large_mob and (dist < 1.03 or dist_feet < 1.6)) or (large_mob and (1.25 or dist_feet < 1.9)) then + 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 self.health ~= 0 then self:damage_mob("cactus", 2)