From 0ead0b1e5a1c8ed9aa5d516c53a48e9683b70921 Mon Sep 17 00:00:00 2001 From: fairiestoy Date: Mon, 19 Aug 2013 02:38:59 +0200 Subject: Fixed Screwdriver Fixed a Bug which causes doors (if locked or not) to be opened by the screwdriver. It now makes a check if you are on valid ground. --- init.lua | 1 + screwdriver.lua | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 screwdriver.lua diff --git a/init.lua b/init.lua index a63beb6..ea99421 100644 --- a/init.lua +++ b/init.lua @@ -450,5 +450,6 @@ dofile(path.."/bucket.lua") dofile(path.."/doors.lua") dofile(path.."/fire.lua") dofile(path.."/chatcommands.lua") +dofile(path.."/screwdriver.lua") end ) diff --git a/screwdriver.lua b/screwdriver.lua new file mode 100644 index 0000000..079d65c --- /dev/null +++ b/screwdriver.lua @@ -0,0 +1,111 @@ +--[[ +Screwdriver replacement to fit the needs of the landrush mod. +Otherwise it will be possible to open doors without permission. +]] + +if minetest.get_modpath("screwdriver") then + -- Start overwriting the standard function + tmp_tool = minetest.registered_tools["screwdriver:screwdriver"] + if tmp_tool == nil then + print("Something went wrong when correcting the screwdriver...") + end + if tmp_tool.on_use == nil then + print( "tmp_tool.on_use is a nil value... ") + end + tmp_tool.on_use = function(itemstack, user, pointed_thing) + safe_screwdriver_handler(itemstack, user, pointed_thing) + return itemstack + end + minetest.registered_tools["screwdriver:screwdriver"] = tmp_tool + for i = 1,4,1 do + tmp_tool = minetest.registered_tools["screwdriver:screwdriver"..i] + tmp_tool.on_use = function(itemstack, user, pointed_thing) + safe_screwdriver_handler(itemstack, user, pointed_thing) + return itemstack + end + minetest.registered_tools["screwdriver:screwdriver"..i] = tmp_tool + end + print( "Rewritten screwdriver routines..." ) +end + + +function safe_screwdriver_handler (itemstack,user,pointed_thing) + local keys=user:get_player_control() + local player_name=user:get_player_name() + local item=itemstack:to_table() + if item["metadata"]=="" or keys["sneak"]==true then return screwdriver_setmode(user,itemstack) end + local mode=tonumber((item["metadata"])) + if pointed_thing.type~="node" then return end + local pos=minetest.get_pointed_thing_position(pointed_thing,above) + -- Landrush fix + if not landrush.can_interact( player_name, pos ) then + return nil + end + -- end fix + local node=minetest.get_node(pos) + local node_name=node.name + if minetest.registered_nodes[node_name].paramtype2 == "facedir" then + if minetest.registered_nodes[node_name].drawtype == "nodebox" then + if minetest.registered_nodes[node_name].node_box["type"]~="fixed" then return end + end + if node.param2==nil then return end + -- Get ready to set the param2 + local n = node.param2 + local axisdir=math.floor(n/4) + local rotation=n-axisdir*4 + if mode==1 then + rotation=rotation+1 + if rotation>3 then rotation=0 end + n=axisdir*4+rotation + end + + if mode==2 then + local ppos=user:getpos() + local pvect=user:get_look_dir() + local face=get_node_face(pos,ppos,pvect) + if face == nil then return end + local index=convertFaceToIndex(face) + local face1=faces_table[n*6+index+1] + local found = 0 + while found == 0 do + n=n+1 + if n>23 then n=0 end + if faces_table[n*6+index+1]==face1 then found=1 end + end + end + + if mode==3 then + axisdir=axisdir+1 + if axisdir>5 then axisdir=0 end + n=axisdir*4 + end + + if mode==4 then + local ppos=user:getpos() + local pvect=user:get_look_dir() + local face=get_node_face(pos,ppos,pvect) + if face == nil then return end + if axisdir == face then + rotation=rotation+1 + if rotation>3 then rotation=0 end + n=axisdir*4+rotation + else + n=face*4 + end + end + --print (dump(axisdir..", "..rotation)) + local meta = minetest.get_meta(pos) + local meta0 = meta:to_table() + node.param2 = n + minetest.set_node(pos,node) + meta = minetest.get_meta(pos) + meta:from_table(meta0) + local item=itemstack:to_table() + local item_wear=tonumber((item["wear"])) + item_wear=item_wear+327 + if item_wear>65535 then itemstack:clear() return itemstack end + item["wear"]=tostring(item_wear) + itemstack:replace(item) + return itemstack + end +end -- cgit v1.2.3 From 065543f3321218af9f9df7749608876110bf5ab8 Mon Sep 17 00:00:00 2001 From: fairiestoy Date: Wed, 21 Aug 2013 05:23:47 +0200 Subject: Added TNT workaround Added a quick workaround to avoid TNT set near claimed areas to destroy partial buildings or landscapes with the TNT exploit. Since overwriting the registered node functions seem not to work as expected, used the landrush own routines for this 'fix' --- init.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/init.lua b/init.lua index ea99421..2c925f8 100644 --- a/init.lua +++ b/init.lua @@ -252,6 +252,32 @@ function minetest.item_place(itemstack, placer, pointed_thing) owner = landrush.get_owner(pointed_thing.above) player = placer:get_player_name() if landrush.can_interact(player, pointed_thing.above) or itemstack:get_name() == "" then + -- add a workaround for TNT, since overwriting the registered node seems not to work + if itemstack:get_name() == "tnt:tnt" or itemstack:get_name() == "tnt:tnt_burning" then + local pos = pointed_thing.above + local temp_pos = pos + temp_pos.x = pos.x + 2 + if player ~= landrush.get_owner( temp_pos ) then + minetest.chat_send_player( player, "Do not place TNT near claimed areas..." ) + return itemstack + end + temp_pos.x = pos.x - 2 + if player ~= landrush.get_owner( temp_pos ) then + minetest.chat_send_player( player, "Do not place TNT near claimed areas..." ) + return itemstack + end + temp_pos.z = pos.z + 2 + if player ~= landrush.get_owner( temp_pos ) then + minetest.chat_send_player( player, "Do not place TNT near claimed areas..." ) + return itemstack + end + temp_pos.z = pos.z - 2 + if player ~= landrush.get_owner( temp_pos ) then + minetest.chat_send_player( player, "Do not place TNT near claimed areas..." ) + return itemstack + end + end + -- end of the workaround return landrush.default_place(itemstack, placer, pointed_thing) else if ( owner ~= nil ) then -- cgit v1.2.3