Add TA2 clutch

This commit is contained in:
Joachim Stolberg 2023-08-26 21:26:22 +02:00
parent ae8d2d3d09
commit 92039b3a83
3 changed files with 56 additions and 129 deletions

View File

@ -24,14 +24,21 @@ local Axle = tubelib2.Tube:new({
max_tube_length = 10, max_tube_length = 10,
show_infotext = false, show_infotext = false,
tube_type = "axle", 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 = {}, secondary_node_names = {},
after_place_tube = function(pos, param2, tube_type, num_tubes, state) after_place_tube = function(pos, param2, tube_type, num_tubes, state)
if state == "on" then 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}) minetest.swap_node(pos, {name = "techage:axle_on", param2 = param2})
else else
minetest.swap_node(pos, {name = "techage:axle", param2 = param2}) minetest.swap_node(pos, {name = "techage:axle", param2 = param2})
end end
else
minetest.swap_node(pos, {name = name, param2 = param2})
end
end, end,
}) })

View File

@ -17,117 +17,57 @@ local P2S = minetest.pos_to_string
local M = minetest.get_meta local M = minetest.get_meta
local S = techage.S local S = techage.S
local CYCLE_TIME = 2
local PWR_PERF = 100
local DESCR = S("TA2 Clutch") local DESCR = S("TA2 Clutch")
local Axle = techage.Axle local Axle = techage.Axle
local power = networks.power
-- Axles texture animation local function switch_on(pos, node)
local function switch_axles(pos, on) if node.name == "techage:ta2_clutch_off" then
local outdir = M(pos):get_int("outdir") node.name = "techage:ta2_clutch_on"
Axle:switch_tube_line(pos, outdir, on and "on" or "off") minetest.swap_node(pos, node)
end Axle:after_place_tube(pos)
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)
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", { minetest.sound_play("techage_button", {
pos = pos, pos = pos,
gain = 0.5, gain = 0.5,
max_hear_distance = 5}) max_hear_distance = 5})
end 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 end
local function after_dig_node(pos, oldnode, oldmetadata, digger) local function switch_off(pos, node)
local outdir = tonumber(oldmetadata.fields.outdir or 0) if node.name == "techage:ta2_clutch_on" then
Axle:after_dig_node(pos, {outdir, networks.Flip[outdir]}) node.name = "techage:ta2_clutch_off"
techage.del_mem(pos) minetest.swap_node(pos, node)
end Axle:after_dig_tube(pos, node)
minetest.sound_play("techage_button", {
local function get_generator_data(pos, outdir, tlib2) pos = pos,
local nvm = techage.get_nvm(pos) gain = 0.5,
if techage.is_running(nvm) then max_hear_distance = 5})
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
end end
end end
minetest.register_node("techage:ta2_clutch_off", { minetest.register_node("techage:ta2_clutch_off", {
description = DESCR, description = DESCR,
tiles = { tiles = {
-- up, down, right, left, back, front -- back, front, up, down, right, left
"techage_filling_ta2.png^techage_frame_ta2_top.png", "techage_filling_ta2.png^techage_appl_clutch.png^techage_frame_ta2.png^[transformR90",
"techage_filling_ta2.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_appl_clutch.png^techage_frame_ta2.png^[transformR90",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_axle_gearbox.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_axle_gearbox.png",
"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_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, after_place_node = function(pos, placer, itemstack, pointed_thing)
on_rightclick = on_rightclick, if not Axle:after_place_tube(pos, placer, pointed_thing) then
after_place_node = after_place_node, minetest.remove_node(pos)
after_dig_node = after_dig_node, return true
get_generator_data = get_generator_data, 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", paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2}, groups = {cracky=2, crumbly=2, choppy=2},
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
@ -138,47 +78,27 @@ minetest.register_node("techage:ta2_clutch_off", {
minetest.register_node("techage:ta2_clutch_on", { minetest.register_node("techage:ta2_clutch_on", {
description = DESCR, description = DESCR,
tiles = { tiles = {
-- up, down, right, left, back, front -- back, front, up, down, right, left
"techage_filling_ta2.png^techage_frame_ta2_top.png", "techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png^[transformR90",
"techage_filling_ta2.png^techage_frame_ta2.png", "techage_filling_ta2.png^techage_appl_clutch_on.png^techage_frame_ta2.png^[transformR90",
{
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,
},
},
"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", "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, after_dig_node = function(pos, oldnode, oldmetadata, digger)
on_rightclick = on_rightclick, Axle:after_dig_tube(pos, oldnode, oldmetadata)
get_generator_data = get_generator_data, end,
on_rightclick = switch_off,
paramtype2 = "facedir", paramtype2 = "facedir",
drop = "", drop = "techage:ta2_clutch_off",
groups = {not_in_creative_inventory=1}, groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1},
diggable = false,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
power.register_nodes({"techage:ta2_clutch_off", "techage:ta2_clutch_on"}, Axle, "gen", {"R", "L"})
minetest.register_craft({ minetest.register_craft({
output = "techage:ta2_clutch_off", output = "techage:ta2_clutch_off",
recipe = { recipe = {

Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B