Skip to content

Commit ea262b3

Browse files
committed
Remove soft dependency on 'technic'
This avoids dependency chains as reported in issue N° 125.
1 parent 2cc3dfa commit ea262b3

5 files changed

Lines changed: 29 additions & 12 deletions

File tree

mod.conf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ title = Digtron
33
author = FaceDeer
44
description = Adds components for building modular tunnel boring machines.
55
depends = default, fakelib
6-
optional_depends = pipeworks, doc, hopper, awards, catacomb, intllib, technic
6+
optional_depends = pipeworks, doc, hopper, awards, catacomb, intllib
7+
# ^ Note: 'technic' is omitted to break dependency chains.
78
license = MIT, LGPL 2.1 or later
89
forum = https://forum.luanti.org/viewtopic.php?t=16295
910
version = 0.8

nodes/node_battery_holder.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
local S = digtron.S
33
-- local MP = minetest.get_modpath(minetest.get_current_modname())
44
-- local S = dofile(MP.."/intllib.lua")
5-
5+
local have_technic_mod = core.get_modpath("technic")
66

77
-- Battery storage. Controller node draws electrical power from here.
88
-- Note that batttery boxes are digtron group 7.
@@ -24,7 +24,7 @@ local battery_holder_formspec = function()
2424
end
2525

2626
local holder_groups = {cracky = 3, oddly_breakable_by_hand = 3, digtron = 7, tubedevice = 1, tubedevice_receiver = 1}
27-
if not minetest.get_modpath("technic") then
27+
if not have_technic_mod then
2828
-- if technic isn't installed there's no point in offering battery holders.
2929
-- leave them registered, though, in case technic is being removed from an existing server.
3030
holder_groups.not_in_creative_inventory = 1
@@ -66,8 +66,12 @@ local def = {
6666

6767
-- Allow all items with energy storage to be placed in the inventory
6868
allow_metadata_inventory_put = function(pos, listname, _, stack, player)
69+
if not have_technic_mod then
70+
return 0
71+
end
72+
6973
if listname == "batteries" then
70-
if minetest.global_exists("technic") and technic.get_charge(stack) > 0 then
74+
if technic.get_charge(stack) > 0 then
7175
if digtron.check_protected_and_record(pos, player) then
7276
return 0
7377
end
@@ -99,8 +103,12 @@ local def = {
99103
return inv:add_item("batteries", stack)
100104
end,
101105
can_insert = function(pos, _, stack)
106+
if not have_technic_mod then
107+
return false
108+
end
109+
102110
-- Disregard empty batteries, the player should know better
103-
if minetest.global_exists("technic") and technic.get_charge(stack) > 0 then
111+
if technic.get_charge(stack) > 0 then
104112
local meta = minetest.get_meta(pos)
105113
local inv = meta:get_inventory()
106114
return inv:room_for_item("batteries", stack)

nodes/node_power_connector.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
local S = digtron.S
33
-- local MP = minetest.get_modpath(minetest.get_current_modname())
44
-- local S = dofile(MP.."/intllib.lua")
5+
local have_technic_mod = core.get_modpath("technic")
56

67
local size = 3/16
78

@@ -19,7 +20,7 @@ local get_formspec_string = function(current_val, current_max)
1920
end
2021

2122
local connector_groups = {cracky = 3, oddly_breakable_by_hand=3, digtron = 8, technic_machine=1, technic_hv=1}
22-
if not minetest.get_modpath("technic") then
23+
if not have_technic_mod then
2324
-- Technic is not installed, hide this away.
2425
connector_groups.not_in_creative_inventory = 1
2526
end
@@ -100,6 +101,10 @@ minetest.register_node("digtron:power_connector", {
100101
end,
101102
})
102103

103-
if minetest.get_modpath("technic") then
104-
technic.register_machine("HV", "digtron:power_connector", technic.receiver)
105-
end
104+
-- To avoid dependency chains, delay the machine registration. But allow post-processing
105+
-- by other mods by running this callback at the first chance.
106+
table.insert(core.registered_on_mods_loaded, 1, function()
107+
if have_technic_mod then
108+
technic.register_machine("HV", "digtron:power_connector", technic.receiver)
109+
end
110+
end)

nodes/recipes.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
local S = digtron.S
33
-- local MP = minetest.get_modpath(minetest.get_current_modname())
44
-- local S = dofile(MP.."/intllib.lua")
5+
local have_technic_mod = core.get_modpath("technic")
56

67
minetest.register_craftitem("digtron:digtron_core", {
78
description = S("Digtron Core"),
@@ -46,7 +47,7 @@ minetest.register_craft({
4647
}
4748
})
4849

49-
if minetest.get_modpath("technic") then
50+
if have_technic_mod then
5051
minetest.register_craft({
5152
output = "digtron:master_builder",
5253
recipe = {
@@ -111,7 +112,7 @@ minetest.register_craft({
111112
}
112113
})
113114

114-
if minetest.get_modpath("technic") then
115+
if have_technic_mod then
115116
-- no need for this recipe if technic is not installed, avoid cluttering crafting guides
116117
minetest.register_craft({
117118
output = "digtron:battery_holder",

util.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ dofile( minetest.get_modpath( "digtron" ) .. "/util_execute_cycle.lua" ) -- sepa
55

66
local node_inventory_table = {type="node"} -- a reusable parameter for get_inventory calls, set the pos parameter before using.
77

8+
local have_technic_mod = core.get_modpath("technic")
9+
810
-- Apparently node_sound_metal_defaults is a newer thing, I ran into games using an older version of the default mod without it.
911
if default.node_sound_metal_defaults ~= nil then
1012
digtron.metal_sounds = default.node_sound_metal_defaults()
@@ -279,7 +281,7 @@ digtron.tap_batteries = function(battery_positions, target, test)
279281
end
280282

281283
for _, itemstack in pairs(invlist) do
282-
if minetest.global_exists("technic") then
284+
if have_technic_mod then
283285
local power_available = math.floor(technic.get_charge(itemstack) / digtron.config.power_ratio)
284286
if power_available ~= 0 then
285287
local actual_burned = power_available -- we just take all we have from the battery, since they aren't stackable

0 commit comments

Comments
 (0)