From f1018dfaaf41854eb953011c3312edace9753af3 Mon Sep 17 00:00:00 2001 From: crabman77 Date: Wed, 29 Jul 2015 02:30:46 +0200 Subject: [PATCH] fixed mores bug in throwing mod enable dig_arrow --- mods/throwing/build_arrow.lua | 12 ++++++++---- mods/throwing/dig_arrow.lua | 14 ++++++++------ mods/throwing/fire_arrow.lua | 5 ++++- mods/throwing/fireworks_arrows.lua | 10 +++++++--- mods/throwing/functions.lua | 2 +- mods/throwing/shell_arrow.lua | 7 +++++-- mods/throwing/standard_arrows.lua | 9 ++++++--- mods/throwing/teleport_arrow.lua | 22 +++++++++++++++------- mods/throwing/throwing.conf | 2 +- mods/throwing/torch_arrow.lua | 13 ++++++++++--- 10 files changed, 65 insertions(+), 31 deletions(-) diff --git a/mods/throwing/build_arrow.lua b/mods/throwing/build_arrow.lua index fbf6dd25..1ced08a5 100755 --- a/mods/throwing/build_arrow.lua +++ b/mods/throwing/build_arrow.lua @@ -38,6 +38,9 @@ local THROWING_ARROW_ENTITY={ lastpos={}, collisionbox = {0,0,0,0,0,0}, node = "", + player = "", + inventory = false, + stack = false, } THROWING_ARROW_ENTITY.on_step = function(self, dtime) @@ -50,7 +53,6 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) 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 - self.object:remove() 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 @@ -63,6 +65,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) else minetest.add_item(self.lastpos, 'default:stick') end + self.object:remove() + return end end end @@ -70,18 +74,18 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) if self.lastpos.x~=nil then if node.name ~= "air" then - self.object:remove() 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 - if 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 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()}) else minetest.add_item(self.lastpos, {name=self.stack:get_name()}) end end minetest.add_item(self.lastpos, 'default:shovel_steel') + self.object:remove() end end self.lastpos={x=pos.x, y=pos.y, z=pos.z} diff --git a/mods/throwing/dig_arrow.lua b/mods/throwing/dig_arrow.lua index 2aa78906..119f4c40 100755 --- a/mods/throwing/dig_arrow.lua +++ b/mods/throwing/dig_arrow.lua @@ -37,6 +37,7 @@ local THROWING_ARROW_ENTITY={ textures = {"throwing:arrow_dig_box"}, lastpos={}, collisionbox = {0,0,0,0,0,0}, + player = "", } THROWING_ARROW_ENTITY.on_step = function(self, dtime) @@ -54,26 +55,27 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) full_punch_interval=1.0, damage_groups={fleshy=damage}, }, nil) - self.object:remove() if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15) minetest.add_item(self.lastpos, "throwing:arrow_dig") end + self.object:remove() + return end end end end if self.lastpos.x~=nil then - if node.name ~= "air" then - - if minetest.get_item_group(node.name, "unbreakable") == 0 - and areas:canInteract(self.lastpos, self.player:get_player_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(self.lastpos, self.player) and node.diggable ~= false then minetest.set_node(pos, {name = "air"}) + minetest.add_item(self.lastpos, node.name) end - minetest.add_item(self.lastpos, node.name) minetest.add_item(self.lastpos, "throwing:arrow_dig") self.object:remove() + return end end self.lastpos={x=pos.x, y=pos.y, z=pos.z} diff --git a/mods/throwing/fire_arrow.lua b/mods/throwing/fire_arrow.lua index 6898266c..fefa6283 100755 --- a/mods/throwing/fire_arrow.lua +++ b/mods/throwing/fire_arrow.lua @@ -37,6 +37,7 @@ local THROWING_ARROW_ENTITY={ textures = {"throwing:arrow_fire_box"}, lastpos={}, collisionbox = {0,0,0,0,0,0}, + player = "", } THROWING_ARROW_ENTITY.on_step = function(self, dtime) @@ -54,10 +55,11 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) full_punch_interval=1.0, damage_groups={fleshy=damage}, }, nil) - self.object:remove() if math.random(0,100) % 2 == 0 then -- 50% of chance to drop //MFF (Mg|07/27/15) minetest.add_item(self.lastpos, 'default:stick') end + self.object:remove() + return end end end @@ -67,6 +69,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) if node.name ~= "air" and node.name ~= "throwing:light" then minetest.set_node(self.lastpos, {name="fire:basic_flame"}) 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 diff --git a/mods/throwing/fireworks_arrows.lua b/mods/throwing/fireworks_arrows.lua index b0895104..392373bf 100755 --- a/mods/throwing/fireworks_arrows.lua +++ b/mods/throwing/fireworks_arrows.lua @@ -38,6 +38,7 @@ local function throwing_register_fireworks(color, desc) textures = {"throwing:arrow_fireworks_" .. color .. "_box"}, lastpos={}, collisionbox = {0,0,0,0,0,0}, + player = "", } local radius = 0.5 @@ -104,20 +105,23 @@ local function throwing_register_fireworks(color, desc) full_punch_interval=1.0, damage_groups={fleshy=damage}, }, nil) - self.object:remove() boom(pos) + self.object:remove() + return end end end end if self.timer > 2 then - self.object:remove() 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 - self.object:remove() boom(self.lastpos) + self.object:remove() + return end end if node.name == 'air' then diff --git a/mods/throwing/functions.lua b/mods/throwing/functions.lua index af10bd26..a3d9de9b 100755 --- a/mods/throwing/functions.lua +++ b/mods/throwing/functions.lua @@ -34,7 +34,7 @@ function throwing_shoot_arrow (itemstack, player, stiffness, is_cross) minetest.sound_play("throwing_bow_sound", {pos=playerpos}) end if obj:get_luaentity() then - obj:get_luaentity().player = player + 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) end diff --git a/mods/throwing/shell_arrow.lua b/mods/throwing/shell_arrow.lua index 77033ac1..ca6637d7 100755 --- a/mods/throwing/shell_arrow.lua +++ b/mods/throwing/shell_arrow.lua @@ -37,6 +37,7 @@ local THROWING_ARROW_ENTITY={ textures = {"throwing:arrow_shell_box"}, lastpos={}, collisionbox = {0,0,0,0,0,0}, + player = "", } local radius = 1 @@ -85,8 +86,9 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) full_punch_interval=1.0, damage_groups={fleshy=damage}, }, nil) - self.object:remove() boom(pos) + self.object:remove() + return end end end @@ -94,8 +96,9 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) 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 - self.object:remove() boom(self.lastpos) + self.object:remove() + return end end self.lastpos={x=pos.x, y=pos.y, z=pos.z} diff --git a/mods/throwing/standard_arrows.lua b/mods/throwing/standard_arrows.lua index 2cd621c8..f0b647c1 100755 --- a/mods/throwing/standard_arrows.lua +++ b/mods/throwing/standard_arrows.lua @@ -38,6 +38,7 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft) textures = {"throwing:arrow_" .. kind .. "_box"}, lastpos={}, collisionbox = {0,0,0,0,0,0}, + player = "", } THROWING_ARROW_ENTITY.on_step = function(self, dtime) @@ -56,7 +57,6 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft) full_punch_interval=1.0, damage_groups={fleshy=damage}, }, nil) - self.object:remove() if math.random() < toughness then if math.random(0,100) % 2 == 0 then minetest.add_item(self.lastpos, 'throwing:arrow_' .. kind) @@ -64,19 +64,22 @@ function throwing_register_arrow_standard (kind, desc, eq, toughness, craft) else minetest.add_item(self.lastpos, 'default:stick') end + self.object:remove() + 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 - self.object:remove() + 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 end self.lastpos={x=pos.x, y=pos.y, z=pos.z} diff --git a/mods/throwing/teleport_arrow.lua b/mods/throwing/teleport_arrow.lua index 6b5ba500..4b2b87e8 100755 --- a/mods/throwing/teleport_arrow.lua +++ b/mods/throwing/teleport_arrow.lua @@ -50,23 +50,31 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) 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 - self.object:remove() if self.player ~= "" then - self.player:setpos(pos) - self.player:get_inventory():add_item("main", ItemStack("default:stick 2")) + local player = minetest.get_player_by_name(self.player) + if player then + player:setpos(pos) + player:get_inventory():add_item("main", ItemStack("default:stick 2")) + end end + self.object:remove() + return end end end end - if self.lastpos.x~=nil then + if self.lastpos.x~= nil then if node.name ~= "air" then - self.object:remove() if self.player ~= "" then - self.player:setpos(self.lastpos) - self.player:get_inventory():add_item("main", ItemStack("default:stick 2")) + local player = minetest.get_player_by_name(self.player) + if player then + player:setpos(self.lastpos) + player:get_inventory():add_item("main", ItemStack("default:stick 2")) + end end + self.object:remove() + return end end self.lastpos={x=pos.x, y=pos.y, z=pos.z} diff --git a/mods/throwing/throwing.conf b/mods/throwing/throwing.conf index 46a1bf0f..ea87851b 100755 --- a/mods/throwing/throwing.conf +++ b/mods/throwing/throwing.conf @@ -18,7 +18,7 @@ DISABLE_AUTOMATED_ARBALEST = false -- Arrow -- Special Arrows DISABLE_TELEPORT_ARROW = false -DISABLE_DIG_ARROW = true -- Desactivated because too bugged +DISABLE_DIG_ARROW = false DISABLE_BUILD_ARROW = false DISABLE_TNT_ARROW = true -- Desactivated because too dangerous DISABLE_FIRE_ARROW = true -- Desactivated because too dangerous diff --git a/mods/throwing/torch_arrow.lua b/mods/throwing/torch_arrow.lua index 5f0e86ac..e12e3ca9 100755 --- a/mods/throwing/torch_arrow.lua +++ b/mods/throwing/torch_arrow.lua @@ -38,6 +38,7 @@ local THROWING_ARROW_ENTITY={ lastpos={}, collisionbox = {0,0,0,0,0,0}, node = "", + player = "", } THROWING_ARROW_ENTITY.on_step = function(self, dtime) @@ -55,7 +56,6 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) full_punch_interval=1.0, damage_groups={fleshy=damage}, }, nil) - self.object:remove() 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) @@ -64,6 +64,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) else minetest.add_item(self.lastpos, 'default:stick') end + self.object:remove() + return end end end @@ -71,8 +73,11 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) if self.lastpos.x~=nil then if node.name ~= "air" then - self.object:remove() - if not string.find(node.name, "water") and not string.find(node.name, "lava") and not string.find(node.name, "torch") 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") + 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) local wall=minetest.dir_to_wallmounted(dir) minetest.add_node(self.lastpos, {name="default:torch", param2 = wall}) @@ -84,6 +89,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) minetest.add_item(self.lastpos, 'default:stick') end end + self.object:remove() + return end end self.lastpos={x=pos.x, y=pos.y, z=pos.z}