From 6951ecdfc9fc5310f7fb3a11ce0058cc9a828baf Mon Sep 17 00:00:00 2001 From: epCode Date: Wed, 17 Mar 2021 13:47:02 -0700 Subject: [PATCH 1/8] Let players shoot themselves with regular arrows --- mods/ITEMS/mcl_bows/arrow.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 035dd122..6952f594 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -136,6 +136,8 @@ end ARROW_ENTITY.on_step = function(self, dtime) mcl_burning.tick(self.object, dtime) + self._time_in_air = self._time_in_air + .001 + local pos = self.object:get_pos() local dpos = table.copy(pos) -- digital pos dpos = vector.round(dpos) @@ -201,10 +203,10 @@ ARROW_ENTITY.on_step = function(self, dtime) for k, obj in pairs(objs) do local ok = false -- Arrows can only damage players and mobs - if obj ~= self._shooter and obj:is_player() then + if obj:is_player() then ok = true elseif obj:get_luaentity() ~= nil then - if obj ~= self._shooter and (obj:get_luaentity()._cmi_is_mob or obj:get_luaentity()._hittable_by_projectile) then + if obj:get_luaentity()._cmi_is_mob or obj:get_luaentity()._hittable_by_projectile then ok = true end end @@ -226,7 +228,7 @@ ARROW_ENTITY.on_step = function(self, dtime) local obj = closest_object local is_player = obj:is_player() local lua = obj:get_luaentity() - if obj ~= self._shooter and (is_player or (lua and (lua._cmi_is_mob or lua._hittable_by_projectile))) then + if obj == self._shooter and self._time_in_air > 1.02 or obj ~= self._shooter and (is_player or (lua and (lua._cmi_is_mob or lua._hittable_by_projectile))) then if obj:get_hp() > 0 then -- Check if there is no solid node between arrow and object local ray = minetest.raycast(self.object:get_pos(), obj:get_pos(), true) @@ -411,6 +413,7 @@ end ARROW_ENTITY.on_activate = function(self, staticdata, dtime_s) local data = minetest.deserialize(staticdata) + self._time_in_air = 1.0 if data then self._stuck = data.stuck if data.stuck then From 8ed5fd47407a1cdddd74591585a2cd00aebeab3e Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 11 Jul 2021 19:37:01 +0200 Subject: [PATCH 2/8] Let players shoot themselves with potion arrows --- mods/ITEMS/mcl_potions/tipped_arrow.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_potions/tipped_arrow.lua b/mods/ITEMS/mcl_potions/tipped_arrow.lua index 2853487c..2fd9933a 100644 --- a/mods/ITEMS/mcl_potions/tipped_arrow.lua +++ b/mods/ITEMS/mcl_potions/tipped_arrow.lua @@ -130,6 +130,8 @@ function mcl_potions.register_arrow(name, desc, color, def) end ARROW_ENTITY.on_step = function(self, dtime) + self._time_in_air = self._time_in_air + .001 + local pos = self.object:get_pos() local dpos = table.copy(pos) -- digital pos dpos = vector.round(dpos) @@ -193,10 +195,10 @@ function mcl_potions.register_arrow(name, desc, color, def) for k, obj in pairs(objs) do local ok = false -- Arrows can only damage players and mobs - if obj ~= self._shooter and obj:is_player() then + if obj:is_player() then ok = true elseif obj:get_luaentity() ~= nil then - if obj ~= self._shooter and obj:get_luaentity()._cmi_is_mob then + if obj:get_luaentity()._cmi_is_mob then ok = true end end @@ -218,7 +220,7 @@ function mcl_potions.register_arrow(name, desc, color, def) local obj = closest_object local is_player = obj:is_player() local lua = obj:get_luaentity() - if obj ~= self._shooter and (is_player or (lua and lua._cmi_is_mob)) then + if obj == self._shooter and self._time_in_air > 1.02 or obj ~= self._shooter and (is_player or (lua and (lua._cmi_is_mob or lua._hittable_by_projectile))) then if obj:get_hp() > 0 then -- Check if there is no solid node between arrow and object @@ -395,6 +397,7 @@ function mcl_potions.register_arrow(name, desc, color, def) ARROW_ENTITY.on_activate = function(self, staticdata, dtime_s) local data = minetest.deserialize(staticdata) + self._time_in_air = 1.0 if data then self._stuck = data.stuck if data.stuck then From 689054f9041a413fed48e39d25a140845550fbb7 Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Mon, 12 Jul 2021 03:40:58 +0200 Subject: [PATCH 3/8] Fix sound_play invocation when player hit by potion arrow --- mods/ITEMS/mcl_potions/tipped_arrow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_potions/tipped_arrow.lua b/mods/ITEMS/mcl_potions/tipped_arrow.lua index 2fd9933a..ca5fc7f3 100644 --- a/mods/ITEMS/mcl_potions/tipped_arrow.lua +++ b/mods/ITEMS/mcl_potions/tipped_arrow.lua @@ -260,7 +260,7 @@ function mcl_potions.register_arrow(name, desc, color, def) if is_player then if self._shooter and self._shooter:is_player() then -- “Ding” sound for hitting another player - minetest.sound_play({name="mcl_bows_hit_player", gain=0.1}, {to_player=self._shooter}, true) + minetest.sound_play({name="mcl_bows_hit_player", gain=0.1}, {to_player=self._shooter:get_player_name()}, true) end end From 39023f1adf8f9e010d4ed18e040ac93f03b1a644 Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Mon, 12 Jul 2021 04:59:39 +0200 Subject: [PATCH 4/8] Play no hit sound when regular arrow hits shooter --- mods/ITEMS/mcl_bows/arrow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 6952f594..40600ca2 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -265,7 +265,7 @@ ARROW_ENTITY.on_step = function(self, dtime) if is_player then - if self._shooter and self._shooter:is_player() then + if self._shooter and self._shooter:is_player() and obj ~= self._shooter then -- “Ding” sound for hitting another player minetest.sound_play({name="mcl_bows_hit_player", gain=0.1}, {to_player=self._shooter:get_player_name()}, true) end From c45c0df118ceaa26c901c2b2aec122a643f3866b Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Mon, 12 Jul 2021 04:59:53 +0200 Subject: [PATCH 5/8] Play no hit sound when potion arrow hits shooter --- mods/ITEMS/mcl_potions/tipped_arrow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_potions/tipped_arrow.lua b/mods/ITEMS/mcl_potions/tipped_arrow.lua index ca5fc7f3..f71974b8 100644 --- a/mods/ITEMS/mcl_potions/tipped_arrow.lua +++ b/mods/ITEMS/mcl_potions/tipped_arrow.lua @@ -258,7 +258,7 @@ function mcl_potions.register_arrow(name, desc, color, def) end if is_player then - if self._shooter and self._shooter:is_player() then + if self._shooter and self._shooter:is_player() and obj ~= self._shooter then -- “Ding” sound for hitting another player minetest.sound_play({name="mcl_bows_hit_player", gain=0.1}, {to_player=self._shooter:get_player_name()}, true) end From 99ebf08873cc539d2b936fbb00bfb80a6d68d6fd Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Mon, 12 Jul 2021 16:04:09 +0200 Subject: [PATCH 6/8] Refactor regular arrow flight time calculation --- mods/ITEMS/mcl_bows/arrow.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 40600ca2..4b477bf6 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -136,7 +136,7 @@ end ARROW_ENTITY.on_step = function(self, dtime) mcl_burning.tick(self.object, dtime) - self._time_in_air = self._time_in_air + .001 + self._time_in_air = self._time_in_air + dtime local pos = self.object:get_pos() local dpos = table.copy(pos) -- digital pos @@ -228,7 +228,7 @@ ARROW_ENTITY.on_step = function(self, dtime) local obj = closest_object local is_player = obj:is_player() local lua = obj:get_luaentity() - if obj == self._shooter and self._time_in_air > 1.02 or obj ~= self._shooter and (is_player or (lua and (lua._cmi_is_mob or lua._hittable_by_projectile))) then + if obj == self._shooter and self._time_in_air > 1 or obj ~= self._shooter and (is_player or (lua and (lua._cmi_is_mob or lua._hittable_by_projectile))) then if obj:get_hp() > 0 then -- Check if there is no solid node between arrow and object local ray = minetest.raycast(self.object:get_pos(), obj:get_pos(), true) @@ -413,7 +413,7 @@ end ARROW_ENTITY.on_activate = function(self, staticdata, dtime_s) local data = minetest.deserialize(staticdata) - self._time_in_air = 1.0 + self._time_in_air = dtime_s if data then self._stuck = data.stuck if data.stuck then From 2033a9bf1de2e46893b36c840d5d558d7067644f Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Mon, 12 Jul 2021 16:07:20 +0200 Subject: [PATCH 7/8] Refactor potion arrow flight time calculation --- mods/ITEMS/mcl_potions/tipped_arrow.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ITEMS/mcl_potions/tipped_arrow.lua b/mods/ITEMS/mcl_potions/tipped_arrow.lua index f71974b8..5dbb0de6 100644 --- a/mods/ITEMS/mcl_potions/tipped_arrow.lua +++ b/mods/ITEMS/mcl_potions/tipped_arrow.lua @@ -130,7 +130,7 @@ function mcl_potions.register_arrow(name, desc, color, def) end ARROW_ENTITY.on_step = function(self, dtime) - self._time_in_air = self._time_in_air + .001 + self._time_in_air = self._time_in_air + dtime local pos = self.object:get_pos() local dpos = table.copy(pos) -- digital pos @@ -220,7 +220,7 @@ function mcl_potions.register_arrow(name, desc, color, def) local obj = closest_object local is_player = obj:is_player() local lua = obj:get_luaentity() - if obj == self._shooter and self._time_in_air > 1.02 or obj ~= self._shooter and (is_player or (lua and (lua._cmi_is_mob or lua._hittable_by_projectile))) then + if obj == self._shooter and self._time_in_air > 1 or obj ~= self._shooter and (is_player or (lua and (lua._cmi_is_mob or lua._hittable_by_projectile))) then if obj:get_hp() > 0 then -- Check if there is no solid node between arrow and object @@ -397,7 +397,7 @@ function mcl_potions.register_arrow(name, desc, color, def) ARROW_ENTITY.on_activate = function(self, staticdata, dtime_s) local data = minetest.deserialize(staticdata) - self._time_in_air = 1.0 + self._time_in_air = dtime_s if data then self._stuck = data.stuck if data.stuck then From 76e3a00e180ef6e0d5d5460dae581f43907c6568 Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Mon, 12 Jul 2021 22:21:15 +0200 Subject: [PATCH 8/8] Make potion arrows able to hit end crystals --- mods/ITEMS/mcl_potions/tipped_arrow.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_potions/tipped_arrow.lua b/mods/ITEMS/mcl_potions/tipped_arrow.lua index 5dbb0de6..a5f2644e 100644 --- a/mods/ITEMS/mcl_potions/tipped_arrow.lua +++ b/mods/ITEMS/mcl_potions/tipped_arrow.lua @@ -198,7 +198,7 @@ function mcl_potions.register_arrow(name, desc, color, def) if obj:is_player() then ok = true elseif obj:get_luaentity() ~= nil then - if obj:get_luaentity()._cmi_is_mob then + if obj:get_luaentity()._cmi_is_mob or obj:get_luaentity()._hittable_by_projectile then ok = true end end