forked from Mineclonia/Mineclonia
Merge pull request 'items/mcl_bows: Let players shoot themselves with arrows' (#117) from fix-arrow-selfshoot-3 into master
Reviewed-on: Mineclonia/Mineclonia#117 Reviewed-by: E <e@noreply.git.minetest.land>
This commit is contained in:
commit
e2e08f28dd
|
@ -136,6 +136,8 @@ end
|
||||||
ARROW_ENTITY.on_step = function(self, dtime)
|
ARROW_ENTITY.on_step = function(self, dtime)
|
||||||
mcl_burning.tick(self.object, dtime)
|
mcl_burning.tick(self.object, dtime)
|
||||||
|
|
||||||
|
self._time_in_air = self._time_in_air + dtime
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local dpos = table.copy(pos) -- digital pos
|
local dpos = table.copy(pos) -- digital pos
|
||||||
dpos = vector.round(dpos)
|
dpos = vector.round(dpos)
|
||||||
|
@ -201,10 +203,10 @@ ARROW_ENTITY.on_step = function(self, dtime)
|
||||||
for k, obj in pairs(objs) do
|
for k, obj in pairs(objs) do
|
||||||
local ok = false
|
local ok = false
|
||||||
-- Arrows can only damage players and mobs
|
-- Arrows can only damage players and mobs
|
||||||
if obj ~= self._shooter and obj:is_player() then
|
if obj:is_player() then
|
||||||
ok = true
|
ok = true
|
||||||
elseif obj:get_luaentity() ~= nil then
|
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
|
ok = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -226,7 +228,7 @@ ARROW_ENTITY.on_step = function(self, dtime)
|
||||||
local obj = closest_object
|
local obj = closest_object
|
||||||
local is_player = obj:is_player()
|
local is_player = obj:is_player()
|
||||||
local lua = obj:get_luaentity()
|
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 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
|
if obj:get_hp() > 0 then
|
||||||
-- Check if there is no solid node between arrow and object
|
-- Check if there is no solid node between arrow and object
|
||||||
local ray = minetest.raycast(self.object:get_pos(), obj:get_pos(), true)
|
local ray = minetest.raycast(self.object:get_pos(), obj:get_pos(), true)
|
||||||
|
@ -263,7 +265,7 @@ ARROW_ENTITY.on_step = function(self, dtime)
|
||||||
|
|
||||||
|
|
||||||
if is_player then
|
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
|
-- “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)
|
minetest.sound_play({name="mcl_bows_hit_player", gain=0.1}, {to_player=self._shooter:get_player_name()}, true)
|
||||||
end
|
end
|
||||||
|
@ -411,6 +413,7 @@ end
|
||||||
|
|
||||||
ARROW_ENTITY.on_activate = function(self, staticdata, dtime_s)
|
ARROW_ENTITY.on_activate = function(self, staticdata, dtime_s)
|
||||||
local data = minetest.deserialize(staticdata)
|
local data = minetest.deserialize(staticdata)
|
||||||
|
self._time_in_air = dtime_s
|
||||||
if data then
|
if data then
|
||||||
self._stuck = data.stuck
|
self._stuck = data.stuck
|
||||||
if data.stuck then
|
if data.stuck then
|
||||||
|
|
|
@ -130,6 +130,8 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
ARROW_ENTITY.on_step = function(self, dtime)
|
ARROW_ENTITY.on_step = function(self, dtime)
|
||||||
|
self._time_in_air = self._time_in_air + dtime
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local dpos = table.copy(pos) -- digital pos
|
local dpos = table.copy(pos) -- digital pos
|
||||||
dpos = vector.round(dpos)
|
dpos = vector.round(dpos)
|
||||||
|
@ -193,10 +195,10 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
||||||
for k, obj in pairs(objs) do
|
for k, obj in pairs(objs) do
|
||||||
local ok = false
|
local ok = false
|
||||||
-- Arrows can only damage players and mobs
|
-- Arrows can only damage players and mobs
|
||||||
if obj ~= self._shooter and obj:is_player() then
|
if obj:is_player() then
|
||||||
ok = true
|
ok = true
|
||||||
elseif obj:get_luaentity() ~= nil then
|
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 or obj:get_luaentity()._hittable_by_projectile then
|
||||||
ok = true
|
ok = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -218,7 +220,7 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
||||||
local obj = closest_object
|
local obj = closest_object
|
||||||
local is_player = obj:is_player()
|
local is_player = obj:is_player()
|
||||||
local lua = obj:get_luaentity()
|
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 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
|
if obj:get_hp() > 0 then
|
||||||
-- Check if there is no solid node between arrow and object
|
-- Check if there is no solid node between arrow and object
|
||||||
|
@ -256,9 +258,9 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
if is_player then
|
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
|
-- “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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -395,6 +397,7 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
||||||
|
|
||||||
ARROW_ENTITY.on_activate = function(self, staticdata, dtime_s)
|
ARROW_ENTITY.on_activate = function(self, staticdata, dtime_s)
|
||||||
local data = minetest.deserialize(staticdata)
|
local data = minetest.deserialize(staticdata)
|
||||||
|
self._time_in_air = dtime_s
|
||||||
if data then
|
if data then
|
||||||
self._stuck = data.stuck
|
self._stuck = data.stuck
|
||||||
if data.stuck then
|
if data.stuck then
|
||||||
|
|
Loading…
Reference in New Issue