From aee918d02530088378354785b220d42f96c3729f Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sun, 27 Aug 2023 20:18:55 +0200 Subject: [PATCH] Improve TA2 clutch --- ta2_energy_storage/ta2_clutch.lua | 55 +++++++++++++++++++--------- ta2_energy_storage/ta2_winch.lua | 25 ++++++++++++- textures/techage_appl_arrow3.png | Bin 0 -> 112 bytes textures/techage_appl_clutch.png | Bin 196 -> 201 bytes textures/techage_appl_clutch_on.png | Bin 201 -> 165 bytes 5 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 textures/techage_appl_arrow3.png diff --git a/ta2_energy_storage/ta2_clutch.lua b/ta2_energy_storage/ta2_clutch.lua index e060e2f..4438135 100644 --- a/ta2_energy_storage/ta2_clutch.lua +++ b/ta2_energy_storage/ta2_clutch.lua @@ -20,9 +20,36 @@ local S = techage.S local DESCR = S("TA2 Clutch") local Axle = techage.Axle +local power = networks.power +local control = networks.control + +-- Search for a gearbox, which is part of the axle network +local function get_gearbox_pos(pos) + local outdir = M(pos):get_int("outdir") + local pos1, dir1 = Axle:get_connected_node_pos(pos, outdir) + if pos1 then + local node = minetest.get_node(pos1) + --print("get_gearbox_pos", node.name) + if node.name == "techage:gearbox_on" or node.name == "techage:gearbox" then + return pos1 + end + end +end + +-- Send to the winches +local function control_cmnd(pos, topic) + -- The clutch is not part of the axle network, + -- so we have to use a helper function to be able + -- to send a command into the network. + local pos1 = get_gearbox_pos(pos) + if pos1 then + control.send(pos1, Axle, 0, "sto", topic) + end +end local function switch_on(pos, node) if node.name == "techage:ta2_clutch_off" then + control_cmnd(pos, "on") node.name = "techage:ta2_clutch_on" minetest.swap_node(pos, node) Axle:after_place_tube(pos) @@ -35,8 +62,8 @@ end local function switch_off(pos, node) if node.name == "techage:ta2_clutch_on" then - node.name = "techage:ta2_clutch_off" - minetest.swap_node(pos, node) + control_cmnd(pos, "off") + minetest.swap_node(pos, {name = "techage:ta2_clutch_off", param2 = M(pos):get_int("outdir") - 1}) Axle:after_dig_tube(pos, node) minetest.sound_play("techage_button", { pos = pos, @@ -48,24 +75,16 @@ end minetest.register_node("techage:ta2_clutch_off", { description = DESCR, tiles = { - -- back, front, up, down, right, left - "techage_filling_ta2.png^techage_appl_clutch.png^techage_frame_ta2.png^[transformR90", - "techage_filling_ta2.png^techage_appl_clutch.png^techage_frame_ta2.png^[transformR90", - "techage_filling_ta2.png^techage_appl_clutch.png^techage_frame_ta2.png", + -- up, down, right, left, back, front + "techage_filling_ta2.png^techage_appl_clutch.png^techage_appl_arrow3.png^techage_frame_ta2.png^[transformR90", + "techage_filling_ta2.png^techage_appl_clutch.png^techage_appl_arrow3.png^techage_frame_ta2.png^[transformR270", "techage_filling_ta2.png^techage_appl_clutch.png^techage_frame_ta2.png", + "techage_filling_ta2.png^techage_appl_clutch.png^techage_frame_ta2.png^[transformR180", "techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png", "techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png", }, - after_place_node = function(pos, placer, itemstack, pointed_thing) - if not Axle:after_place_tube(pos, placer, pointed_thing) then - minetest.remove_node(pos) - return true - end - return false - end, - after_dig_node = function(pos, oldnode, oldmetadata, digger) - Axle:after_dig_tube(pos, oldnode, oldmetadata) + M(pos):set_int("outdir", networks.side_to_outdir(pos, "B")) end, on_rightclick = switch_on, paramtype2 = "facedir", @@ -78,11 +97,11 @@ minetest.register_node("techage:ta2_clutch_off", { minetest.register_node("techage:ta2_clutch_on", { description = DESCR, tiles = { - -- back, front, up, down, right, left - "techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png^[transformR90", + -- up, down, right, left, back, front "techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png^[transformR90", + "techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png^[transformR270", "techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png", - "techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png", + "techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png^[transformR180", "techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png", "techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png", }, diff --git a/ta2_energy_storage/ta2_winch.lua b/ta2_energy_storage/ta2_winch.lua index 42b5e56..b9fd848 100644 --- a/ta2_energy_storage/ta2_winch.lua +++ b/ta2_energy_storage/ta2_winch.lua @@ -24,6 +24,7 @@ local CYCLE_TIME = 2 local Axle = techage.Axle local power = networks.power +local control = networks.control local function chest_pos(pos) @@ -136,6 +137,11 @@ minetest.register_node("techage:ta2_winch", { nvm.capa = nvm.capa or 1 nvm.load = nvm.load or 0 + if nvm.blocked then + -- Keep the network active + power.get_storage_load(pos, Axle, outdir, nvm.capa) + return true + end if not nvm.running and power.power_available(pos, Axle, outdir) and chest_full(pos) then remove_chest(pos) nvm.running = true @@ -169,7 +175,7 @@ minetest.register_node("techage:ta2_winch", { get_storage_data = function(pos, outdir, tlib2) local nvm = techage.get_nvm(pos) nvm.capa = nvm.capa or 1 - if nvm.running then + if nvm.running and not nvm.blocked then return {level = (nvm.load or 0) / nvm.capa, capa = nvm.capa} end end, @@ -192,6 +198,23 @@ techage.register_node({"techage:ta2_winch"}, { end, }) +control.register_nodes({"techage:ta2_winch"}, { + on_receive = function(pos, tlib2, topic, payload) + --print("on_receive", topic) + local nvm = techage.get_nvm(pos) + if topic == "on" then + nvm.blocked = false + local outdir = M(pos):get_int("outdir") + power.start_storage_calc(pos, Axle, outdir) + elseif topic == "off" then + nvm.blocked = true + local outdir = M(pos):get_int("outdir") + power.start_storage_calc(pos, Axle, outdir) + end + end, + } +) + minetest.register_craft({ output = "techage:ta2_winch", recipe = { diff --git a/textures/techage_appl_arrow3.png b/textures/techage_appl_arrow3.png new file mode 100644 index 0000000000000000000000000000000000000000..e34eaf617d3fe3e47899b33960b6ea5c638eeba6 GIT binary patch literal 112 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnL3?x0byx0z;*aCb)T-^(N?#RlvU-mcv6k#k0 z@(X5gcy=QV$dT}LaSY+Oo}93NsenO{Q(+N@u)qYEjg1+M4Uhy_Lqi!t15i{j7^A2l zEWo6s#Gs^rPXNtYB_(B$fRU0Ck^s<9yaFIIK>#Ws0JH@tKqiW{SOp0CmXH~!fs7Fi b6vr(9CA=*4i+|OR00000NkvXXu0mjfHMBcZ delta 168 zcmX@fc!Y6+O1)@+Pl)UNyLa6SeDw76Hf&w*RhOO(>)YRhQ;$AGs`^&(_!@p z%JG4F0gI8FNdOPSK}ON#qS4b0fQB)6y85}Sb7D$p0sw-WD3JgF delta 173 zcmZ3=c#?5~O1*S|Pl&5~fzSQBcY(;jz+l7H^*%m63=9lvYHD$Dao^fG<$)aLk|4ie z26e;2+_FX>H_Fq+F+}5ha>4?x0!O9d=C7(;aPGBZyqFmB$mMdT4{kYiihL6#F6rr9v6eJoPYIHJzLlj7>4knF;Il!2in X->RtP+t~*|YZyFT{an^LB{Ts5OyoFZ