diff options
author | fairiestoy <johannesvk@web.de> | 2013-08-19 02:38:59 +0200 |
---|---|---|
committer | fairiestoy <johannesvk@web.de> | 2013-08-19 02:38:59 +0200 |
commit | 0ead0b1e5a1c8ed9aa5d516c53a48e9683b70921 (patch) | |
tree | f985258551e89853dd8200e42bc5a0d537921b37 | |
parent | 4792259f2851dbd466e9e92086d681827294f8a6 (diff) |
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.
-rw-r--r-- | init.lua | 1 | ||||
-rw-r--r-- | screwdriver.lua | 111 |
2 files changed, 112 insertions, 0 deletions
@@ -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 |