improve throwing mod, arrows don't touch sign:text entity

arrows more accurate shooting
This commit is contained in:
crabman77 2015-08-20 20:26:01 +02:00
parent 5e8a22fc9d
commit 2da8ce1c1a
3 changed files with 38 additions and 29 deletions

View File

@ -41,22 +41,26 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime)
local newpos = self.object:getpos()
if self.lastpos.x~=nil then
if self.lastpos.x ~= nil then
for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
local objpos = obj:getpos()
if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
local damage = 4
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
minetest.add_item(pos, 'default:stick')
if (pos.x - objpos.x < 0.5 and pos.x - objpos.x > -0.5) and (pos.z - objpos.z < 0.5 and pos.z - objpos.z > -0.5) then
local damage = 4
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
minetest.add_item(pos, 'default:stick')
end
self.object:remove()
return
end
self.object:remove()
return
end
end
@ -67,19 +71,20 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.object:remove()
return
end
if math.floor(self.lastpos.x+0.5) ~= math.floor(pos.x+0.5) or math.floor(self.lastpos.y+0.5) ~= math.floor(pos.y+0.5) or math.floor(self.lastpos.z+0.5) ~= math.floor(pos.z+0.5) then
if minetest.get_node(self.lastpos).name == "throwing:light" then
minetest.remove_node(self.lastpos)
end
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="throwing:light"})
end
if minetest.get_node(pos).name == "air" then
minetest.set_node(pos, {name="throwing:light"})
end
if minetest.get_node(self.lastpos).name == "throwing:light" then
minetest.remove_node(self.lastpos)
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
end
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end
minetest.register_entity("throwing:arrow_fire_entity", THROWING_ARROW_ENTITY)
minetest.register_node("throwing:light", {

View File

@ -24,7 +24,8 @@ function throwing_is_entity(obj)
return (obj:get_luaentity() ~= nil
and not string.find(obj:get_luaentity().name, "throwing:arrow_")
and obj:get_luaentity().name ~= "__builtin:item"
and obj:get_luaentity().name ~= "gauges:hp_bar")
and obj:get_luaentity().name ~= "gauges:hp_bar"
and obj:get_luaentity().name ~= "signs:text")
end
function throwing_get_trajectoire(self, newpos)
if self.lastpos.x == nil then

View File

@ -48,20 +48,23 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
local node = minetest.get_node(pos)
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do
local objpos = obj:getpos()
if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=eq},
}, nil)
if math.random() < toughness then
if math.random(0,100) % 2 == 0 then
minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind)
if (pos.x - objpos.x < 0.5 and pos.x - objpos.x > -0.5) and (pos.z - objpos.z < 0.5 and pos.z - objpos.z > -0.5) then
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=eq},
}, nil)
if math.random() < toughness then
if math.random(0,100) % 2 == 0 then
minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind)
end
else
minetest.add_item(self.lastpos, 'default:stick')
end
else
minetest.add_item(self.lastpos, 'default:stick')
self.object:remove()
return
end
self.object:remove()
return
end
end
if node.name ~= "air" and not string.find(node.name, 'water_') and not string.find(node.name, 'default:grass') and not string.find(node.name, 'default:junglegrass') and not string.find(node.name, 'flowers:') and not string.find(node.name, 'farming:') then