From 861a36f45caf56a7c1a1365da9b0171c6142e8c2 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Wed, 5 Jan 2022 12:48:36 +0100 Subject: [PATCH] Add screwdriver tool --- basis/fly_lib.lua | 6 +- basis/lib.lua | 47 +++++++++- doc/items.lua | 1 + doc/manual_DE.lua | 13 +++ doc/manual_EN.lua | 13 +++ init.lua | 1 + locale/techage.de.tr | 5 ++ locale/template.txt | 5 ++ manuals/manual_ta3_DE.md | 15 +++- manuals/manual_ta3_EN.md | 15 +++- manuals/toc_DE.md | 1 + manuals/toc_EN.md | 1 + textures/techage_screwdriver.png | Bin 0 -> 290 bytes tools/screwdriver.lua | 142 +++++++++++++++++++++++++++++++ 14 files changed, 252 insertions(+), 13 deletions(-) create mode 100644 textures/techage_screwdriver.png create mode 100644 tools/screwdriver.lua diff --git a/basis/fly_lib.lua b/basis/fly_lib.lua index b20a6ae..a9064b7 100644 --- a/basis/fly_lib.lua +++ b/basis/fly_lib.lua @@ -694,11 +694,11 @@ function flylib.rotate_nodes(pos, posses1, rot) for i, pos1 in ipairs(posses1) do local node = techage.get_node_lvm(pos1) if rot == "l" then - param2 = techage.param2_turn_left(node.param2) - elseif rot == "r" then param2 = techage.param2_turn_right(node.param2) + elseif rot == "r" then + param2 = techage.param2_turn_left(node.param2) else - param2 = techage.param2_turn_left(techage.param2_turn_left(node.param2)) + param2 = techage.param2_turn_right(techage.param2_turn_right(node.param2)) end if not minetest.is_protected(pos1, owner) and is_simple_node(pos1) then minetest.remove_node(pos1) diff --git a/basis/lib.lua b/basis/lib.lua index 99deec8..edbe7c1 100644 --- a/basis/lib.lua +++ b/basis/lib.lua @@ -80,13 +80,56 @@ function techage.facedir_to_rotation(facedir) end function techage.param2_turn_left(param2) - return (RotationViaYAxis[param2] or RotationViaYAxis[0])[1] + return (RotationViaYAxis[param2] or RotationViaYAxis[0])[2] end function techage.param2_turn_right(param2) - return (RotationViaYAxis[param2] or RotationViaYAxis[0])[2] + return (RotationViaYAxis[param2] or RotationViaYAxis[0])[1] end +-- Roll a block in north direction (south is vice versa) +local RollNorth = { + {0,4,22,8}, + {1,5,23,9}, + {2,6,20,10}, + {3,7,21,11}, + {12,13,14,15}, + {16,19,18,17}, +} +-- Roll a block in east direction (west is vice versa) +local RollEast = { + {0,12,20,16}, + {1,13,21,17}, + {2,14,22,18}, + {3,15,23,19}, + {4,7,6,5}, + {8,9,10,11}, +} + +-- Generate a table for all facedir and param2 values: +-- TurnUp[facedir][param2] = new_param2 +local TurnUp = {[0] = {}, {}, {}, {}} + +for i = 1,6 do + for j = 1,4 do + local idx = RollNorth[i][j] + TurnUp[0][idx] = RollNorth[i][j == 4 and 1 or j + 1] -- north + TurnUp[2][idx] = RollNorth[i][j == 1 and 4 or j - 1] -- south + + idx = RollEast[i][j] + TurnUp[1][idx] = RollEast[i][j == 4 and 1 or j + 1] -- east + TurnUp[3][idx] = RollEast[i][j == 1 and 4 or j - 1] -- west + end +end + +-- facedir is from the players (0..3) +-- param2 is from the node (0..23) +function techage.param2_turn_up(facedir, param2) + return TurnUp[facedir % 4][param2 % 24] +end + + + ------------------------------------------------------------------------------- -- Rotate nodes around the center ------------------------------------------------------------------------------- diff --git a/doc/items.lua b/doc/items.lua index de6dc6c..0ee4745 100644 --- a/doc/items.lua +++ b/doc/items.lua @@ -85,6 +85,7 @@ techage.Items = { ta3_powerswitchbox = "techage:powerswitch_box", ta3_powerterminal = "techage:ta3_power_terminal", ta3_trowel = "techage:trowel", + ta3_screwdriver = "techage:screwdriver", ta3_tinygenerator = "techage:tiny_generator", ta3_akkublock = "techage:ta3_akku", ta3_furnace = "techage:ta3_furnace_pas", diff --git a/doc/manual_DE.lua b/doc/manual_DE.lua index 3ef0398..9c8042a 100644 --- a/doc/manual_DE.lua +++ b/doc/manual_DE.lua @@ -139,6 +139,7 @@ techage.manual_DE.aTitel = { "3,TechAge Programmer", "3,TechAge Kelle / Trowel", "3,TA3 Bohrgestängezange / TA3 Drill Pipe Wrench", + "3,Techage Schraubendreher", "1,TA4: Gegenwart", "2,Windkraftanlage", "3,TA4 Windkraftanlage / Wind Turbine", @@ -1268,6 +1269,15 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", + "Der Techage Schraubendreher dient als Ersatz für den normalen Schraubendreher. Es besitzt folgende Funktionen:\n".. + "\n".. + " - Linksklick: Den Block nach links drehen\n".. + " - Rechtsklick: Die sichtbare Seite des Blockes nach oben drehen\n".. + " - Shift+Linksklick: Ausrichtung des angeklickten Blockes speichern\n".. + " - Shift+Rechtsklick: Die gespeicherte Ausrichtung auf den angeklickten Block anwenden\n".. + "\n".. + "\n".. + "\n", "Regenerative Energiequellen wie Wind\\, Sonne und Biokraft helfen dir\\, das Ölzeitalter zu verlassen. Mit modernen Technologien und intelligenten Maschinen machst du dich auf in die Zukunft.\n".. "\n".. "\n".. @@ -2198,6 +2208,7 @@ techage.manual_DE.aItemName = { "ta3_programmer", "ta3_trowel", "ta3_drill_pipe_wrench", + "ta3_screwdriver", "techage_ta4", "", "ta4_windturbine", @@ -2446,6 +2457,7 @@ techage.manual_DE.aPlanTable = { "", "", "", + "", "ta4_windturbine", "", "", @@ -2552,3 +2564,4 @@ techage.manual_DE.aPlanTable = { "", "", } + diff --git a/doc/manual_EN.lua b/doc/manual_EN.lua index 024086f..27faf5e 100644 --- a/doc/manual_EN.lua +++ b/doc/manual_EN.lua @@ -139,6 +139,7 @@ techage.manual_EN.aTitel = { "3,TechAge Programmer", "3,TechAge Trowel / Trowel", "3,TA3 drill pipe wrench", + "3,Techage Screwdriver", "1,TA4: Present", "2,Wind Turbine", "3,TA4 Wind Turbine", @@ -1266,6 +1267,15 @@ techage.manual_EN.aText = { "\n".. "\n".. "\n", + "The Techage Screwdriver serves as a replacement for the normal screwdriver. It has the following functions:\n".. + "\n".. + " - Left click: turn the block to the left\n".. + " - Right click: turn the visible side of the block upwards\n".. + " - Shift + left click: save the alignment of the clicked block\n".. + " - Shift + right click: apply the saved alignment to the clicked block\n".. + "\n".. + " \n".. + "\n", "Renewable energy sources such as wind\\, sun and biofuels help you to leave the oil age. With modern technologies and intelligent machines you set out into the future.\n".. "\n".. "\n".. @@ -2193,6 +2203,7 @@ techage.manual_EN.aItemName = { "ta3_programmer", "ta3_trowel", "ta3_drill_pipe_wrench", + "ta3_screwdriver", "techage_ta4", "", "ta4_windturbine", @@ -2440,6 +2451,7 @@ techage.manual_EN.aPlanTable = { "", "", "", + "", "ta4_windturbine", "", "", @@ -2545,3 +2557,4 @@ techage.manual_EN.aPlanTable = { "", "", } + diff --git a/init.lua b/init.lua index 50810a8..71f83e4 100644 --- a/init.lua +++ b/init.lua @@ -228,6 +228,7 @@ dofile(MP.."/tools/repairkit.lua") dofile(MP.."/tools/pipe_wrench.lua") dofile(MP.."/basic_machines/blackhole.lua") dofile(MP.."/basic_machines/forceload.lua") +dofile(MP.."/tools/screwdriver.lua") -- Lamps dofile(MP.."/lamps/lib.lua") diff --git a/locale/techage.de.tr b/locale/techage.de.tr index fda454e..58208ef 100644 --- a/locale/techage.de.tr +++ b/locale/techage.de.tr @@ -1049,6 +1049,11 @@ TA4 Rotor Blade=TA4 Rotorblatt TA4 Wind Turbine=TA4 Windkraftanlage TA4 Wind Turbine Nacelle=TA4 Windkraftanlagengondel +### screwdriver.lua ### + +Block alignment stored!=Blockausrichtung gespeichert! +Techage Screwdriver@n(See: TA3 > Tools)=Techage Schraubendreher@n(Siehe: TA3 > Werkzeuge) + ### sensorchest.lua ### Allow public chest access=Erlaube öffentlichen Zugriff diff --git a/locale/template.txt b/locale/template.txt index 6a51b06..6d1ce2d 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -1049,6 +1049,11 @@ TA4 Rotor Blade= TA4 Wind Turbine= TA4 Wind Turbine Nacelle= +### screwdriver.lua ### + +Block alignment stored!= +Techage Screwdriver@n(See: TA3 > Tools)= + ### sensorchest.lua ### Allow public chest access= diff --git a/manuals/manual_ta3_DE.md b/manuals/manual_ta3_DE.md index 6916f56..e44f9f7 100644 --- a/manuals/manual_ta3_DE.md +++ b/manuals/manual_ta3_DE.md @@ -836,8 +836,6 @@ Mit Shift+Rechtsklick kann bei einigen Blöcken ein erweitertes Menü geöffnet [ta3_end_wrench|image] - - ### TechAge Programmer Mit dem Programmer können Blocknummern mit einem Rechtsklick von mehreren Blöcken eingesammelt und mit einem Linksklick in einen Block wie Taster/Schalter geschrieben werden. @@ -845,8 +843,6 @@ Wird in die Luft geklickt, wird der interne Speicher gelöscht. [ta3_programmer|image] - - ### TechAge Kelle / Trowel Die Kelle dient zum Verputzen von Stromkabel. Siehe dazu "TA Stromkabel". @@ -859,3 +855,14 @@ Die Kelle dient zum Verputzen von Stromkabel. Siehe dazu "TA Stromkabel". Mit diesem Werkzeug lassen sich die Bohrgestängezange Blöcke wieder entfernen, wenn dort bspw. ein Tunnel durch soll. [ta3_drill_pipe_wrench|image] + +### Techage Schraubendreher + +Der Techage Schraubendreher dient als Ersatz für den normalen Schraubendreher. Es besitzt folgende Funktionen: + +- Linksklick: Den Block nach links drehen +- Rechtsklick: Die sichtbare Seite des Blockes nach oben drehen +- Shift+Linksklick: Ausrichtung des angeklickten Blockes speichern +- Shift+Rechtsklick: Die gespeicherte Ausrichtung auf den angeklickten Block anwenden + +[ta3_screwdriver|image] \ No newline at end of file diff --git a/manuals/manual_ta3_EN.md b/manuals/manual_ta3_EN.md index 82b6f81..b24434c 100644 --- a/manuals/manual_ta3_EN.md +++ b/manuals/manual_ta3_EN.md @@ -829,7 +829,6 @@ With Shift + right click an extended menu can be opened for some blocks. Dependi [ta3_end_wrench|image] - ### TechAge Programmer With the programmer, block numbers can be collected from several blocks with a right click and written into a block like a button / switch with a left click. @@ -837,17 +836,25 @@ If you click in the air, the internal memory is deleted. [ta3_programmer|image] - - ### TechAge Trowel / Trowel The trowel is used for plastering power cables. See also "TA power cable". [ta3_trowel|image] - ### TA3 drill pipe wrench This tool can be used to remove the drill pipe blocks if, for example, a tunnel is to pass through there. [ta3_drill_pipe_wrench|image] + +### Techage Screwdriver + +The Techage Screwdriver serves as a replacement for the normal screwdriver. It has the following functions: + +- Left click: turn the block to the left +- Right click: turn the visible side of the block upwards +- Shift + left click: save the alignment of the clicked block +- Shift + right click: apply the saved alignment to the clicked block + +[ta3_screwdriver|image] diff --git a/manuals/toc_DE.md b/manuals/toc_DE.md index b55e835..593d91b 100644 --- a/manuals/toc_DE.md +++ b/manuals/toc_DE.md @@ -138,6 +138,7 @@ - [TechAge Programmer](./manual_ta3_DE.md#techage-programmer) - [TechAge Kelle / Trowel](./manual_ta3_DE.md#techage-kelle--trowel) - [TA3 Bohrgestängezange / TA3 Drill Pipe Wrench](./manual_ta3_DE.md#ta3-bohrgestängezange--ta3-drill-pipe-wrench) + - [Techage Schraubendreher](./manual_ta3_DE.md#techage-schraubendreher) - [TA4: Gegenwart](./manual_ta4_DE.md#ta4:-gegenwart) - [Windkraftanlage](./manual_ta4_DE.md#windkraftanlage) - [TA4 Windkraftanlage / Wind Turbine](./manual_ta4_DE.md#ta4-windkraftanlage--wind-turbine) diff --git a/manuals/toc_EN.md b/manuals/toc_EN.md index 359853c..7847f76 100644 --- a/manuals/toc_EN.md +++ b/manuals/toc_EN.md @@ -138,6 +138,7 @@ - [TechAge Programmer](./manual_ta3_EN.md#techage-programmer) - [TechAge Trowel / Trowel](./manual_ta3_EN.md#techage-trowel--trowel) - [TA3 drill pipe wrench](./manual_ta3_EN.md#ta3-drill-pipe-wrench) + - [Techage Screwdriver](./manual_ta3_EN.md#techage-screwdriver) - [TA4: Present](./manual_ta4_EN.md#ta4:-present) - [Wind Turbine](./manual_ta4_EN.md#wind-turbine) - [TA4 Wind Turbine](./manual_ta4_EN.md#ta4-wind-turbine) diff --git a/textures/techage_screwdriver.png b/textures/techage_screwdriver.png new file mode 100644 index 0000000000000000000000000000000000000000..e80ac2a149d72c27f13c595c635101f9b4c38152 GIT binary patch literal 290 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dyEa{HEjtmSN`?>!lvI6;x#X;^) z4C~IxyaaM=0(?STeKHGsZog1yTwiehcJRsTJ|UlcZ@zMKafywNW}kguOHLc zA_q&rqV16vFMpo&|Nr$FN^g_oZ`Cq0H_x2AOj|zcNli{i!m-Da9KX#AnXWMTsWQm> zcIMy9S3Gek>V4FeQ%Xl;*KcD9?eCUel=1PCimU&+BUy$vLdGJQ&U@6KXc_aqSj^0& h<9O=+295t$*%c159-pVWIT7dt22WQ%mvv4FO#m5fY5xEK literal 0 HcmV?d00001 diff --git a/tools/screwdriver.lua b/tools/screwdriver.lua new file mode 100644 index 0000000..770d21d --- /dev/null +++ b/tools/screwdriver.lua @@ -0,0 +1,142 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2020-2022 Joachim Stolberg + + AGPL v3 + See LICENSE.txt for more information + + Screwdriver + +]]-- +if minetest.global_exists("screwdriver") then + +local S = techage.S +local M = minetest.get_meta + +local USES = 2000 + +local function base_checks(user, pointed_thing) + if pointed_thing.type ~= "node" then + return false + end + + if not user then + return false + end + + local pos = pointed_thing.under + local player_name = user:get_player_name() + + if minetest.is_protected(pos, player_name) then + return false + end + + local node = minetest.get_node(pos) + local ndef = minetest.registered_nodes[node.name] + + if not ndef then + return false + end + + if ndef.on_rotate == screwdriver.disallow then + return false + end + + local yaw = user:get_look_horizontal() + local dir = minetest.yaw_to_dir(yaw) + local facedir = minetest.dir_to_facedir(dir) + print("base_checks", facedir, ndef.paramtype2) + + return true, pos, player_name, facedir, node, ndef +end + + +local function store_node_param2(user, node) + user:get_meta():set_string("techage_screwdriver_param2", node.param2) + minetest.chat_send_player(user:get_player_name(), S("Block alignment stored!")) +end + +local function turn_node_param2(pos, node, user) + local param2 = user:get_meta():get_string("techage_screwdriver_param2") + minetest.swap_node(pos, {name = node.name, param2 = param2}) +end + +local function turn_left(pos, node) + local param2 = techage.param2_turn_left(node.param2) + minetest.swap_node(pos, {name = node.name, param2 = param2}) +end + +local function turn_up(pos, node, facedir) + local param2 = techage.param2_turn_up(facedir, node.param2) + minetest.swap_node(pos, {name = node.name, param2 = param2}) +end + + +-- on_use == on_left_click == turn left +local function on_use(itemstack, user, pointed_thing) + local res, pos, player_name, facedir, node, ndef = base_checks(user, pointed_thing) + if res then + if ndef.paramtype2 == "facedir" then + if user:get_player_control().sneak then + store_node_param2(user, node) + else + turn_left(pos, node) + end + else + return screwdriver.handler(itemstack, user, pointed_thing, screwdriver.ROTATE_FACE, USES) + end + + if not minetest.is_creative_enabled(player_name) then + itemstack:add_wear(65535 / (USES - 1)) + end + end + return itemstack +end + +-- on_place == on_right_click == turn up +local function on_place(itemstack, user, pointed_thing) + local res, pos, player_name, facedir, node, ndef = base_checks(user, pointed_thing) + if res then + if ndef.paramtype2 == "facedir" then + if ndef.on_rotate ~= screwdriver.rotate_simple then + if user:get_player_control().sneak then + turn_node_param2(pos, node, user) + else + turn_up(pos, node, facedir) + end + else + return itemstack + end + else + return screwdriver.handler(itemstack, user, pointed_thing, screwdriver.ROTATE_AXIS, USES) + end + + if not minetest.is_creative_enabled(player_name) then + itemstack:add_wear(65535 / (USES - 1)) + end + end + return itemstack +end + +minetest.register_tool("techage:screwdriver", { + description = S("Techage Screwdriver\n(See: TA3 > Tools)"), + inventory_image = "techage_screwdriver.png", + on_use = on_use, + on_place = on_place, + node_placement_prediction = "", + stack_max = 1, +}) + +minetest.register_craft({ + output = "techage:screwdriver", + recipe = { + {"", "default:diamond", ""}, + {"", "default:stick", ""}, + {"", "", ""}, + }, +}) + +end