mods that hopefully work for a TechAge-based pack

This commit is contained in:
tangent committed 2026-09-09 06:27:51 -06:00
1 parent 4e6b08d194
commit c27db2a537
6234 files changed
+375578

No files matched your search

@@ -0,0 +1,128 @@
--[[
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
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)
minetest.sound_play("techage_button", {
pos = pos,
gain = 0.5,
max_hear_distance = 5})
end
end
local function switch_off(pos, node)
if node.name == "techage:ta2_clutch_on" then
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,
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_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)
M(pos):set_int("outdir", networks.side_to_outdir(pos, "B"))
end,
on_rightclick = switch_on,
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 = {
-- 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^[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_dig_node = function(pos, oldnode, oldmetadata, digger)
Axle:after_dig_tube(pos, oldnode, oldmetadata)
end,
on_rightclick = switch_off,
paramtype2 = "facedir",
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(),
})
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"},
},
})
@@ -0,0 +1,85 @@
--[[
TechAge
=======
Copyright (C) 2019-2021 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Rope for TA2 gravity-based energy storage
]]--
local Entities = {}
-- Return first pos after start pos and the destination pos
local function get_positions(pos, length, force)
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} -- start pos
local pos2 = {x = pos.x, y = pos.y - 1 - length, z = pos.z} -- end pos
if force then
return pos1, pos2 -- force given length
end
local _, pos3 = minetest.line_of_sight(pos1, pos2)
return pos1, pos3 or pos2 -- new values
end
local function del_rope(pos)
local key = minetest.hash_node_position(pos)
local rope = Entities[key]
if rope then
rope:remove()
Entities[key] = nil
end
return key
end
local function add_rope(pos, pos1, pos2)
local key = del_rope(pos)
pos1.y = pos1.y + 0.5 -- from
pos2.y = pos2.y - 0.5 -- to
local pos3 = {x = pos1.x, y = (pos1.y + pos2.y) / 2, z = pos1.z} -- mid-pos
local length = math.abs(pos1.y - pos2.y)
local rope = minetest.add_entity(pos3, "techage:ta2_rope")
if rope then
rope:set_properties({visual_size = {x = 0.06, y = length}, collisionbox = {x = 0.06, y = length}})
end
Entities[key] = rope
end
minetest.register_entity("techage:ta2_rope", {
initial_properties = {
visual = "cube",
textures = {
"techage_rope.png",
"techage_rope.png",
"techage_rope.png",
"techage_rope.png",
"techage_rope.png",
"techage_rope.png",
},
use_texture_alpha = false,
physical = true,
collide_with_objects = true,
pointable = true,
static_save = false,
visual_size = {x = 0.06, y = 10, z = 0.06},
shaded = true,
},
})
-------------------------------------------------------------------------------
-- API functions
-------------------------------------------------------------------------------
function techage.renew_rope(pos, length, force)
local pos1, pos2 = get_positions(pos, length, force)
if pos1 then
add_rope(pos, pos1, pos2)
return pos1, pos2
end
end
techage.del_rope = del_rope
@@ -0,0 +1,137 @@
--[[
TechAge
=======
Copyright (C) 2019-2021 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Chest for TA2 gravity-based energy storage
]]--
-- for lazy programmers
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local S2P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local function valid_weight_items(stack)
local name = stack:get_name()
local ndef = minetest.registered_nodes[name]
if ndef then
if minetest.get_item_group(name, "stone") > 0 then
return true
end
if minetest.get_item_group(name, "cobble") > 0 then
return true
end
if minetest.get_item_group(name, "gravel") > 0 then
return true
end
if minetest.get_item_group(name, "sand") > 0 then
return true
end
end
end
minetest.register_entity("techage:ta2_weight_chest_entity", {
initial_properties = {
physical = true,
pointable = false,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
visual = "wielditem",
textures = {"techage:ta2_weight_chest"},
visual_size = {x=0.66, y=0.66, z=0.66},
static_save = false,
},
})
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if not valid_weight_items(stack) then
return 0
end
return stack:get_count()
end
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end
local function can_dig(pos, player)
if minetest.is_protected(pos, player:get_player_name()) then
return false
end
local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("main")
end
local function after_dig_node(pos, oldnode, oldmetadata, digger)
techage.remove_node(pos, oldnode, oldmetadata)
end
local function formspec()
return "size[8,6.7]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;main;1.5,0.2;5,2;]"..
"list[current_player;main;0,3;8,4;]"..
"listring[context;main]"..
"listring[current_player;main]"
end
minetest.register_node("techage:ta2_weight_chest", {
description = S("TA2 Weight Chest"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta2.png^techage_frame_ta2.png^techage_weight_bottom.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_weight_bottom.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png",
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size('main', 10)
end,
after_place_node = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", formspec())
end,
techage_set_numbers = function(pos, numbers, player_name)
return techage.logic.set_numbers(pos, numbers, player_name, S("TA2 Weight Chest"))
end,
can_dig = can_dig,
after_dig_node = after_dig_node,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_craft({
output = "techage:ta2_weight_chest",
recipe = {
{"", "", ""},
{"basic_materials:steel_strip", "techage:chest_ta2", "basic_materials:steel_strip"},
{"", "", ""},
},
})
@@ -0,0 +1,225 @@
--[[
TechAge
=======
Copyright (C) 2019-2021 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Winch for TA2 gravity-based energy storage
]]--
-- for lazy programmers
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local S2P = minetest.string_to_pos
local M = minetest.get_meta
local S = techage.S
local MIN_LOAD = 99 -- 1 stack
local MAX_ROPE_LEN = 10
local CYCLE_TIME = 2
local Axle = techage.Axle
local power = networks.power
local control = networks.control
local function chest_pos(pos)
local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} -- start pos
local pos2 = {x = pos.x, y = pos.y - 1 - MAX_ROPE_LEN, z = pos.z} -- end pos
local _, pos3 = minetest.line_of_sight(pos1, pos2)
return pos3 or pos2
end
local function chest_load(nvm, pos)
local amount = 0
local inv = minetest.get_inventory({type = "node", pos = pos})
nvm.stored_items = {}
for i = 1, inv:get_size("main") do
local stack = inv:get_stack("main", i)
nvm.stored_items[i] = {name = stack:get_name(), count = stack:get_count()}
amount = amount + stack:get_count()
end
return amount * 3
end
local function chest_full(pos)
local nvm = techage.get_nvm(pos)
local pos1 = chest_pos(pos)
local node = minetest.get_node(pos1)
if node.name == "techage:ta2_weight_chest" then
return chest_load(nvm, pos1) >= MIN_LOAD
end
end
local function add_chest_entity(pos, nvm)
local mem = techage.get_mem(pos)
local length
if not nvm.capa or nvm.capa == 0 then
length = (nvm.length or MAX_ROPE_LEN) * (1 - (nvm.load or 0))
else
length = (nvm.length or MAX_ROPE_LEN) * (1 - (nvm.load or 0) / nvm.capa)
end
local y = pos.y - length - 1
techage.renew_rope(pos, length, true)
if mem.obj then
mem.obj:remove()
end
mem.obj = minetest.add_entity({x = pos.x, y = y, z = pos.z}, "techage:ta2_weight_chest_entity")
end
-- Add chest node, remove chest entity instead
local function add_chest(pos)
local mem = techage.get_mem(pos)
local nvm = techage.get_nvm(pos)
if mem.obj then
mem.obj:remove()
mem.obj = nil
end
if nvm.capa and nvm.capa >= MIN_LOAD then
local pos1 = {x = pos.x, y = pos.y - (nvm.length or 1) - 1, z = pos.z}
minetest.add_node(pos1, {name = "techage:ta2_weight_chest", param2 = 0})
local ndef = minetest.registered_nodes["techage:ta2_weight_chest"]
ndef.on_construct(pos1)
ndef.after_place_node(pos1)
local inv = minetest.get_inventory({type = "node", pos = pos1})
for i, item in ipairs(nvm.stored_items or {}) do
inv:set_stack("main", i, item)
end
end
nvm.capa = 0
end
-- Remove chest node, add rope and chest entity instead
local function remove_chest(pos)
local mem = techage.get_mem(pos)
local nvm = techage.get_nvm(pos)
local pos1 = chest_pos(pos)
local mass = chest_load(nvm, pos1)
if mass > 0 then
nvm.length = pos.y - pos1.y - 1
nvm.capa = mass * nvm.length / MAX_ROPE_LEN
minetest.remove_node(pos1)
mem.obj = minetest.add_entity(pos1, "techage:ta2_weight_chest_entity")
techage.renew_rope(pos, nvm.length)
return true
end
end
minetest.register_node("techage:ta2_winch", {
description = S("TA2 Winch"),
tiles = {
-- up, down, right, left, back, front
"techage_filling_ta2.png^techage_appl_arrow2.png^techage_frame_ta2.png^[transformR270",
"techage_filling_ta2.png^techage_appl_arrow2.png^techage_frame_ta2.png^techage_appl_winch_hole.png^[transformR270",
"techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_appl_winch.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_appl_winch.png^techage_frame_ta2.png",
"techage_filling_ta2.png^techage_appl_winch.png^techage_frame_ta2.png",
},
after_place_node = function(pos, placer)
local nvm = techage.get_nvm(pos)
local outdir = networks.side_to_outdir(pos, "R")
M(pos):set_int("outdir", outdir)
Axle:after_place_node(pos, {outdir})
minetest.get_node_timer(pos):start(CYCLE_TIME)
techage.renew_rope(pos, MAX_ROPE_LEN - 1)
end,
on_timer = function(pos, elapsed)
local nvm = techage.get_nvm(pos)
local outdir = M(pos):get_int("outdir")
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
power.start_storage_calc(pos, Axle, outdir)
elseif nvm.running and nvm.load < 2 and not power.power_available(pos, Axle, outdir) then
add_chest(pos)
nvm.running = false
power.start_storage_calc(pos, Axle, outdir)
end
if nvm.running then
nvm.load = power.get_storage_load(pos, Axle, outdir, nvm.capa) or 0
if nvm.load > 2 then
add_chest_entity(pos, nvm)
end
else
techage.renew_rope(pos, 50)
end
return true
end,
after_dig_node = function(pos, oldnode, oldmetadata)
add_chest(pos)
techage.del_rope(pos)
local outdir = tonumber(oldmetadata.fields.outdir or 0)
power.start_storage_calc(pos, Axle, outdir)
Axle:after_dig_node(pos, {outdir})
techage.del_mem(pos)
end,
get_storage_data = function(pos, outdir, tlib2)
local nvm = techage.get_nvm(pos)
nvm.capa = nvm.capa or 1
if nvm.running and not nvm.blocked then
return {level = (nvm.load or 0) / nvm.capa, capa = nvm.capa}
end
end,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
power.register_nodes({"techage:ta2_winch"}, Axle, "sto", {"R"})
techage.register_node({"techage:ta2_winch"}, {
on_node_load = function(pos, node)
minetest.get_node_timer(pos):start(CYCLE_TIME)
local nvm = techage.get_nvm(pos)
if nvm.running then
add_chest_entity(pos, nvm)
end
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 = {
{"farming:string", "farming:string", "farming:string"},
{"farming:string", "techage:gearbox", "farming:string"},
{"farming:string", "farming:string", "farming:string"},
},
})