From 92039b3a8311412171601ece210736d509489567 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sat, 26 Aug 2023 21:26:22 +0200 Subject: [PATCH] Add TA2 clutch --- power/drive_axle.lua | 15 ++- ta2_energy_storage/ta2_clutch.lua | 170 ++++++++--------------------- textures/techage_clutch_clutch.png | Bin 0 -> 184 bytes 3 files changed, 56 insertions(+), 129 deletions(-) create mode 100644 textures/techage_clutch_clutch.png diff --git a/power/drive_axle.lua b/power/drive_axle.lua index 4f710e3..4b9b44b 100644 --- a/power/drive_axle.lua +++ b/power/drive_axle.lua @@ -24,13 +24,20 @@ local Axle = tubelib2.Tube:new({ max_tube_length = 10, show_infotext = false, tube_type = "axle", - primary_node_names = {"techage:axle", "techage:axle_on"}, + primary_node_names = {"techage:axle", "techage:axle_on", "techage:ta2_clutch_on"}, secondary_node_names = {}, after_place_tube = function(pos, param2, tube_type, num_tubes, state) - if state == "on" then - minetest.swap_node(pos, {name = "techage:axle_on", param2 = param2}) + local node = minetest.get_node(pos) + local name = node.name + print("after_place_tube", name) + if name == "techage:axle_on" or name == "techage:axle" then + if state == "on" then -- texture state + minetest.swap_node(pos, {name = "techage:axle_on", param2 = param2}) + else + minetest.swap_node(pos, {name = "techage:axle", param2 = param2}) + end else - minetest.swap_node(pos, {name = "techage:axle", param2 = param2}) + minetest.swap_node(pos, {name = name, param2 = param2}) end end, }) diff --git a/ta2_energy_storage/ta2_clutch.lua b/ta2_energy_storage/ta2_clutch.lua index 08f3123..e060e2f 100644 --- a/ta2_energy_storage/ta2_clutch.lua +++ b/ta2_energy_storage/ta2_clutch.lua @@ -17,117 +17,57 @@ local P2S = minetest.pos_to_string local M = minetest.get_meta local S = techage.S -local CYCLE_TIME = 2 -local PWR_PERF = 100 local DESCR = S("TA2 Clutch") local Axle = techage.Axle -local power = networks.power --- Axles texture animation -local function switch_axles(pos, on) - local outdir = M(pos):get_int("outdir") - Axle:switch_tube_line(pos, outdir, on and "on" or "off") -end - -local function start_node(pos, nvm, state) - local outdir = M(pos):get_int("outdir") - --switch_axles(pos, true) - nvm.load = 0 - power.start_storage_calc(pos, Axle, outdir) - outdir = networks.Flip[outdir] - power.start_storage_calc(pos, Axle, outdir) -end - -local function stop_node(pos, nvm, state) - local outdir = M(pos):get_int("outdir") - --switch_axles(pos, false) - power.start_storage_calc(pos, Axle, outdir) - outdir = networks.Flip[outdir] - power.start_storage_calc(pos, Axle, outdir) -end - -local State = techage.NodeStates:new({ - node_name_passive = "techage:ta2_clutch_off", - node_name_active = "techage:ta2_clutch_on", - infotext_name = DESCR, - cycle_time = CYCLE_TIME, - standby_ticks = 0, - start_node = start_node, - stop_node = stop_node, -}) - -local function node_timer(pos, elapsed) - local t = minetest.get_us_time() - local nvm = techage.get_nvm(pos) - local outdir2 = M(pos):get_int("outdir") - local outdir1 = networks.Flip[outdir2] - local data = power.transfer_duplex(pos, Axle, outdir1, Axle, outdir2, PWR_PERF) - local power_flow = (data.curr_load1 == 0 and data.curr_load2 == 0) or (data.curr_load1 > 0 and data.curr_load2 > 0) - if not power_flow then - power.start_storage_calc(pos, Axle, outdir1) - power.start_storage_calc(pos, Axle, outdir2) - switch_axles(pos, data.curr_load1 ~= 0) +local function switch_on(pos, node) + if node.name == "techage:ta2_clutch_off" then + node.name = "techage:ta2_clutch_on" + minetest.swap_node(pos, node) + Axle:after_place_tube(pos) + minetest.sound_play("techage_button", { + pos = pos, + gain = 0.5, + max_hear_distance = 5}) end - t = minetest.get_us_time() - t - print("node_timer", t, power_flow, dump(data)) - return true end -local function on_rightclick(pos, node, clicker) - local nvm = techage.get_nvm(pos) - if techage.is_running(nvm) then - State:stop(pos, nvm) - else - State:start(pos, nvm) - end - minetest.sound_play("techage_button", { - pos = pos, - gain = 0.5, - max_hear_distance = 5}) -end - -local function after_place_node(pos, placer, itemstack) - local meta = M(pos) - local nvm = techage.get_nvm(pos) - local own_num = techage.add_node(pos, "techage:ta2_clutch_off") - meta:set_string("owner", placer:get_player_name()) - local outdir = networks.side_to_outdir(pos, "R") - meta:set_int("outdir", outdir) - Axle:after_place_node(pos, {outdir, networks.Flip[outdir]}) - State:node_init(pos, nvm, own_num) -end - -local function after_dig_node(pos, oldnode, oldmetadata, digger) - local outdir = tonumber(oldmetadata.fields.outdir or 0) - Axle:after_dig_node(pos, {outdir, networks.Flip[outdir]}) - techage.del_mem(pos) -end - -local function get_generator_data(pos, outdir, tlib2) - local nvm = techage.get_nvm(pos) - if techage.is_running(nvm) then - return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2} +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) + Axle:after_dig_tube(pos, node) + minetest.sound_play("techage_button", { + pos = pos, + gain = 0.5, + max_hear_distance = 5}) end end minetest.register_node("techage:ta2_clutch_off", { description = DESCR, tiles = { - -- up, down, right, left, back, front - "techage_filling_ta2.png^techage_frame_ta2_top.png", - "techage_filling_ta2.png^techage_frame_ta2.png", - "techage_filling_ta2.png^techage_frame_ta2.png^techage_axle_gearbox.png", - "techage_filling_ta2.png^techage_frame_ta2.png^techage_axle_gearbox.png", + -- 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", "techage_filling_ta2.png^techage_appl_clutch.png^techage_frame_ta2.png", + "techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png", + "techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png", }, - on_timer = node_timer, - on_rightclick = on_rightclick, - after_place_node = after_place_node, - after_dig_node = after_dig_node, - get_generator_data = get_generator_data, + 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) + end, + on_rightclick = switch_on, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, @@ -138,47 +78,27 @@ minetest.register_node("techage:ta2_clutch_off", { minetest.register_node("techage:ta2_clutch_on", { description = DESCR, tiles = { - -- up, down, right, left, back, front - "techage_filling_ta2.png^techage_frame_ta2_top.png", - "techage_filling_ta2.png^techage_frame_ta2.png", - { - name = "techage_filling4_ta2.png^techage_axle_gearbox4.png^techage_frame4_ta2.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 0.6, - }, - }, - { - name = "techage_filling4_ta2.png^techage_axle_gearbox4.png^techage_frame4_ta2.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 0.6, - }, - }, + -- back, front, up, down, right, left + "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^[transformR90", "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_frame_ta2.png^techage_clutch_clutch.png", + "techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png", }, - on_timer = node_timer, - on_rightclick = on_rightclick, - get_generator_data = get_generator_data, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Axle:after_dig_tube(pos, oldnode, oldmetadata) + end, + on_rightclick = switch_off, paramtype2 = "facedir", - drop = "", - groups = {not_in_creative_inventory=1}, - diggable = false, + drop = "techage:ta2_clutch_off", + groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1}, on_rotate = screwdriver.disallow, is_ground_content = false, sounds = default.node_sound_wood_defaults(), }) -power.register_nodes({"techage:ta2_clutch_off", "techage:ta2_clutch_on"}, Axle, "gen", {"R", "L"}) - minetest.register_craft({ output = "techage:ta2_clutch_off", recipe = { diff --git a/textures/techage_clutch_clutch.png b/textures/techage_clutch_clutch.png new file mode 100644 index 0000000000000000000000000000000000000000..5b0d30b3f88c024ef3b25e8308b32e819387fa0c GIT binary patch literal 184 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfv(Ey(iSN8%RAQJ*MY+Mx@96V#@ zq}RFu^MFFkB|(0{40<7R%Om80Tz^j&#}JM4$q5o?8axGfL>@5p=xORXs5A(8n6WVl zt1zZdXpro3$k15Db@{@Dgp|e