From bd24c15db4a3c7cdec24f1980ad3079c8d29b5be Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Sat, 6 Sep 2014 21:07:57 +0100 Subject: [PATCH] Screwdriver rewrite --- mods/screwdriver/init.lua | 135 +++++----------------- mods/screwdriver/textures/screwdriver.png | Bin 769 -> 286 bytes mods/screwdriver/textures/tool_mode1.png | Bin 211 -> 0 bytes mods/screwdriver/textures/tool_mode2.png | Bin 360 -> 0 bytes mods/screwdriver/textures/tool_mode3.png | Bin 367 -> 0 bytes mods/screwdriver/textures/tool_mode4.png | Bin 268 -> 0 bytes 6 files changed, 29 insertions(+), 106 deletions(-) delete mode 100644 mods/screwdriver/textures/tool_mode1.png delete mode 100644 mods/screwdriver/textures/tool_mode2.png delete mode 100644 mods/screwdriver/textures/tool_mode3.png delete mode 100644 mods/screwdriver/textures/tool_mode4.png diff --git a/mods/screwdriver/init.lua b/mods/screwdriver/init.lua index 6e56038..59c0044 100644 --- a/mods/screwdriver/init.lua +++ b/mods/screwdriver/init.lua @@ -1,52 +1,3 @@ - -local mode_text = { - {"Change rotation, Don't change axisdir."}, - {"Keep choosen face in front then rotate it."}, - {"Change axis dir, Reset rotation."}, - {"Bring top in front then rotate it."}, -} - -local opposite_faces = { - [0] = 5, - [1] = 2, - [2] = 1, - [3] = 4, - [4] = 3, - [5] = 0, -} - -local function screwdriver_setmode(user,itemstack) - local player_name = user:get_player_name() - local item = itemstack:to_table() - local mode = tonumber(itemstack:get_metadata()) - if not mode then - minetest.chat_send_player(player_name, "Use while sneaking to change screwdriwer modes.") - mode = 0 - end - mode = mode + 1 - if mode == 5 then - mode = 1 - end - minetest.chat_send_player(player_name, "Screwdriver mode : "..mode.." - "..mode_text[mode][1] ) - itemstack:set_name("screwdriver:screwdriver"..mode) - itemstack:set_metadata(mode) - return itemstack -end - -local function get_node_face(pointed_thing) - local ax, ay, az = pointed_thing.above.x, pointed_thing.above.y, pointed_thing.above.z - local ux, uy, uz = pointed_thing.under.x, pointed_thing.under.y, pointed_thing.under.z - if ay > uy then return 0 -- Top - elseif az > uz then return 1 -- Z+ side - elseif az < uz then return 2 -- Z- side - elseif ax > ux then return 3 -- X+ side - elseif ax < ux then return 4 -- X- side - elseif ay < uy then return 5 -- Bottom - else - error("pointed_thing.above and under are the same!") - end -end - local function nextrange(x, max) x = x + 1 if x > max then @@ -55,21 +6,21 @@ local function nextrange(x, max) return x end -local function screwdriver_handler(itemstack, user, pointed_thing) +-- Handles rotation +local function screwdriver_handler(itemstack, user, pointed_thing, mode) if pointed_thing.type ~= "node" then return end + local pos = pointed_thing.under local keys = user:get_player_control() local player_name = user:get_player_name() - local mode = tonumber(itemstack:get_metadata()) - if not mode or keys["sneak"] == true then - return screwdriver_setmode(user, itemstack) - end + if minetest.is_protected(pos, user:get_player_name()) then minetest.record_protection_violation(pos, user:get_player_name()) return end + local node = minetest.get_node(pos) local ndef = minetest.registered_nodes[node.name] if not ndef or not ndef.paramtype2 == "facedir" or @@ -78,47 +29,22 @@ local function screwdriver_handler(itemstack, user, pointed_thing) node.param2 == nil then return end - -- Get ready to set the param2 + + -- Set param2 local n = node.param2 local axisdir = math.floor(n / 4) local rotation = n - axisdir * 4 if mode == 1 then n = axisdir * 4 + nextrange(rotation, 3) - elseif mode == 2 then - -- If you are pointing at the axisdir face or the - -- opposite one then you can just rotate the node. - -- Otherwise change the axisdir, avoiding the facing - -- and opposite axes. - local face = get_node_face(pointed_thing) - if axisdir == face or axisdir == opposite_faces[face] then - n = axisdir * 4 + nextrange(rotation, 3) - else - axisdir = nextrange(axisdir, 5) - -- This is repeated because switching from the face - -- can move to to the opposite and vice-versa - if axisdir == face or axisdir == opposite_faces[face] then - axisdir = nextrange(axisdir, 5) - end - if axisdir == face or axisdir == opposite_faces[face] then - axisdir = nextrange(axisdir, 5) - end - n = axisdir * 4 - end elseif mode == 3 then n = nextrange(axisdir, 5) * 4 - elseif mode == 4 then - local face = get_node_face(pointed_thing) - if axisdir == face then - n = axisdir * 4 + nextrange(rotation, 3) - else - n = face * 4 - end end - --print (dump(axisdir..", "..rotation)) + node.param2 = n minetest.swap_node(pos, node) + local item_wear = tonumber(itemstack:get_wear()) - item_wear = item_wear + 327 + item_wear = item_wear + 300 -- was 327 if item_wear > 65535 then itemstack:clear() return itemstack @@ -127,6 +53,21 @@ local function screwdriver_handler(itemstack, user, pointed_thing) return itemstack end +-- Screwdriver +minetest.register_tool("screwdriver:screwdriver", { + description = "Screwdriver (left-click rotates face, right-click rotates axis)", + inventory_image = "screwdriver.png", + on_use = function(itemstack, user, pointed_thing) + screwdriver_handler(itemstack, user, pointed_thing, 1) + return itemstack + end, + on_place = function(itemstack, user, pointed_thing) + screwdriver_handler(itemstack, user, pointed_thing, 3) + return itemstack + end, +}) + + minetest.register_craft({ output = "screwdriver:screwdriver", recipe = { @@ -135,25 +76,7 @@ minetest.register_craft({ } }) -minetest.register_tool("screwdriver:screwdriver", { - description = "Screwdriver", - inventory_image = "screwdriver.png", - on_use = function(itemstack, user, pointed_thing) - screwdriver_handler(itemstack, user, pointed_thing) - return itemstack - end, -}) - -for i = 1, 4 do - minetest.register_tool("screwdriver:screwdriver"..i, { - description = "Screwdriver in Mode "..i, - inventory_image = "screwdriver.png^tool_mode"..i..".png", - wield_image = "screwdriver.png", - groups = {not_in_creative_inventory=1}, - on_use = function(itemstack, user, pointed_thing) - screwdriver_handler(itemstack, user, pointed_thing) - return itemstack - end, - }) -end - +minetest.register_alias("screwdriver:screwdriver1", "screwdriver:screwdriver") +minetest.register_alias("screwdriver:screwdriver2", "screwdriver:screwdriver") +minetest.register_alias("screwdriver:screwdriver3", "screwdriver:screwdriver") +minetest.register_alias("screwdriver:screwdriver4", "screwdriver:screwdriver") diff --git a/mods/screwdriver/textures/screwdriver.png b/mods/screwdriver/textures/screwdriver.png index 672692a160136e295ba0d97be42734eeedba7fd8..f471756d4239d51092fb9bbe957a78fe6275b639 100644 GIT binary patch delta 270 zcmV+p0rCEU2A%?t8Gi!+002a!ipBr{05ecbR7E%d04^U5J0}uEEfi2S7+5(RT|F6a zOCy6g@ad`<4}qOaK4?0d!JMQvg8b*k%9#0GUZd zK~y-)z0XS$!ypU;P{-g;6Ks0_)0U>wrA1fOR&RtM+9$5WeSc&OL`G)Lj6@4L=e$ag z;|2p9v00#u)z7%lKgT(qKx9NbpdgyL6ZBuvHi8+7VDrOkak4F7^&QPjtRLJfz^Il<3B&V2z21fE0zeP}CR%6$(YICb|-$Z9^?ZBgLqZ z*`@FEyh}`X?%oXxPjYkfy7_+Zob$S7)zpY}6zv^1;dZ;hJ%8L{8G>c_Ioy*Tym)ED z?d~2-xLo`oo#rl#jlYN8;l$LZ&zPN?#|OIuLzZEyRJda!sJS=Z@5N2KX}VW#{MY9L!y}_>AIle?Q)hjbqX?C3S!S<`))m@zP~J z0BP2J{R8;+{eK7M<`-D_;?gpn(s){0TKOObo(!O^y#t+QGfp=(v$05Jp-RDt3&1$98c zd0NPlbPkAg8b@PcGz&MTD^R8rP)v8JPJw14A+&->`yn49H!&DAZ?PgHjP^i5M_>q} zgdkMYz8LC+LZorYxf8*(3xv>zp-d}vLZCNi2yNDxlLgT*@<33l#qyQ6Cx8!8LZB1* zYKF*)l@Xzp{saDjXe?ACIm({_WJRz~^KY>4W@E~T31k4S2)fxb{q76rfiO^LrCwk+ m3+G*#nn0wg0>Ik7+UgHs7&bQZFYFco0000ym)PKLmBfxtsY+6ZC%l!T)|9_W1Yu5Gk3~I4HaKWLW zZsCKsnjh^gJbvxpCB?sr`2}yoG`=2YH(7&M4T0X{Z`inyK|)%p!Ej2yB-7#qk)EbN11`6N8WOCF85oY--BLLF>zZdkS2B3I L`njxgN@xNA4d+$c diff --git a/mods/screwdriver/textures/tool_mode2.png b/mods/screwdriver/textures/tool_mode2.png deleted file mode 100644 index 2043d8f61ba03c0b3d5db84c3f9a109ef79e2a58..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 360 zcmV-u0hj)XP)t zc~VdtQ&JmPRvlbg9%Eo3WMUy{W+QEDByVgbac?Dgb|`>;D}#Y6nwK-6oHeGRH>ssK ztEV}+wLQeZPtD0_&dY7m&w195bbds)eUkf@sEj7eb5|BOUw@?ey@`FPX*A+=A-> znq9aVLbEfo0GgX~KY%tq^3Z6Sc@TR1nn3W|_U55h`?n`)h6<)59LB@|00000mPps9(VxtWlK zxsa8mu(g%2t&NDit%!rYsH20Zi?f)Ui@3X+xVNW-pO0ila(1S2VZLf7j zQZ8Spxqh|t#cdaHRIl$x%cnPe{gT{gZoP!K3MVS!AirTAO)b~7)yfuf*Bm1 z-ADs+T0C7GLnI{M9`qDzG7w=o5XNMoblxISBw!B1#S7o<=ZK#;e@Zp9z-norfFA#Z z8IMvkZ~ta$`ucm})s0VsohRfKE2PRFQeQaNL8QNoH^16LXwtTj39gU#Bu_nLDZ zYkotBKnC-Rrn@qEyLKMg{OYt;^X#41Y;)&kd-yDBDo8bu_;Z(k&Q5M!Z%GMI$T4`j L`njxgN@xNAOWBI( diff --git a/mods/screwdriver/textures/tool_mode4.png b/mods/screwdriver/textures/tool_mode4.png deleted file mode 100644 index c925314686682ce106d468632459b9c9213cae30..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 268 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyQ2{<7u0UE$lwDGSLsf-GU5!Uy zkKfQhz}Qg0+)T*AT*%5&*xE|i-A&xjN7CO{D!^YVu&y#9Og1uHHa=E9B}sAfdh4wl zZMJW+J$f+c*rCuH*Lv>Wn(^TNl1C3#W|?JG15IZv3GxeOaCmkj4aiCGba4!+xb^mo zrBH){fXl@~#*#Z;g{;5+T{pQnp^xWp=KidcPjCB0d}h>O4rbE1X&NJ~*ZaXHFx z!9y7y#=7p_2&P>o*S9fnon_qfRdV4uTYeR0iA2o>hgwhFzyJNNsTP~Rx$nkopj`}} Lu6{1-oD!M