Skip to content

Conversation

@pyrollo
Copy link
Contributor

@pyrollo pyrollo commented Aug 16, 2025

A quick & dirty fix for making battery holder working with current version of Luanti & Tehnic.

Using both master versions, battery holder always reject charged objects (md is nil).

I just updated code to use new get_meta api and "technic:charge" metadata name.

@pyrollo pyrollo force-pushed the pyrollo/fix-battery branch from 51e7359 to f7426af Compare August 16, 2025 16:16
@DustyBagel
Copy link

I was just about to make a pr to do just that! Thanks.

Copy link

@DustyBagel DustyBagel left a comment

Choose a reason for hiding this comment

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

Make sure to also update the digtron.tap_batteries function in https://github.com/minetest-mods/digtron/blob/master/util.lua#L265 so that it also uses technic's new way of storing the item's charge value.

@pyrollo pyrollo force-pushed the pyrollo/fix-battery branch from f7426af to a38b14d Compare August 20, 2025 08:59
@pyrollo
Copy link
Contributor Author

pyrollo commented Aug 20, 2025

Thanks to your comments I realized I did a very partial job :)

Now inventory put, tube sending and battery consumption are fixed.

I changed battery consumption so only power needed for next step is drained (it seemed better to me but may be it's not Digtron policy).

-- Disregard empty batteries, the player should know better
if md and md.charge > 0 then
meta = minetest.get_meta(pos)
if minetest.global_exists("technic") and technic.get_charge(stack) > 0 then
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the previous comment about -- Disregard empty batteries, the player should know better to justify the charge > 0 check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment is back.
Anyway I was wondering if it would be better to accept empty batteries (seems more usual).

Copy link
Member

Choose a reason for hiding this comment

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

This function should be logically equivalent to allow_metadata_inventory_put. The player (automated or manual action) should be made aware that the battery is not usable as-is. Some feedback is needed for them, and rejecting the movement transaction is about the most simple approach to do that.
Anyway. I think this should be kept.

@pyrollo pyrollo force-pushed the pyrollo/fix-battery branch from d99f368 to 416686c Compare August 22, 2025 06:21
@DustyBagel
Copy link

DustyBagel commented Aug 22, 2025

I changed battery consumption so only power needed for next step is drained (it seemed better to me but may be it's not Digtron policy).

I always assumed that the whole charge of an itemstack was drained all at once because if we do that we don't have to keep running the code that takes the energy from itemstacks every time the digtron moves and can instead do it all at once. I would imagine digteon's old way would be good for big servers that may have many digtron's running all at once. I might be wrong, though.

@SmallJoker might know. They seem to be way more active in the Luanti community and with this mod than I am.

@SmallJoker
Copy link
Member

if we do that we don't have to keep running the code that takes the energy from itemstacks every time the digtron moves and can instead do it all at once.

This is a fair argument. Whereas the PR makes it more realistic (decrement as needed), it also means that the itemstacks are updated every time in digtron.execute_dig_cycle. That is upon manual input or when using a specified dig interval (auto mode). Note: this is based on static code analysis only. I did yet not set up an in-game test to double-check that.
Luckily, the inventory changes are rather quick, and the data sent over the network is compressed as of the most recent Luanti versions, thus no significant impact on network activity.

As a compromise, we could instead drain - say - 5x the target energy and break afterwards. I wouldn't recommend more optimizations in this function, as digtron.execute_dig_cycle is considerably more complex.

@DustyBagel
Copy link

Just to be clear, I'm not arguing for one approach over the other. I was just making an observation. In situations like this I would just make a setting and call it a day. I just want the fix merged and everyone happy. :)

@pyrollo
Copy link
Contributor Author

pyrollo commented Aug 22, 2025

The possible performance issue is very interesting.
I'm not very keen on @SmallJoker proposed solution (sort of half-half), I'd rather revert this particular change and keep it somewhere in a branch for maybe later (or not).
I guess it's way more important to fix the problem.

@pyrollo pyrollo force-pushed the pyrollo/fix-battery branch from 416686c to d7bd622 Compare August 22, 2025 19:12
@pyrollo pyrollo force-pushed the pyrollo/fix-battery branch from d7bd622 to 148293d Compare August 22, 2025 19:20
@SmallJoker
Copy link
Member

Okay, sure. Without further ado - LGTM.

@SmallJoker SmallJoker merged commit 3d391a0 into minetest-mods:master Aug 23, 2025
1 check passed
@pyrollo pyrollo deleted the pyrollo/fix-battery branch August 23, 2025 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants