From b917f63dc01dd1085aaab3b4b0b3e5fa05524568 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sun, 6 Feb 2022 21:49:05 +0100 Subject: [PATCH] Add pack controller --- basis/fly_lib.lua | 8 +-- basis/lib.lua | 93 +++++++++++++++++++++++++++++- basis/pack_lib.lua | 28 ++++++++- locale/techage.de.tr | 2 +- move_controller/packcontainer.lua | 87 +++++++++++++++++----------- textures/techage_appl_pack.png | Bin 0 -> 245 bytes textures/techage_pack_storage.png | Bin 0 -> 635 bytes tools/screwdriver.lua | 3 +- 8 files changed, 175 insertions(+), 46 deletions(-) create mode 100644 textures/techage_appl_pack.png create mode 100644 textures/techage_pack_storage.png diff --git a/basis/fly_lib.lua b/basis/fly_lib.lua index 4ae48b2..671c1bc 100644 --- a/basis/fly_lib.lua +++ b/basis/fly_lib.lua @@ -692,13 +692,7 @@ 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_right(node.param2) - elseif rot == "r" then - param2 = techage.param2_turn_left(node.param2) - else - param2 = techage.param2_turn_right(techage.param2_turn_right(node.param2)) - end + param2 = techage.rotate_param2(node, rot) if not minetest.is_protected(pos1, owner) and is_simple_node(pos1) then minetest.remove_node(pos1) nodes2[#nodes2 + 1] = {pos = posses2[i], name = node.name, param2 = param2} diff --git a/basis/lib.lua b/basis/lib.lua index 6bf49dc..edaaf46 100644 --- a/basis/lib.lua +++ b/basis/lib.lua @@ -64,6 +64,10 @@ local FACEDIR_TO_ROT = {[0] = {x=0.000000, y=4.712389, z=3.141593}, } +-- 0 1 2 3 4 5 +local WALLMOUNTED_TO_RIGHT = {[0]=0, 1, 5, 4, 2, 3} +local WALLMOUNTED_TO_LEFT = {[0]=0, 1, 4, 5, 3, 2} + local RotationViaYAxis = {} for _,row in ipairs(ROTATION) do @@ -80,11 +84,11 @@ function techage.facedir_to_rotation(facedir) end function techage.param2_turn_left(param2) - return (RotationViaYAxis[param2] or RotationViaYAxis[0])[2] + return (RotationViaYAxis[param2] or RotationViaYAxis[0])[1] end function techage.param2_turn_right(param2) - return (RotationViaYAxis[param2] or RotationViaYAxis[0])[1] + return (RotationViaYAxis[param2] or RotationViaYAxis[0])[2] end -- Roll a block in north direction (south is vice versa) @@ -133,6 +137,91 @@ end ------------------------------------------------------------------------------- -- Rotate nodes around the center ------------------------------------------------------------------------------- +-- turn is one of "l", "r", "2l", "2r", or "" +function techage.rotate_param2(node, turn) + print("calc_node_param2", turn) + local ndef = minetest.registered_nodes[node.name] + if ndef then + print("calc_node_param2", ndef.paramtype2) + if ndef.paramtype2 == "facedir" then + if turn == "l" then + return techage.param2_turn_left(node.param2) + elseif turn == "r" then + return techage.param2_turn_right(node.param2) + elseif turn == "" then + return node.param2 + else + return techage.param2_turn_right(techage.param2_turn_right(node.param2)) + end + elseif ndef.paramtype2 == "colorfacedir" then + local param2 = math.floor(node.param2 % 32) + if turn == "l" then + param2 = techage.param2_turn_left(param2) + elseif turn == "r" then + param2 = techage.param2_turn_right(param2) + elseif turn == "" then + param2 = param2 + else + param2 = techage.param2_turn_right(param2) + param2 = techage.param2_turn_right(param2) + end + -- Add color again + return math.floor(node.param2 / 32) * 32 + param2 + elseif ndef.paramtype2 == "wallmounted" then + if turn == "l" then + return WALLMOUNTED_TO_LEFT[node.param2] + elseif turn == "r" then + return WALLMOUNTED_TO_RIGHT[node.param2] + elseif turn == "" then + return node.param2 + else + return WALLMOUNTED_TO_RIGHT[WALLMOUNTED_TO_RIGHT[node.param2]] + end + elseif ndef.paramtype2 == "colorwallmounted" then + local param2 = math.floor(node.param2 % 8) + if turn == "l" then + param2 = WALLMOUNTED_TO_LEFT[param2] + elseif turn == "r" then + param2 = WALLMOUNTED_TO_RIGHT[param2] + elseif turn == "" then + param2 = param2 + else + param2 = WALLMOUNTED_TO_RIGHT[param2] + param2 = WALLMOUNTED_TO_RIGHT[param2] + end + -- Add color again + return math.floor(node.param2 / 8) * 8 + param2 + elseif ndef.paramtype2 == "degrotate" then + local rot = (node.param2 * 1.5) + 360 + if turn == "l" then + rot = rot + 90 + elseif turn == "r" then + rot = rot - 90 + elseif turn == "" then + rot = rot + 0 + else + rot = rot + 180 + end + return math.floor((rot % 360) / 1.5) + elseif ndef.paramtype2 == "colordegrotate" then + local param2 = node.param2 % 32 + local rot = (param2 * 15) + 360 + if turn == "l" then + rot = rot + 90 + elseif turn == "r" then + rot = rot - 90 + elseif turn == "" then + rot = rot + 0 + else + rot = rot + 180 + end + -- Add color again + return math.floor(node.param2 / 32) * 32 + math.floor((rot % 360) / 15) + end + end + return node.param2 +end + function techage.positions_center(lpos) local c = {x=0, y=0, z=0} for _,v in ipairs(lpos) do diff --git a/basis/pack_lib.lua b/basis/pack_lib.lua index b425123..3b3c4a8 100644 --- a/basis/pack_lib.lua +++ b/basis/pack_lib.lua @@ -85,6 +85,14 @@ local function on_unpack_fallback(pos, name, param2, data) end end +-- cpos is the center pos +-- npos the the node pos +-- turn is one of "l", "r", "2l", "2r" +local function get_new_node_pos(cpos, npos, turn, item) + item.param2 = techage.rotate_param2(item, turn) + return techage.rotate_around_axis(npos, cpos, turn) +end + -- pack/unpack API functions function techage.pack_nodes(pos, pos_list) print("pack_nodes", P2S(pos), #pos_list) @@ -103,14 +111,32 @@ function techage.pack_nodes(pos, pos_list) return tbl end -function techage.unpack_nodes(pos, tbl) +function techage.unpack_nodes(pos, tbl, turn) + print("unpack_nodes", P2S(pos), turn) + -- Check positions for rpos, item in pairs(tbl or {}) do local pos2 = vector.add(pos, rpos) + pos2 = techage.rotate_around_axis(pos2, pos, turn) + local node = minetest.get_node(pos2) + if not techage.is_air_like(node.name) then + return false + end + end + -- Place nodes + local out = {} + for rpos, item in pairs(tbl or {}) do + local pos2 = vector.add(pos, rpos) + item.param2 = techage.rotate_param2(item, turn) + pos2 = techage.rotate_around_axis(pos2, pos, turn) local ndef = minetest.registered_nodes[item.name] if ndef and ndef.on_unpack then ndef.on_unpack(pos2, item.name, item.param2, item.data) else on_unpack_fallback(pos2, item.name, item.param2, item.data) end + -- Because of the rotated arrangement, generate a new rel-pos table + table.insert(out, vector.subtract(pos2, pos)) end + return out end + diff --git a/locale/techage.de.tr b/locale/techage.de.tr index b59c664..e84284a 100644 --- a/locale/techage.de.tr +++ b/locale/techage.de.tr @@ -1403,7 +1403,7 @@ TA5 Turbine=TA5 Turbine ### turncontroller.lua ### -Click on all blocks that shall be turned=Klicke auf all Blöcke, die gedreht werden sollen +Click on all blocks that shall be turned=Klicke auf alle Blöcke, die gedreht werden sollen TA4 Turn Controller=TA4 Dreh Controller Turn left=Drehe links Turn right=Drehe rechts diff --git a/move_controller/packcontainer.lua b/move_controller/packcontainer.lua index e471200..e707424 100644 --- a/move_controller/packcontainer.lua +++ b/move_controller/packcontainer.lua @@ -40,7 +40,7 @@ local function formspec(nvm, meta) "button[4.1,2.1;3.8,1;done;" .. S("Done") .. "]" .. "button[0.1,2.9;3.8,1;pack;" .. S("Pack") .. "]" .. "button[4.1,2.9;3.8,1;unpack;" .. S("Unpack") .. "]" .. - "label[0.3,9;" .. status .. "]" + "label[0.3,3.9;" .. status .. "]" end local function get_rposlist(pos, pos_list) @@ -53,21 +53,24 @@ local function get_rposlist(pos, pos_list) end local function set_storage_pos(pos, oldnode, oldmetadata, drops) - local meta = drops[1]:get_meta() - meta:set_string("storage_pos", P2S(pos)) - meta:set_string("node_name", (oldmetadata.node_name or "")) - meta:set_string("description", DESCRIPTION .. ' "' .. (oldmetadata.node_name or "") .. '"') + if oldmetadata.data_stored == "1" then + local meta = drops[1]:get_meta() + meta:set_string("storage_pos", P2S(pos)) + meta:set_string("node_name", oldmetadata.node_name or "") + meta:set_string("status", oldmetadata.status or "") + meta:set_int("data_stored", 1) + meta:set_string("description", DESCRIPTION .. ' "' .. (oldmetadata.node_name or "") .. '"') + end end local function get_storage_pos(pos, nvm, itemstack) - print("get_storage_pos") local imeta = itemstack:get_meta() if imeta then - print("get_storage_pos2") local meta = M(pos) meta:set_string("node_name", imeta:get_string("node_name")) + meta:set_string("status", imeta:get_string("status")) + meta:set_int("data_stored", imeta:get_int("data_stored")) nvm.storage_pos = S2P(imeta:get_string("storage_pos")) - print("get_storage_pos3", dump(nvm)) return nvm.storage_pos ~= nil end end @@ -81,12 +84,24 @@ local function copy_data_and_remove_node(mypos, rmtpos) techage.del_mem(rmtpos) end +local function determine_rotation(old_param2, new_param2) + local offs = new_param2 - old_param2 + print("determine_rotation", offs) + if offs == 0 then return "" + elseif offs == -1 then return "l" + elseif offs == 1 then return "r" + else return "2r" end +end + local function after_place_node(pos, placer, itemstack) local meta = M(pos) local nvm = techage.get_nvm(pos) meta:set_string("infotext", DESCRIPTION) + meta:set_string("owner", placer:get_player_name()) if get_storage_pos(pos, nvm, itemstack) then - if techage.get_node_lvm(nvm.storage_pos).name == "techage:ta5_packcontainer_storage" then + local node = techage.get_node_lvm(nvm.storage_pos) + if node.name == "techage:ta5_packcontainer_storage" then + nvm.turn = determine_rotation(node.param2, minetest.get_node(pos).param2) copy_data_and_remove_node(pos, nvm.storage_pos) nvm.storage_pos = nil end @@ -101,18 +116,19 @@ local function on_receive_fields(pos, formname, fields, player) local meta = M(pos) local nvm = techage.get_nvm(pos) + local data_stored = meta:get_int("data_stored") == 1 - if fields.record then - nvm.lrpos = {} + if fields.record and not data_stored then + nvm.lrpos = nil meta:set_string("status", S("Recording...")) local name = player:get_player_name() minetest.chat_send_player(name, S("Click on all blocks that shall be turned")) mark.start(name, MAX_BLOCKS) meta:set_string("formspec", formspec(nvm, meta)) - elseif fields.store then + elseif fields.store and not data_stored then meta:set_string("node_name", fields.node_name) meta:set_string("formspec", formspec(nvm, meta)) - elseif fields.done then + elseif fields.done and not data_stored then local name = player:get_player_name() local pos_list = mark.get_poslist(name) local text = #pos_list.." "..S("block positions are stored.") @@ -122,20 +138,23 @@ local function on_receive_fields(pos, formname, fields, player) mark.unmark_all(name) mark.stop(name) meta:set_string("formspec", formspec(nvm, meta)) - elseif fields.pack then + elseif fields.pack and nvm.lrpos and #nvm.lrpos > 0 and not data_stored then nvm.pack_tbl = techage.pack_nodes(pos, nvm.lrpos or {}) - meta:set_string("status", S("Packed")) + meta:set_string("status", S("Blocks stored")) meta:set_string("formspec", formspec(nvm, meta)) meta:set_int("data_stored", 1) - local name = player:get_player_name() - mark.stop(name) - elseif fields.unpack then - techage.unpack_nodes(pos, nvm.pack_tbl) - meta:set_string("status", S("Unpacked")) - meta:set_string("formspec", formspec(nvm, meta)) - meta:set_int("data_stored", 0) - local name = player:get_player_name() - mark.stop(name) + elseif fields.unpack and data_stored then + local tbl = techage.unpack_nodes(pos, nvm.pack_tbl, nvm.turn or "") + if tbl then + nvm.lrpos = tbl + meta:set_string("status", S("Blocks placed")) + meta:set_string("formspec", formspec(nvm, meta)) + meta:set_int("data_stored", 0) + nvm.turn = "" + else + meta:set_string("status", S("Position(s) occupied")) + meta:set_string("formspec", formspec(nvm, meta)) + end end end @@ -145,7 +164,9 @@ local function after_dig_node(pos, oldnode, oldmetadata, digger) mark.stop(name) if oldmetadata.fields.data_stored == "1" then - minetest.set_node(pos, {name = "techage:ta5_packcontainer_storage"}) + minetest.set_node(pos, {name = "techage:ta5_packcontainer_storage", param2 = oldnode.param2}) + local owner = oldmetadata.fields.owner or "" + M(pos):set_string("infotext", S("@1's @2 storage", owner, DESCRIPTION)) else techage.del_mem(pos) end @@ -155,9 +176,9 @@ minetest.register_node("techage:ta5_packcontainer", { description = DESCRIPTION, tiles = { -- up, down, right, left, back, front + "techage_filling_ta4.png^techage_frame_ta5_top.png^techage_appl_arrow.png", "techage_filling_ta4.png^techage_frame_ta5_top.png", - "techage_filling_ta4.png^techage_frame_ta5_top.png", - "techage_filling_ta4.png^techage_frame_ta5.png^techage_appl_turn.png", + "techage_filling_ta4.png^techage_frame_ta5.png^techage_appl_pack.png", }, after_place_node = after_place_node, on_receive_fields = on_receive_fields, @@ -195,20 +216,18 @@ minetest.register_node("techage:ta5_packcontainer_storage", { node_box = { type = "fixed", fixed = { - { -11/32, -1/2, -11/32, 11/32, -5/16, 11/32}, + { -5/16, -8/16, -5/16, 5/16, -5/16, 5/16}, }, }, tiles = { -- up, down, right, left, back, front - "signs_bot_sensor2.png^signs_bot_sensor_bot.png", - "signs_bot_sensor2.png", - "signs_bot_sensor2.png", - "signs_bot_sensor2.png", - "signs_bot_sensor2.png", - "signs_bot_sensor2.png", + "techage_pack_storage.png", }, + paramtype2 = "facedir", paramtype = "light", sunlight_propagates = true, + light_source = 5, + glow = 12, use_texture_alpha = techage.CLIP, is_ground_content = false, on_blast = function() end, diff --git a/textures/techage_appl_pack.png b/textures/techage_appl_pack.png new file mode 100644 index 0000000000000000000000000000000000000000..4d7bcd49998f72f0499d44809c60ad9bb6b8ec60 GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0L3?#3!&-4XSoB=)|uI>ds5fM@DE-t4;YB+#` zj3q&S!3+-1ZlnP@vpiiKLo80eoxG8k$&kl2cZtc$j6E#D5^4n#O?(b(Xj=MLZu2`) zsKvEHA@t9udXb;j4FA7g)5>LBTd+!>`B%(htpz>{!et#2H?4i8?4!5t7mx6+8!CVQ zFzKz^RmdPdTfHH^+W$aY)#(LWg4qtpGbXccVEAD+f!XE$O9qzW>6Wa{d>MXz4Z%fa rr=}co+vz38{_1qif0)+jEP)EX>4Tx04R}tkv&MmKpe$iQ?()$hjx(SkfAzR@C$L&DionYs1;guFuC*#nlvOS zE{=k0!NHHks)LKOt`4q(Aou~|=;Wm6A|?JWDYS_7;J6>}?mh0_0YbgZG^=Y2&~)2O zCE{WxyDA1=A)p5#j3Xj5%b1g-Bsz|-d-(Wz7vou-&;2?2)ttoupGZ8*4AUmwAfDc| z4bJ<-VOEq?;&b9rlP*a7$aTfzH_io@1)do;)2VslFtJ!@W2KE*(bR~ih@+~eQ@)V# zSmnIMSu0mr^Pc>L!JNLb%ypVWNMI35kRU=q6(y8mBSx!EiiH&I$2<5Vu3sXTLaq`R zITlcX2HEw4|H1EWt^DMKmlTWx-7k*wF$@HDfkw@7zKjJ_!ggl>VpHLthkK29HiG}y-9kKjV0^%c zT2%Z;3QDr$0NIeyI2etC(Kr~5gFz7oEVwHTMzS3}kX7brG9CD2O8sUF3#l4N1psPO VURhK2OfUcd002ovPDHLkV1iQ-3V8qk literal 0 HcmV?d00001 diff --git a/tools/screwdriver.lua b/tools/screwdriver.lua index 26f0929..5561725 100644 --- a/tools/screwdriver.lua +++ b/tools/screwdriver.lua @@ -69,7 +69,8 @@ local function turn_node_param2(pos, node, ndef, user) end local function turn_left(pos, node, ndef) - local param2 = techage.param2_turn_left(node.param2) + -- Turn face left means turn block right + local param2 = techage.param2_turn_right(node.param2) if ndef.ta_rotate_node then ndef.ta_rotate_node(pos, node, param2) else