improve throwing mod

This commit is contained in:
crabman77 2015-08-01 18:45:35 +02:00
parent 30b65de384
commit 640f02cdd2
10 changed files with 177 additions and 208 deletions

View File

@ -31,7 +31,6 @@ minetest.register_node("throwing:arrow_build_box", {
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
physical = false, physical = false,
timer=0,
visual = "wielditem", visual = "wielditem",
visual_size = {x=0.1, y=0.1}, visual_size = {x=0.1, y=0.1},
textures = {"throwing:arrow_build_box"}, textures = {"throwing:arrow_build_box"},
@ -44,51 +43,47 @@ local THROWING_ARROW_ENTITY={
} }
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local newpos = self.object:getpos() local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do if self.lastpos.x ~= nil then
local node = minetest.get_node(pos) for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do
if self.timer>0.2 then local node = minetest.get_node(pos)
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1) local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
if obj:get_luaentity().name ~= "throwing:arrow_build_entity" and obj:get_luaentity().name ~= "__builtin:item" then if self.inventory and self.stack and not minetest.setting_getbool("creative_mode") then
if self.inventory and self.stack and not minetest.setting_getbool("creative_mode") then self.inventory:remove_item("main", {name=self.stack:get_name()})
self.inventory:remove_item("main", {name=self.stack:get_name()})
end
if self.stack then
minetest.add_item(pos, {name=self.stack:get_name()})
end
local toughness = 0.95
if math.random() < toughness then
minetest.add_item(pos, 'throwing:arrow_build')
else
minetest.add_item(pos, 'default:stick')
end
self.object:remove()
return
end end
if self.stack then
minetest.add_item(pos, {name=self.stack:get_name()})
end
local toughness = 0.95
if math.random() < toughness then
minetest.add_item(pos, 'throwing:arrow_build')
else
minetest.add_item(pos, 'default:stick')
end
self.object:remove()
return
end end
end end
end
if self.lastpos.x~= nil then
if node.name ~= "air" then if node.name ~= "air" then
if self.inventory and self.stack and not minetest.setting_getbool("creative_mode") then if node.name ~= "ignore" and self.inventory and self.stack then
self.inventory:remove_item("main", {name=self.stack:get_name()}) if not minetest.is_protected(self.lastpos, "") and not string.find(node.name, "water_") and not string.find(node.name, "lava") and not string.find(node.name, "torch") and self.stack:get_definition().type == "node" and self.stack:get_name() ~= "default:torch" then
end
if self.stack then
if not minetest.is_protected(self.lastpos, self.player) and not string.find(node.name, "water_") and not string.find(node.name, "lava") and not string.find(node.name, "torch") and self.stack:get_definition().type == "node" and self.stack:get_name() ~= "default:torch" then
minetest.place_node(self.lastpos, {name=self.stack:get_name()}) minetest.place_node(self.lastpos, {name=self.stack:get_name()})
else else
minetest.add_item(self.lastpos, {name=self.stack:get_name()}) minetest.add_item(self.lastpos, {name=self.stack:get_name()})
end end
if not minetest.setting_getbool("creative_mode") then
self.inventory:remove_item("main", {name=self.stack:get_name()})
end
end end
minetest.add_item(self.lastpos, 'default:shovel_steel') minetest.add_item(self.lastpos, 'default:shovel_steel')
self.object:remove() self.object:remove()
return return
end end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end 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} self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end end

View File

@ -42,38 +42,36 @@ local THROWING_ARROW_ENTITY={
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local newpos = self.object:getpos() local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do if self.lastpos.x ~= nil then
local node = minetest.get_node(pos) for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do
if self.timer>0.2 then local node = minetest.get_node(pos)
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1) local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
if obj:get_luaentity().name ~= "throwing:arrow_dig_entity" and obj:get_luaentity().name ~= "__builtin:item" then local damage = 1.5
local damage = 1.5 obj:punch(self.object, 1.0, {
obj:punch(self.object, 1.0, { full_punch_interval=1.0,
full_punch_interval=1.0, damage_groups={fleshy=damage},
damage_groups={fleshy=damage}, }, nil)
}, nil) if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15) minetest.add_item(pos, "throwing:arrow_dig")
minetest.add_item(pos, "throwing:arrow_dig")
end
self.object:remove()
return
end end
self.object:remove()
return
end end
end end
end if node.name ~= "air" and not string.find(node.name, "water_") then
if node.name ~= "air" and not string.find(node.name, "water_") then if node.name ~= "ignore" and minetest.get_item_group(node.name, "unbreakable") == 0
if node.name ~= "ignore" and minetest.get_item_group(node.name, "unbreakable") == 0 and not minetest.is_protected(pos, self.player)
and not minetest.is_protected(pos, self.player) and node.diggable ~= false then
and node.diggable ~= false then minetest.set_node(pos, {name = "air"})
minetest.set_node(pos, {name = "air"}) minetest.add_item(pos, node.name)
minetest.add_item(pos, node.name) end
self.object:remove()
return
end end
self.object:remove() self.lastpos={x=pos.x, y=pos.y, z=pos.z}
return
end end
end end
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z} self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}

View File

@ -31,7 +31,6 @@ minetest.register_node("throwing:arrow_fire_box", {
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
physical = false, physical = false,
timer=0,
visual = "wielditem", visual = "wielditem",
visual_size = {x=0.1, y=0.1}, visual_size = {x=0.1, y=0.1},
textures = {"throwing:arrow_fire_box"}, textures = {"throwing:arrow_fire_box"},
@ -41,34 +40,30 @@ local THROWING_ARROW_ENTITY={
} }
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local newpos = self.object:getpos() local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do if self.lastpos.x~=nil then
local node = minetest.get_node(pos) for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
if obj:get_luaentity().name ~= "throwing:arrow_fire_entity" and obj:get_luaentity().name ~= "__builtin:item" then local damage = 4
local damage = 4 obj:punch(self.object, 1.0, {
obj:punch(self.object, 1.0, { full_punch_interval=1.0,
full_punch_interval=1.0, damage_groups={fleshy=damage},
damage_groups={fleshy=damage}, }, nil)
}, nil) if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15) minetest.add_item(pos, 'default:stick')
minetest.add_item(pos, 'default:stick')
end
self.object:remove()
return
end end
self.object:remove()
return
end end
end end
end
if self.lastpos.x~=nil then
if node.name ~= "air" and node.name ~= "throwing:light" then if node.name ~= "air" and node.name ~= "throwing:light" then
minetest.set_node(self.lastpos, {name="fire:basic_flame"}) if node.name ~= "ignore" then
minetest.set_node(self.lastpos, {name="fire:basic_flame"})
end
self.object:remove() self.object:remove()
return return
end end

View File

@ -75,16 +75,15 @@ local function throwing_register_fireworks(color, desc)
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime self.timer=self.timer+dtime
local pos = self.object:getpos() local newpos = self.object:getpos()
local node = minetest.get_node(pos)
if self.timer < 0.07 then if self.timer < 0.07 then
minetest.sound_play("throwing_firework_launch", {pos=pos, gain=0.8, max_hear_distance=2*64}) minetest.sound_play("throwing_firework_launch", {pos=newpos, gain=0.8, max_hear_distance=2*64})
end end
minetest.add_particlespawner({ minetest.add_particlespawner({
amount = 16, amount = 16,
time = 0.1, time = 0.1,
minpos = pos, minpos = newpos,
maxpos = pos, maxpos = newpos,
minvel = {x=-5, y=-5, z=-5}, minvel = {x=-5, y=-5, z=-5},
maxvel = {x=5, y=5, z=5}, maxvel = {x=5, y=5, z=5},
minacc = vector.new(), minacc = vector.new(),
@ -95,11 +94,11 @@ local function throwing_register_fireworks(color, desc)
maxsize = 1, maxsize = 1,
texture = "throwing_sparkle.png", texture = "throwing_sparkle.png",
}) })
if self.timer>0.2 then if self.lastpos.x ~= nil then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do
for k, obj in pairs(objs) do local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
if obj:get_luaentity() ~= nil then for k, obj in pairs(objs) do
if obj:get_luaentity().name ~= "throwing:arrow_fireworks_" .. color .. "_entity" and obj:get_luaentity().name ~= "__builtin:item" then if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
local damage = 2 local damage = 2
obj:punch(self.object, 1.0, { obj:punch(self.object, 1.0, {
full_punch_interval=1.0, full_punch_interval=1.0,
@ -111,26 +110,21 @@ local function throwing_register_fireworks(color, desc)
end end
end end
end end
end local node = minetest.get_node(newpos)
if self.timer > 2 then if self.timer > 2 or node.name ~= "air" and node.name ~= "throwing:firework_trail" then
boom(self.lastpos)
self.object:remove()
return
end
if self.lastpos.x~=nil then
if node.name ~= "air" and node.name ~= "throwing:firework_trail" then
boom(self.lastpos) boom(self.lastpos)
self.object:remove() self.object:remove()
return return
end end
if node.name == 'air' then
minetest.add_node(newpos, {name="throwing:firework_trail"})
minetest.get_node_timer(newpos):start(0.1)
end
end end
if node.name == 'air' then self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
minetest.add_node(pos, {name="throwing:firework_trail"})
minetest.get_node_timer(pos):start(0.1)
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end end
minetest.register_entity("throwing:arrow_fireworks_" .. color .. "_entity", THROWING_ARROW_ENTITY) minetest.register_entity("throwing:arrow_fireworks_" .. color .. "_entity", THROWING_ARROW_ENTITY)
minetest.register_craft({ minetest.register_craft({

View File

@ -16,8 +16,17 @@ minetest.register_on_leaveplayer(function(player)
players[playerName] = nil players[playerName] = nil
end) end)
function throwing_is_player(name, obj)
return (obj:is_player() and obj:get_player_name() ~= name)
end
function get_trajectoire(self, newpos) 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")
end
function throwing_get_trajectoire(self, newpos)
if self.lastpos.x == nil then if self.lastpos.x == nil then
return {newpos} return {newpos}
end end
@ -55,6 +64,7 @@ function throwing_shoot_arrow (itemstack, player, stiffness, is_cross)
obj:get_luaentity().player = player:get_player_name() obj:get_luaentity().player = player:get_player_name()
obj:get_luaentity().inventory = player:get_inventory() obj:get_luaentity().inventory = player:get_inventory()
obj:get_luaentity().stack = player:get_inventory():get_stack("main", player:get_wield_index()-1) obj:get_luaentity().stack = player:get_inventory():get_stack("main", player:get_wield_index()-1)
obj:get_luaentity().lastpos = {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}
end end
return true return true
end end

View File

@ -71,15 +71,13 @@ end
-- Back to the arrow -- Back to the arrow
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime local newpos = self.object:getpos()
local pos = self.object:getpos() if self.lastpos.x ~= nil then
local node = minetest.get_node(pos) for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if self.timer>0.2 then local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) for k, obj in pairs(objs) do
for k, obj in pairs(objs) do if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_shell_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local speed = vector.length(self.object:getvelocity()) local speed = vector.length(self.object:getvelocity())
local damage = ((speed + 5)^1.2)/10 + 12 local damage = ((speed + 5)^1.2)/10 + 12
obj:punch(self.object, 1.0, { obj:punch(self.object, 1.0, {
@ -91,17 +89,16 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
return return
end end
end end
end
end
if self.lastpos.x~=nil then if node.name ~= "air" 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
if node.name ~= "air" 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 boom(self.lastpos)
boom(self.lastpos) self.object:remove()
self.object:remove() return
return end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end end
end end
self.lastpos={x=pos.x, y=pos.y, z=pos.z} self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end end
minetest.register_entity("throwing:arrow_shell_entity", THROWING_ARROW_ENTITY) minetest.register_entity("throwing:arrow_shell_entity", THROWING_ARROW_ENTITY)

View File

@ -33,7 +33,6 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
physical = false, physical = false,
timer=0,
visual = "wielditem", visual = "wielditem",
visual_size = {x=0.1, y=0.1}, visual_size = {x=0.1, y=0.1},
textures = {"throwing:arrow_" .. kind .. "_box"}, textures = {"throwing:arrow_" .. kind .. "_box"},
@ -43,44 +42,38 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft)
} }
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local newpos = self.object:getpos() local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do if self.lastpos.x ~= nil then
local node = minetest.get_node(pos) for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
if obj:get_luaentity().name ~= "throwing:arrow_" .. kind .. "_entity" and obj:get_luaentity().name ~= "__builtin:item" then obj:punch(self.object, 1.0, {
obj:punch(self.object, 1.0, {
full_punch_interval=1.0, full_punch_interval=1.0,
damage_groups={fleshy=eq}, damage_groups={fleshy=eq},
}, nil) }, nil)
if math.random() < toughness then if math.random() < toughness then
if math.random(0,100) % 2 == 0 then if math.random(0,100) % 2 == 0 then
minetest.add_item(pos, 'throwing:arrow_' .. kind) minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind)
end
else
minetest.add_item(pos, 'default:stick')
end end
self.object:remove() else
return minetest.add_item(self.lastpos, 'default:stick')
end end
self.object:remove()
return
end end
end 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
if math.random() < toughness then
minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind)
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') else
and not string.find(node.name, 'flowers:') and not string.find(node.name, 'farming:') then minetest.add_item(self.lastpos, 'default:stick')
if math.random() < toughness then end
minetest.add_item(pos, 'throwing:arrow_' .. kind) self.object:remove()
else return
minetest.add_item(pos, 'default:stick')
end end
self.object:remove() self.lastpos={x=pos.x, y=pos.y, z=pos.z}
return
end end
end end
self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z} self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}

View File

@ -31,7 +31,6 @@ minetest.register_node("throwing:arrow_teleport_box", {
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
physical = false, physical = false,
timer=0,
visual = "wielditem", visual = "wielditem",
visual_size = {x=0.1, y=0.1}, visual_size = {x=0.1, y=0.1},
textures = {"throwing:arrow_teleport_box"}, textures = {"throwing:arrow_teleport_box"},
@ -41,41 +40,38 @@ local THROWING_ARROW_ENTITY={
} }
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime local newpos = self.object:getpos()
local pos = self.object:getpos() if self.lastpos.x ~= nil then
local node = minetest.get_node(pos) for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if self.timer>0.2 then local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) for k, obj in pairs(objs) do
for k, obj in pairs(objs) do if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_teleport_entity" and obj:get_luaentity().name ~= "__builtin:item" then
if self.player ~= "" then if self.player ~= "" then
local player = minetest.get_player_by_name(self.player) local player = minetest.get_player_by_name(self.player)
if player then if player then
player:setpos(pos) player:setpos(self.lastpos)
end end
end end
self.object:remove() self.object:remove()
return return
end end
end end
end
end
if self.lastpos.x~= nil then if node.name ~= "air" then
if node.name ~= "air" then if self.player ~= "" then
if self.player ~= "" then local player = minetest.get_player_by_name(self.player)
local player = minetest.get_player_by_name(self.player) if player then
if player then player:setpos(self.lastpos)
player:setpos(self.lastpos) end
end end
self.object:remove()
return
end end
self.object:remove() self.lastpos={x=pos.x, y=pos.y, z=pos.z}
return
end end
end end
self.lastpos={x=pos.x, y=pos.y, z=pos.z} self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end end
minetest.register_entity("throwing:arrow_teleport_entity", THROWING_ARROW_ENTITY) minetest.register_entity("throwing:arrow_teleport_entity", THROWING_ARROW_ENTITY)

View File

@ -244,26 +244,24 @@ end
-- Back to the arrow -- Back to the arrow
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime local newpos = self.object:getpos()
local pos = self.object:getpos() if self.lastpos.x ~= nil then
local node = minetest.get_node(pos) for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if self.timer>0.2 then local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) for k, obj in pairs(objs) do
for k, obj in pairs(objs) do if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "throwing:arrow_tnt_entity" and obj:get_luaentity().name ~= "__builtin:item" then
self.object:remove()
boom(pos) boom(pos)
self.object:remove()
return
end end
end end
end
end
if self.lastpos.x~=nil then if node.name ~= "air" then
if node.name ~= "air" then boom(pos)
self.object:remove() self.object:remove()
boom(self.lastpos) return
end
end end
end end
self.lastpos={x=pos.x, y=pos.y, z=pos.z} self.lastpos={x=pos.x, y=pos.y, z=pos.z}

View File

@ -31,7 +31,6 @@ minetest.register_node("throwing:arrow_torch_box", {
local THROWING_ARROW_ENTITY={ local THROWING_ARROW_ENTITY={
physical = false, physical = false,
timer=0,
visual = "wielditem", visual = "wielditem",
visual_size = {x=0.1, y=0.1}, visual_size = {x=0.1, y=0.1},
textures = {"throwing:arrow_torch_box"}, textures = {"throwing:arrow_torch_box"},
@ -42,41 +41,35 @@ local THROWING_ARROW_ENTITY={
} }
THROWING_ARROW_ENTITY.on_step = function(self, dtime) THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local newpos = self.object:getpos() local newpos = self.object:getpos()
for _, pos in pairs(get_trajectoire(self, newpos)) do if self.lastpos.x~= nil then
local node = minetest.get_node(pos) for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do
local node = minetest.get_node(pos)
if self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 0.5) local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 0.5)
for k, obj in pairs(objs) do for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then
if obj:get_luaentity().name ~= "throwing:arrow_torch_entity" and obj:get_luaentity().name ~= "__builtin:item" then local damage = 0.5
local damage = 0.5 obj:punch(self.object, 1.0, {
obj:punch(self.object, 1.0, { full_punch_interval=1.0,
full_punch_interval=1.0, damage_groups={fleshy=damage},
damage_groups={fleshy=damage}, }, nil)
}, nil) local toughness = 0.9
local toughness = 0.9 if math.random() < toughness then
if math.random() < toughness then if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15)
if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15) minetest.add_item(pos, 'throwing:arrow_torch')
minetest.add_item(pos, 'throwing:arrow_torch')
end
else
minetest.add_item(pos, 'default:stick')
end end
self.object:remove() else
return minetest.add_item(pos, 'default:stick')
end end
self.object:remove()
return
end end
end end
end
if self.lastpos.x~= nil then
if node.name ~= "air" then if node.name ~= "air" then
local player = minetest.get_player_by_name(self.player) local player = minetest.get_player_by_name(self.player)
if not player then self.object:remove() return end if not player then self.object:remove() return end
if not string.find(node.name, "water_") and not string.find(node.name, "lava") if node.name ~= "ignore" and not string.find(node.name, "water_") and not string.find(node.name, "lava")
and not string.find(node.name, "torch") and minetest.get_item_group(node.name, "unbreakable") == 0 and not string.find(node.name, "torch") and minetest.get_item_group(node.name, "unbreakable") == 0
and not minetest.is_protected(self.lastpos, self.player) and node.diggable ~= false then and not minetest.is_protected(self.lastpos, self.player) and node.diggable ~= false then
local dir=vector.direction(self.lastpos, pos) local dir=vector.direction(self.lastpos, pos)
@ -93,8 +86,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self.object:remove() self.object:remove()
return return
end end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end 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} self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z}
end end