fix tipped arrows and rocket
parent
6c804f44d5
commit
6bc5e76b8f
|
@ -410,29 +410,34 @@ function ARROW_ENTITY.on_step(self, dtime)
|
|||
end
|
||||
|
||||
-- Iterate through all objects and remember the closest attackable object
|
||||
for k, obj in pairs(objs) do
|
||||
local ok = false
|
||||
-- Arrows can only damage players and mobs
|
||||
if obj:is_player() then
|
||||
ok = true
|
||||
elseif obj:get_luaentity() then
|
||||
if (obj:get_luaentity().is_mob or obj:get_luaentity()._hittable_by_projectile) then
|
||||
local arrow_dir = self.object:get_velocity()
|
||||
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
|
||||
local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 0.1)), true, false)
|
||||
for hitpoint in raycast do
|
||||
if hitpoint.type == "object" then
|
||||
-- find the closest object that is in the way of the arrow
|
||||
local ok = false
|
||||
if hitpoint.ref:is_player() then
|
||||
ok = true
|
||||
elseif hitpoint.ref:get_luaentity() then
|
||||
if (hitpoint.ref:get_luaentity().is_mob or hitpoint.ref:get_luaentity()._hittable_by_projectile) then
|
||||
ok = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ok then
|
||||
local dist = vector.distance(pos, obj:get_pos())
|
||||
if not closest_object or not closest_distance then
|
||||
closest_object = obj
|
||||
closest_distance = dist
|
||||
elseif dist < closest_distance then
|
||||
closest_object = obj
|
||||
closest_distance = dist
|
||||
if ok then
|
||||
local dist = vector.distance(hitpoint.ref:get_pos(), pos)
|
||||
if not closest_object or not closest_distance then
|
||||
closest_object = hitpoint.ref
|
||||
closest_distance = dist
|
||||
elseif dist < closest_distance then
|
||||
closest_object = hitpoint.ref
|
||||
closest_distance = dist
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- If an attackable object was found, we will damage the closest one only
|
||||
|
||||
if closest_object then
|
||||
|
|
|
@ -210,29 +210,34 @@ function mcl_potions.register_arrow(name, desc, color, def)
|
|||
end
|
||||
|
||||
-- Iterate through all objects and remember the closest attackable object
|
||||
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
|
||||
ok = true
|
||||
elseif obj:get_luaentity() then
|
||||
if obj ~= self._shooter and obj:get_luaentity().is_mob then
|
||||
local arrow_dir = self.object:get_velocity()
|
||||
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
|
||||
local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 0.1)), true, false)
|
||||
for hitpoint in raycast do
|
||||
if hitpoint.type == "object" then
|
||||
-- find the closest object that is in the way of the arrow
|
||||
local ok = false
|
||||
if hitpoint.ref:is_player() then
|
||||
ok = true
|
||||
elseif hitpoint.ref:get_luaentity() then
|
||||
if (hitpoint.ref:get_luaentity().is_mob or hitpoint.ref:get_luaentity()._hittable_by_projectile) then
|
||||
ok = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if ok then
|
||||
local dist = vector.distance(pos, obj:get_pos())
|
||||
if not closest_object or not closest_distance then
|
||||
closest_object = obj
|
||||
closest_distance = dist
|
||||
elseif dist < closest_distance then
|
||||
closest_object = obj
|
||||
closest_distance = dist
|
||||
if ok then
|
||||
local dist = vector.distance(hitpoint.ref:get_pos(), pos)
|
||||
if not closest_object or not closest_distance then
|
||||
closest_object = hitpoint.ref
|
||||
closest_distance = dist
|
||||
elseif dist < closest_distance then
|
||||
closest_object = hitpoint.ref
|
||||
closest_distance = dist
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- If an attackable object was found, we will damage the closest one only
|
||||
if closest_object then
|
||||
local obj = closest_object
|
||||
|
|
Loading…
Reference in New Issue