minetest-mods / technic

Technic mod for Minetest
Other
146 stars 155 forks source link

Battery Box does not see network, will not charge. #614

Closed ulamthelucky closed 1 year ago

ulamthelucky commented 1 year ago

Technic has no main developer and largely depends on user-provided Pull Requests. It will take a while until even important issues are noticed. Please consider proposing a PR directly.


This is a very recent bug that showed up after updating the technic mod within the past two weeks.

Placing an LV battery box onto an LV network containing power sources and a switching station, the Battery box still shows no network.

Open creative world, with only Technic mod enabled. Place down LV solar arrays, attach with LV cables. Place down Swtiching station, connected by LV cables to the Solar Arrays Place down a LV Battery Box on top of open LV cable that is connected to the switching station and the Solar Arrays.

Battery Box still shows it has no network.=, even though it's clearly connected to one.

Problem occurs in existing worlds and if creating a new world and all new technic nodes.

See example image:

image

SmallJoker commented 1 year ago

image

Works for me. Please check for mod updates first. If the issue still persists, please try to reproduce the issue in a new world. If that does not solve it either, feel free to send me a .zip of your world so that I can try to reproduce it.

ulamthelucky commented 1 year ago

Sure, here is the world - it's not just this one, but I made a brand new one and just added technic and placed the circuit and battery box, etc....

Mods are all updated: image

Here is the world.

The Battery has some charge because I had modified the code locally to get them to work, and had to undo the change to get it back to source mod.

I'm running in Windows 11. Minetest 5.6.1

battery_test.zip

SmallJoker commented 1 year ago

Test 1. Linux native 64 bit. Result: Battery charges

Minetest 5.7.0-dev-7bf64fc61 (Linux)
Using Irrlicht 1.9.0mt9
Using LuaJIT 2.1.0-beta3

Test 2: Windows 64 bit though Wine 7.21. Result: Battery has no network

Minetest 5.6.1 (Windows)
Using Irrlicht 1.9.0mt8
Using LuaJIT 2.1.0-beta3

There seems to be a precision issue on Windows caused by 32-bit integers.

SmallJoker commented 1 year ago

https://github.com/LuaJIT/LuaJIT/issues/911

Please give a feedback whether these changes fix the issue on your side:

diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua
index 6fe5574..190ddbf 100644
--- a/technic/machines/register/battery_box.lua
+++ b/technic/machines/register/battery_box.lua
@@ -193,7 +193,7 @@ function technic.register_battery_box(data)

        local run = function(pos, node)
                local meta = minetest.get_meta(pos)
-               local network_id = tonumber(meta:get_string(tier.."_network"), 16)
+               local network_id = tonumber(meta:get_string(tier.."_network"))

                if not technic.networks[network_id] then
                        meta:set_string("infotext", S("%s Battery Box Has No Network"):format(tier))
diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua
index bd34a0a..e97e761 100644
--- a/technic/machines/switching_station.lua
+++ b/technic/machines/switching_station.lua
@@ -134,7 +134,8 @@ local check_node_subp = function(network, pos, machines, sw_pos, from_below, net
        --dprint(name.." is a "..machines[name])
        local meta = minetest.get_meta(pos)
        -- Normal tostring() does not have enough precision, neither does meta:set_int()
-       meta:set_string(network.tier.."_network", string.format("%X", network_id))
+       -- Bug: Cannot use hexadecimal notation for compression (LuaJIT Windows bug, #911)
+       meta:set_string(network.tier.."_network", string.format("%.20g", network_id))

        if     eu_type == technic.producer then
                add_network_node(network.PR_nodes, pos, network_id)

EDIT: Fixed the string formatting

ulamthelucky commented 1 year ago

It does fix it yes. Thanks