techage/ta2_energy_storage/ta2_clutch.lua

129 lines
4.0 KiB
Lua
Raw Normal View History

2023-08-26 18:55:12 +03:00
--[[
TechAge
=======
Copyright (C) 2019-2023 Joachim Stolberg
AGPL v3
See LICENSE.txt for more information
TA2 Axle clutch
]]--
-- for lazy programmers
local P2S = minetest.pos_to_string
local M = minetest.get_meta
local S = techage.S
local DESCR = S("TA2 Clutch")
local Axle = techage.Axle
2023-08-27 21:18:55 +03:00
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
2023-08-26 18:55:12 +03:00
2023-08-26 22:26:22 +03:00
local function switch_on(pos, node)
if node.name == "techage:ta2_clutch_off" then
2023-08-27 21:18:55 +03:00
control_cmnd(pos, "on")
2023-08-26 22:26:22 +03:00
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})
2023-08-26 18:55:12 +03:00
end
end
2023-08-26 22:26:22 +03:00
local function switch_off(pos, node)
if node.name == "techage:ta2_clutch_on" then
2023-08-27 21:18:55 +03:00
control_cmnd(pos, "off")
minetest.swap_node(pos, {name = "techage:ta2_clutch_off", param2 = M(pos):get_int("outdir") - 1})
2023-08-26 22:26:22 +03:00
Axle:after_dig_tube(pos, node)
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,
max_hear_distance = 5})
2023-08-26 18:55:12 +03:00
end
end
minetest.register_node("techage:ta2_clutch_off", {
description = DESCR,
tiles = {
2023-08-27 21:18:55 +03:00
-- 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",
2023-08-26 18:55:12 +03:00
"techage_filling_ta2.png^techage_appl_clutch.png^techage_frame_ta2.png",
2023-08-27 21:18:55 +03:00
"techage_filling_ta2.png^techage_appl_clutch.png^techage_frame_ta2.png^[transformR180",
2023-08-26 22:26:22 +03:00
"techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png",
2023-08-26 18:55:12 +03:00
},
2023-08-26 22:26:22 +03:00
after_place_node = function(pos, placer, itemstack, pointed_thing)
2023-08-27 21:18:55 +03:00
M(pos):set_int("outdir", networks.side_to_outdir(pos, "B"))
2023-08-26 22:26:22 +03:00
end,
on_rightclick = switch_on,
2023-08-26 18:55:12 +03:00
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_node("techage:ta2_clutch_on", {
description = DESCR,
tiles = {
2023-08-27 21:18:55 +03:00
-- up, down, right, left, back, front
2023-08-26 22:26:22 +03:00
"techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png^[transformR90",
2023-08-27 21:18:55 +03:00
"techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png^[transformR270",
2023-08-26 18:55:12 +03:00
"techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png",
2023-08-27 21:18:55 +03:00
"techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png^[transformR180",
2023-08-26 22:26:22 +03:00
"techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_clutch_clutch.png",
2023-08-26 18:55:12 +03:00
},
2023-08-26 22:26:22 +03:00
after_dig_node = function(pos, oldnode, oldmetadata, digger)
Axle:after_dig_tube(pos, oldnode, oldmetadata)
end,
on_rightclick = switch_off,
2023-08-26 18:55:12 +03:00
paramtype2 = "facedir",
2023-08-26 22:26:22 +03:00
drop = "techage:ta2_clutch_off",
groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1},
2023-08-26 18:55:12 +03:00
on_rotate = screwdriver.disallow,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_craft({
output = "techage:ta2_clutch_off",
recipe = {
{"default:junglewood", "techage:axle", "default:wood"},
{"techage:axle", "basic_materials:gear_steel", "techage:axle"},
{"default:wood", "techage:axle", "default:junglewood"},
},
})