From 640f02cdd2f423d923955842da7b49e82ee5e49b Mon Sep 17 00:00:00 2001 From: crabman77 Date: Sat, 1 Aug 2015 18:45:35 +0200 Subject: [PATCH] improve throwing mod --- mods/throwing/build_arrow.lua | 53 ++++++++++++++---------------- mods/throwing/dig_arrow.lua | 48 +++++++++++++-------------- mods/throwing/fire_arrow.lua | 37 +++++++++------------ mods/throwing/fireworks_arrows.lua | 40 ++++++++++------------ mods/throwing/functions.lua | 12 ++++++- mods/throwing/shell_arrow.lua | 31 ++++++++--------- mods/throwing/standard_arrows.lua | 49 ++++++++++++--------------- mods/throwing/teleport_arrow.lua | 40 ++++++++++------------ mods/throwing/tnt_arrow.lua | 30 ++++++++--------- mods/throwing/torch_arrow.lua | 45 +++++++++++-------------- 10 files changed, 177 insertions(+), 208 deletions(-) diff --git a/mods/throwing/build_arrow.lua b/mods/throwing/build_arrow.lua index 924da9b6..b8bf0c87 100755 --- a/mods/throwing/build_arrow.lua +++ b/mods/throwing/build_arrow.lua @@ -31,7 +31,6 @@ minetest.register_node("throwing:arrow_build_box", { local THROWING_ARROW_ENTITY={ physical = false, - timer=0, visual = "wielditem", visual_size = {x=0.1, y=0.1}, textures = {"throwing:arrow_build_box"}, @@ -44,51 +43,47 @@ local THROWING_ARROW_ENTITY={ } THROWING_ARROW_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime local newpos = self.object:getpos() - for _, pos in pairs(get_trajectoire(self, newpos)) do - local node = minetest.get_node(pos) - if self.timer>0.2 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}, 1) for k, obj in pairs(objs) do - if obj:get_luaentity() ~= nil 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 - 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 + if throwing_is_player(self.player, obj) or throwing_is_entity(obj) 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()}) 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 - if self.lastpos.x~= nil then + if node.name ~= "air" 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()}) - 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 + if node.name ~= "ignore" and self.inventory and self.stack then + 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 minetest.place_node(self.lastpos, {name=self.stack:get_name()}) else minetest.add_item(self.lastpos, {name=self.stack:get_name()}) end + if not minetest.setting_getbool("creative_mode") then + self.inventory:remove_item("main", {name=self.stack:get_name()}) + end end minetest.add_item(self.lastpos, 'default:shovel_steel') self.object:remove() return end + self.lastpos={x=pos.x, y=pos.y, z=pos.z} end - self.lastpos={x=pos.x, y=pos.y, z=pos.z} end self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z} end diff --git a/mods/throwing/dig_arrow.lua b/mods/throwing/dig_arrow.lua index 79173491..4c7d6c60 100755 --- a/mods/throwing/dig_arrow.lua +++ b/mods/throwing/dig_arrow.lua @@ -42,38 +42,36 @@ local THROWING_ARROW_ENTITY={ THROWING_ARROW_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime local newpos = self.object:getpos() - for _, pos in pairs(get_trajectoire(self, newpos)) do - local node = minetest.get_node(pos) - if self.timer>0.2 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}, 1) for k, obj in pairs(objs) do - if obj:get_luaentity() ~= nil then - if obj:get_luaentity().name ~= "throwing:arrow_dig_entity" and obj:get_luaentity().name ~= "__builtin:item" then - local damage = 1.5 - 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, "throwing:arrow_dig") - end - self.object:remove() - return + if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then + local damage = 1.5 + 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, "throwing:arrow_dig") end + self.object:remove() + return end end - end - 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 - and not minetest.is_protected(pos, self.player) - and node.diggable ~= false then - minetest.set_node(pos, {name = "air"}) - minetest.add_item(pos, node.name) + 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 + and not minetest.is_protected(pos, self.player) + and node.diggable ~= false then + minetest.set_node(pos, {name = "air"}) + minetest.add_item(pos, node.name) + end + self.object:remove() + return end - self.object:remove() - return + self.lastpos={x=pos.x, y=pos.y, z=pos.z} end end self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z} diff --git a/mods/throwing/fire_arrow.lua b/mods/throwing/fire_arrow.lua index 716a84fc..3e46693f 100755 --- a/mods/throwing/fire_arrow.lua +++ b/mods/throwing/fire_arrow.lua @@ -31,7 +31,6 @@ minetest.register_node("throwing:arrow_fire_box", { local THROWING_ARROW_ENTITY={ physical = false, - timer=0, visual = "wielditem", visual_size = {x=0.1, y=0.1}, textures = {"throwing:arrow_fire_box"}, @@ -41,34 +40,30 @@ local THROWING_ARROW_ENTITY={ } THROWING_ARROW_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime local newpos = self.object:getpos() - for _, pos in pairs(get_trajectoire(self, newpos)) do - local node = minetest.get_node(pos) - - if self.timer>0.2 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 - if obj:get_luaentity() ~= nil then - if obj:get_luaentity().name ~= "throwing:arrow_fire_entity" and obj:get_luaentity().name ~= "__builtin:item" 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 + 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') end + self.object:remove() + return end end - end - if self.lastpos.x~=nil 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() return end diff --git a/mods/throwing/fireworks_arrows.lua b/mods/throwing/fireworks_arrows.lua index 392373bf..87e30247 100755 --- a/mods/throwing/fireworks_arrows.lua +++ b/mods/throwing/fireworks_arrows.lua @@ -75,16 +75,15 @@ local function throwing_register_fireworks(color, desc) THROWING_ARROW_ENTITY.on_step = function(self, dtime) self.timer=self.timer+dtime - local pos = self.object:getpos() - local node = minetest.get_node(pos) + local newpos = self.object:getpos() 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 minetest.add_particlespawner({ amount = 16, time = 0.1, - minpos = pos, - maxpos = pos, + minpos = newpos, + maxpos = newpos, minvel = {x=-5, y=-5, z=-5}, maxvel = {x=5, y=5, z=5}, minacc = vector.new(), @@ -95,11 +94,11 @@ local function throwing_register_fireworks(color, desc) maxsize = 1, texture = "throwing_sparkle.png", }) - if self.timer>0.2 then - local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) - for k, obj in pairs(objs) do - if obj:get_luaentity() ~= nil then - if obj:get_luaentity().name ~= "throwing:arrow_fireworks_" .. color .. "_entity" and obj:get_luaentity().name ~= "__builtin:item" then + if self.lastpos.x ~= nil then + for _, pos in pairs(throwing_get_trajectoire(self, newpos)) do + local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) + for k, obj in pairs(objs) do + if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then local damage = 2 obj:punch(self.object, 1.0, { full_punch_interval=1.0, @@ -111,26 +110,21 @@ local function throwing_register_fireworks(color, desc) end end end - end - if self.timer > 2 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 + local node = minetest.get_node(newpos) + if self.timer > 2 or node.name ~= "air" and node.name ~= "throwing:firework_trail" then boom(self.lastpos) self.object:remove() return end + if node.name == 'air' then + minetest.add_node(newpos, {name="throwing:firework_trail"}) + minetest.get_node_timer(newpos):start(0.1) + end end - if node.name == 'air' then - 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} + self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z} end + minetest.register_entity("throwing:arrow_fireworks_" .. color .. "_entity", THROWING_ARROW_ENTITY) minetest.register_craft({ diff --git a/mods/throwing/functions.lua b/mods/throwing/functions.lua index 1ea080b0..e35a6c5c 100755 --- a/mods/throwing/functions.lua +++ b/mods/throwing/functions.lua @@ -16,8 +16,17 @@ minetest.register_on_leaveplayer(function(player) players[playerName] = nil 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 return {newpos} 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().inventory = player:get_inventory() 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 return true end diff --git a/mods/throwing/shell_arrow.lua b/mods/throwing/shell_arrow.lua index ca6637d7..d4284356 100755 --- a/mods/throwing/shell_arrow.lua +++ b/mods/throwing/shell_arrow.lua @@ -71,15 +71,13 @@ end -- Back to the arrow THROWING_ARROW_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime - local pos = self.object:getpos() - 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) - for k, obj in pairs(objs) do - if obj:get_luaentity() ~= nil then - if obj:get_luaentity().name ~= "throwing:arrow_shell_entity" and obj:get_luaentity().name ~= "__builtin:item" then + local newpos = self.object:getpos() + 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 + if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then local speed = vector.length(self.object:getvelocity()) local damage = ((speed + 5)^1.2)/10 + 12 obj:punch(self.object, 1.0, { @@ -91,17 +89,16 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) return 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 - boom(self.lastpos) - self.object:remove() - return + 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) + self.object:remove() + return + 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} + self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z} end minetest.register_entity("throwing:arrow_shell_entity", THROWING_ARROW_ENTITY) diff --git a/mods/throwing/standard_arrows.lua b/mods/throwing/standard_arrows.lua index 1e39dd64..ecb4f7d0 100755 --- a/mods/throwing/standard_arrows.lua +++ b/mods/throwing/standard_arrows.lua @@ -33,7 +33,6 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft) local THROWING_ARROW_ENTITY={ physical = false, - timer=0, visual = "wielditem", visual_size = {x=0.1, y=0.1}, 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) - self.timer=self.timer+dtime local newpos = self.object:getpos() - for _, pos in pairs(get_trajectoire(self, newpos)) do - local node = minetest.get_node(pos) - - if self.timer>0.2 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 - if obj:get_luaentity() ~= nil then - if obj:get_luaentity().name ~= "throwing:arrow_" .. kind .. "_entity" and obj:get_luaentity().name ~= "__builtin:item" then - obj:punch(self.object, 1.0, { + 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(pos, 'throwing:arrow_' .. kind) - end - else - minetest.add_item(pos, 'default:stick') + if math.random() < toughness then + if math.random(0,100) % 2 == 0 then + minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind) end - self.object:remove() - return + else + minetest.add_item(self.lastpos, 'default:stick') end + self.object:remove() + return 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(pos, 'throwing:arrow_' .. kind) - else - minetest.add_item(pos, 'default:stick') + 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) + else + minetest.add_item(self.lastpos, 'default:stick') + end + self.object:remove() + return end - self.object:remove() - return + self.lastpos={x=pos.x, y=pos.y, z=pos.z} end end self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z} diff --git a/mods/throwing/teleport_arrow.lua b/mods/throwing/teleport_arrow.lua index 117ee845..d81fa280 100755 --- a/mods/throwing/teleport_arrow.lua +++ b/mods/throwing/teleport_arrow.lua @@ -31,7 +31,6 @@ minetest.register_node("throwing:arrow_teleport_box", { local THROWING_ARROW_ENTITY={ physical = false, - timer=0, visual = "wielditem", visual_size = {x=0.1, y=0.1}, textures = {"throwing:arrow_teleport_box"}, @@ -41,41 +40,38 @@ local THROWING_ARROW_ENTITY={ } THROWING_ARROW_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime - local pos = self.object:getpos() - 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) - for k, obj in pairs(objs) do - if obj:get_luaentity() ~= nil then - if obj:get_luaentity().name ~= "throwing:arrow_teleport_entity" and obj:get_luaentity().name ~= "__builtin:item" then + local newpos = self.object:getpos() + 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 + if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then if self.player ~= "" then local player = minetest.get_player_by_name(self.player) if player then - player:setpos(pos) + player:setpos(self.lastpos) end end self.object:remove() return end end - end - end - if self.lastpos.x~= nil then - if node.name ~= "air" then - if self.player ~= "" then - local player = minetest.get_player_by_name(self.player) - if player then - player:setpos(self.lastpos) + if node.name ~= "air" then + if self.player ~= "" then + local player = minetest.get_player_by_name(self.player) + if player then + player:setpos(self.lastpos) + end end + self.object:remove() + return end - self.object:remove() - return + self.lastpos={x=pos.x, y=pos.y, z=pos.z} 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 minetest.register_entity("throwing:arrow_teleport_entity", THROWING_ARROW_ENTITY) diff --git a/mods/throwing/tnt_arrow.lua b/mods/throwing/tnt_arrow.lua index 441b4f28..fcabda93 100755 --- a/mods/throwing/tnt_arrow.lua +++ b/mods/throwing/tnt_arrow.lua @@ -244,26 +244,24 @@ end -- Back to the arrow THROWING_ARROW_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime - local pos = self.object:getpos() - 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) - for k, obj in pairs(objs) do - 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() + local newpos = self.object:getpos() + 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 + if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then boom(pos) + self.object:remove() + return end end - end - end - if self.lastpos.x~=nil then - if node.name ~= "air" then - self.object:remove() - boom(self.lastpos) + if node.name ~= "air" then + boom(pos) + self.object:remove() + return + end end end self.lastpos={x=pos.x, y=pos.y, z=pos.z} diff --git a/mods/throwing/torch_arrow.lua b/mods/throwing/torch_arrow.lua index 4b39c3ba..ab3d565d 100755 --- a/mods/throwing/torch_arrow.lua +++ b/mods/throwing/torch_arrow.lua @@ -31,7 +31,6 @@ minetest.register_node("throwing:arrow_torch_box", { local THROWING_ARROW_ENTITY={ physical = false, - timer=0, visual = "wielditem", visual_size = {x=0.1, y=0.1}, textures = {"throwing:arrow_torch_box"}, @@ -42,41 +41,35 @@ local THROWING_ARROW_ENTITY={ } THROWING_ARROW_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime local newpos = self.object:getpos() - for _, pos in pairs(get_trajectoire(self, newpos)) do - local node = minetest.get_node(pos) - - if self.timer>0.2 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}, 0.5) for k, obj in pairs(objs) do - if obj:get_luaentity() ~= nil then - if obj:get_luaentity().name ~= "throwing:arrow_torch_entity" and obj:get_luaentity().name ~= "__builtin:item" then - local damage = 0.5 - obj:punch(self.object, 1.0, { - full_punch_interval=1.0, - damage_groups={fleshy=damage}, - }, nil) - local toughness = 0.9 - if math.random() < toughness then - 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') - end - else - minetest.add_item(pos, 'default:stick') + if throwing_is_player(self.player, obj) or throwing_is_entity(obj) then + local damage = 0.5 + obj:punch(self.object, 1.0, { + full_punch_interval=1.0, + damage_groups={fleshy=damage}, + }, nil) + local toughness = 0.9 + if math.random() < toughness then + 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') end - self.object:remove() - return + else + minetest.add_item(pos, 'default:stick') end + self.object:remove() + return end end - end - if self.lastpos.x~= nil then if node.name ~= "air" then local player = minetest.get_player_by_name(self.player) 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 minetest.is_protected(self.lastpos, self.player) and node.diggable ~= false then local dir=vector.direction(self.lastpos, pos) @@ -93,8 +86,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) self.object:remove() return end + self.lastpos={x=pos.x, y=pos.y, z=pos.z} end - self.lastpos={x=pos.x, y=pos.y, z=pos.z} end self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z} end