Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and cleanup dependencies #224

Merged
merged 4 commits into from
Nov 1, 2021
Merged

Fix and cleanup dependencies #224

merged 4 commits into from
Nov 1, 2021

Conversation

OgelGames
Copy link
Contributor

@OgelGames OgelGames commented Oct 23, 2021

  • Remove depends.txt files
  • Fix Problems with dependencies #163
  • Reduce optional dependencies of technic_worldgen using minetest.register_on_mods_loaded()
  • Make CNC depend on technic (currently optional, which doesn't make sense)
  • Fix CNC material dependencies.

Not including #214 in this PR because that will be a much bigger change, as opposed these small changes and fixes.

@OgelGames OgelGames added WIP Work in progress Cleanup Cleanup of bad code or other redundant/unnecessary stuff Bug fix labels Oct 23, 2021
@S-S-X
Copy link
Member

S-S-X commented Oct 23, 2021

  • Make CNC depend on technic (currently optional, which doesn't make sense)

CNC does not require technic and it has been used on some servers without technic.

@OgelGames
Copy link
Contributor Author

OgelGames commented Oct 23, 2021

Ah, I didn't realize that it was functional without technic.

Still has one thing to fix though, when technic_worldgen doesn't exist:

ERROR[Main]: generateImage(): Could not load image "technic_zinc_block.png" while building texture; Creating a dummy image
ERROR[Main]: generateImage(): Could not load image "technic_zinc_block.png" while building texture; Creating a dummy image
ERROR[Main]: generateImage(): Could not load image "technic_cast_iron_block.png" while building texture; Creating a dummy image
ERROR[Main]: generateImage(): Could not load image "technic_cast_iron_block.png" while building texture; Creating a dummy image

@S-S-X
Copy link
Member

S-S-X commented Oct 23, 2021

I think it would make sense to divide materials.lua into multiple files possibly moving files to materials/default.lua, materials/technic.lua, materials/ethereal.lua and materials/moreblocks.lua.
That also allows having default materials separated which probably helps with #214

There's even minetest.get_modpath("technic") but some materials are registered outside of that block...

@S-S-X
Copy link
Member

S-S-X commented Oct 23, 2021

It also seems like it would be easy to make also dependency to default for wrench to be optional.
That would be another thing which would also help with #214

Just make registered nodes table empty

wrench.registered_nodes = {

And use API method to register all those nodes if default is loaded
function wrench:register_node(name, def)
if minetest.registered_nodes[name] then
self.registered_nodes[name] = def
end
end

@github-actions
Copy link

Mineunit failed regression tests, click for details

Regression test log for technic:

●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●◌●●●●●
57 successes / 0 failures / 0 errors / 1 pending : 0.14691 seconds

Pending → spec/supply_converter_spec.lua @ 99
Supply converter building overloads network
spec/supply_converter_spec.lua:99: overload does not work with supply converter

@S-S-X

This comment has been minimized.

@S-S-X

This comment has been minimized.

@S-S-X S-S-X mentioned this pull request Oct 23, 2021
@S-S-X
Copy link
Member

S-S-X commented Oct 23, 2021

Reduce optional dependencies of technic_worldgen using minetest.register_on_mods_loaded()

This might not be wise thing to do because every unnecessary registration check during register_on_mods_loaded makes system as a whole lot more complicated and is potential source of problems in future (not as bad but similar to using minetest.after to "fix" bugs).

For many things optional dependencies are good to have if there's real feature dependency, not only because it will allow Minetest to do suggestions for mods and ContentDB to show things that are meant to work together but also because it makes loading order clear and visible.

Is there some real reason (mod conflict) that requires dropping optional dependencies?

@OgelGames
Copy link
Contributor Author

Is there some real reason (mod conflict) that requires dropping optional dependencies?

No, the main reason is because they aren't dependencies at all, they're just there so some items can be renamed.

This is the code I was thinking of changing, using register_on_mods_loaded() to make it less "hacky", while also eliminating the need to include the mods as optional dependencies:

local function for_each_registered_item(action)
local already_reg = {}
for k, _ in pairs(minetest.registered_items) do
table.insert(already_reg, k)
end
local really_register_craftitem = minetest.register_craftitem
minetest.register_craftitem = function(name, def)
really_register_craftitem(name, def)
action(string.gsub(name, "^:", ""))
end
local really_register_tool = minetest.register_tool
minetest.register_tool = function(name, def)
really_register_tool(name, def)
action(string.gsub(name, "^:", ""))
end
local really_register_node = minetest.register_node
minetest.register_node = function(name, def)
really_register_node(name, def)
action(string.gsub(name, "^:", ""))
end
for _, name in ipairs(already_reg) do
action(name)
end
end
local steel_to_iron = {}
for _, i in ipairs({
"default:axe_steel",
"default:pick_steel",
"default:shovel_steel",
"default:sword_steel",
"doors:door_steel",
"farming:hoe_steel",
"glooptest:hammer_steel",
"glooptest:handsaw_steel",
"glooptest:reinforced_crystal_glass",
"mesecons_doors:op_door_steel",
"mesecons_doors:sig_door_steel",
"vessels:steel_bottle",
}) do
steel_to_iron[i] = true
end
for_each_registered_item(function(item_name)
local item_def = minetest.registered_items[item_name]
if steel_to_iron[item_name] and string.find(item_def.description, "Steel") then
minetest.override_item(item_name, { description = string.gsub(item_def.description, "Steel", S("Iron")) })
end
end)

And also this:

local function for_each_registered_node(action)
local really_register_node = minetest.register_node
minetest.register_node = function(name, def)
really_register_node(name, def)
action(name:gsub("^:", ""), def)
end
for name, def in pairs(minetest.registered_nodes) do
action(name, def)
end
end
for_each_registered_node(function(node_name, node_def)
if node_name ~= "default:steelblock" and
node_name:find("steelblock", 1, true) and
node_def.description:find("Steel", 1, true) then
minetest.override_item(node_name, {
description = node_def.description:gsub("Steel", S("Wrought Iron")),
})
end
local tiles = node_def.tiles or node_def.tile_images
if tiles then
local new_tiles = {}
local do_override = false
if type(tiles) == "string" then
tiles = {tiles}
end
for i, t in ipairs(tiles) do
if type(t) == "string" and t == "default_steel_block.png" then
do_override = true
t = "technic_wrought_iron_block.png"
end
table.insert(new_tiles, t)
end
if do_override then
minetest.override_item(node_name, {
tiles = new_tiles
})
end
end
end)

Yes it doesn't need to be changed, but I think it should be, and also be moved to a separate file.

@S-S-X S-S-X force-pushed the master branch 2 times, most recently from ef88bf1 to e5e4cbe Compare October 24, 2021 14:04
@S-S-X
Copy link
Member

S-S-X commented Oct 24, 2021

No, the main reason is because they aren't dependencies at all, they're just there so some items can be renamed.

In that case it could make sense, only reason to keep optional dependencies in mod.conf would be to make it visible that mod does something with another mod. Probably not that important for small changes done by technic_worldgen.

I did take a look at the code and one thing made me wonder if it works or breaks things:
Translations provided by other mods where technic_worldgen rewrites part of description, will translations actually work (for full description) after doing that or will it break translations?

Anyway, that cannot be really fixed here if translations wont work after editing descriptions but I think it is something that should be considered and tested.

If modified translations do break (or if translations are not tested) then would be good to open separate issue about that and let it be broken for now.
If translations do work even after modifications then I guess all good an no need to do anything.

@OgelGames
Copy link
Contributor Author

Yeah, I think translations were broken before, and they will still be broken after these changes. Probably still a good idea to open an issue about it, or at least mention it in #104

removed dependency on `screwdriver` and added `moreores` dependency
@OgelGames
Copy link
Contributor Author

Tidied up the commits, so the different changes can be merged as different commits. (rebase merge)

I don't think there is anything else that needs to be done in this PR, so it should be ready for merging (after an approval is added).

@OgelGames OgelGames removed the WIP Work in progress label Nov 1, 2021
@OgelGames OgelGames requested a review from S-S-X November 1, 2021 07:22
Copy link
Member

@S-S-X S-S-X left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me, change request just 2 lines for consistent style.

reduces optional dependencies and extends to support as many items as possible
@github-actions
Copy link

github-actions bot commented Nov 1, 2021

Click for detailed source code test coverage report

Test coverage report for Technic CNC 78.96% in 10/14 files:

File                             Hits Missed Coverage
-----------------------------------------------------
programs.lua                   263  0      100.00%
materials/basic_materials.lua  17   0      100.00%
materials/default.lua          177  4      97.79%
cnc.lua                        50   3      94.34%
formspec.lua                   103  8      92.79%
materials/init.lua             10   1      90.91%
digilines.lua                  39   8      82.98%
init.lua                       19   6      76.00%
api.lua                        160  83     65.84%
pipeworks.lua                  25   13     65.79%
materials/technic_worldgen.lua 0    25     0.00%
materials/moreblocks.lua       0    29     0.00%
materials/ethereal.lua         0    37     0.00%
materials/bakedclay.lua        0    13     0.00%

Test coverage report for technic 9.61% in 10/103 files:

File                                      Hits Missed Coverage
--------------------------------------------------------------
machines/HV/generator.lua                 9    0      100.00%
config.lua                                47   4      92.16%
machines/register/cables.lua              168  49     77.42%
machines/network.lua                      192  162    54.24%
machines/supply_converter.lua             75   66     53.19%
register.lua                              20   20     50.00%
machines/MV/cables.lua                    10   11     47.62%
machines/LV/cables.lua                    10   11     47.62%
machines/HV/cables.lua                    9    11     45.00%
machines/register/generator.lua           91   114    44.39%
util/throttle.lua                         0    11     0.00%
tools/vacuum.lua                          0    32     0.00%
tools/tree_tap.lua                        0    38     0.00%
tools/sonic_screwdriver.lua               0    51     0.00%
tools/prospector.lua                      0    101    0.00%
tools/multimeter.lua                      0    208    0.00%
tools/mining_lasers.lua                   0    65     0.00%
tools/mining_drill.lua                    0    268    0.00%
tools/init.lua                            0    14     0.00%
tools/flashlight.lua                      0    68     0.00%
tools/chainsaw.lua                        0    115    0.00%
tools/cans.lua                            0    71     0.00%
radiation.lua                             0    138    0.00%
max_lag.lua                               0    12     0.00%
machines/switching_station_globalstep.lua 0    58     0.00%
machines/switching_station.lua            0    79     0.00%
machines/register/solar_array.lua         0    30     0.00%
machines/register/recipes.lua             0    78     0.00%
machines/register/machine_base.lua        0    166    0.00%
machines/register/init.lua                0    22     0.00%
machines/register/grindings.lua           0    39     0.00%
machines/register/grinder_recipes.lua     0    100    0.00%
machines/register/grinder.lua             0    6      0.00%
machines/register/freezer_recipes.lua     0    12     0.00%
machines/register/freezer.lua             0    6      0.00%
machines/register/extractor_recipes.lua   0    71     0.00%
machines/register/extractor.lua           0    6      0.00%
machines/register/electric_furnace.lua    0    6      0.00%
machines/register/compressor_recipes.lua  0    33     0.00%
machines/register/compressor.lua          0    6      0.00%
machines/register/common.lua              0    114    0.00%
machines/register/centrifuge_recipes.lua  0    25     0.00%
machines/register/centrifuge.lua          0    6      0.00%
machines/register/battery_box.lua         0    240    0.00%
machines/register/alloy_recipes.lua       0    40     0.00%
machines/register/alloy_furnace.lua       0    30     0.00%
machines/power_monitor.lua                0    57     0.00%
machines/other/injector.lua               0    85     0.00%
machines/other/init.lua                   0    8      0.00%
machines/other/frames.lua                 0    551    0.00%
machines/other/constructor.lua            0    104    0.00%
machines/other/coal_furnace.lua           0    3      0.00%
machines/other/coal_alloy_furnace.lua     0    94     0.00%
machines/other/anchor.lua                 0    79     0.00%
machines/init.lua                         0    85     0.00%
machines/compat/digtron.lua               0    13     0.00%
machines/MV/wind_mill.lua                 0    45     0.00%
machines/MV/tool_workshop.lua             0    73     0.00%
machines/MV/solar_array.lua               0    7      0.00%
machines/MV/power_radiator.lua            0    96     0.00%
machines/MV/lighting.lua                  0    170    0.00%
machines/MV/init.lua                      0    17     0.00%
machines/MV/hydro_turbine.lua             0    44     0.00%
machines/MV/grinder.lua                   0    6      0.00%
machines/MV/generator.lua                 0    7      0.00%
machines/MV/freezer.lua                   0    6      0.00%
machines/MV/extractor.lua                 0    6      0.00%
machines/MV/electric_furnace.lua          0    6      0.00%
machines/MV/compressor.lua                0    6      0.00%
machines/MV/centrifuge.lua                0    6      0.00%
machines/MV/battery_box.lua               0    6      0.00%
machines/MV/alloy_furnace.lua             0    6      0.00%
machines/LV/water_mill.lua                0    47     0.00%
machines/LV/solar_panel.lua               0    27     0.00%
machines/LV/solar_array.lua               0    6      0.00%
machines/LV/music_player.lua              0    81     0.00%
machines/LV/led.lua                       0    38     0.00%
machines/LV/lamp.lua                      0    68     0.00%
machines/LV/init.lua                      0    17     0.00%
machines/LV/grinder.lua                   0    7      0.00%
machines/LV/geothermal.lua                0    56     0.00%
machines/LV/generator.lua                 0    7      0.00%
machines/LV/extractor.lua                 0    13     0.00%
machines/LV/electric_furnace.lua          0    6      0.00%
machines/LV/compressor.lua                0    10     0.00%
machines/LV/battery_box.lua               0    6      0.00%
machines/LV/alloy_furnace.lua             0    6      0.00%
machines/HV/solar_array.lua               0    6      0.00%
machines/HV/quarry.lua                    0    306    0.00%
machines/HV/nuclear_reactor.lua           0    266    0.00%
machines/HV/init.lua                      0    12     0.00%
machines/HV/grinder.lua                   0    6      0.00%
machines/HV/forcefield.lua                0    213    0.00%
machines/HV/electric_furnace.lua          0    6      0.00%
machines/HV/compressor.lua                0    6      0.00%
machines/HV/battery_box.lua               0    6      0.00%
legacy.lua                                0    7      0.00%
items.lua                                 0    51     0.00%
integration_test.lua                      0    24     0.00%
init.lua                                  0    30     0.00%
helpers.lua                               0    116    0.00%
effects.lua                               0    3      0.00%
crafts.lua                                0    86     0.00%

Raw test runner output for geeks:

CNC:

●●●●●●●●●●●●●●●●●●●●●●
22 successes / 0 failures / 0 errors / 0 pending : 0.198193 seconds

Technic:

●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●◌●●●●●
57 successes / 0 failures / 0 errors / 1 pending : 0.183089 seconds

Pending → spec/supply_converter_spec.lua @ 99
Supply converter building overloads network
spec/supply_converter_spec.lua:99: overload does not work with supply converter

@OgelGames OgelGames mentioned this pull request Nov 1, 2021
@OgelGames OgelGames requested a review from S-S-X November 1, 2021 14:59
Copy link
Member

@S-S-X S-S-X left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me 👍
Also did quick test that registered items (just names) were same in master.

@OgelGames OgelGames merged commit c6433a9 into master Nov 1, 2021
@OgelGames OgelGames mentioned this pull request Nov 4, 2021
@OgelGames OgelGames deleted the depends-cleanup branch November 8, 2021 09:34
@Athozus Athozus added this to the 2.0.0 milestone Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug fix Cleanup Cleanup of bad code or other redundant/unnecessary stuff
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problems with dependencies
3 participants