Post B1DE5eKZe3nIEfIChc by luatic@mastodon.social
(DIR) More posts by luatic@mastodon.social
(DIR) Post #B1AOcSp7rkC6AbzNrc by cy@fedicy.us.to
2025-12-12T08:26:33Z
0 likes, 0 repeats
Alright, so I create a VoxelManip object and read an area from the map, around my position. Then I use a VoxelArea object on the "emergent" boundaries of the VoxelManip, just like several modules have already done, and work great.Now to test it, I use the latter to index into the former, putting a "diamond block" in my exact position in a test world, then writing that to the map.The result is it adds a diamond block, like... uh... over there, somewhere? And when I move positions, it starts adding dozens of diamond blocks randomly scattered all over a 50 block area around me. Never adding anything to the only position that I added something to. This is like 3 seconds of me slightly moving a few blocks over.#programming #vidya #luanti #fail #FuckEverything
(DIR) Post #B1BHKoO6RmbhJgweJM by cy@fedicy.us.to
2025-12-12T18:40:48Z
0 likes, 0 repeats
Ah, huh. The VoxelArea somehow uses the integer representation of floating point numbers as its coordinates. So you have to convert them to integers before passing to the VoxelArea. Even though Lua doesn't have integers. Specifically you have to round them to the nearest integer, and Lua also doesn't have a function to round to the nearest integer, only floor and ceil.Works now! 😩Why couldn't they have just stayed in C++...
(DIR) Post #B1DE5eKZe3nIEfIChc by luatic@mastodon.social
2025-12-13T16:24:00Z
0 likes, 0 repeats
@cy that's a common mistake, happened to me some years ago as well 🙃 we have some supplemental documentation at https://docs.luanti.org that warns about this and some other things, often a good idea to check that out (esp. when something isn't working as expected): https://docs.luanti.org/for-creators/api/classes/voxelarea/#areaindexx-y-zpart of the reason for these rough edges is that VoxelManip-related APIs need to be very performance-conscious and thus skip some validation. might be a good idea to have some kind of "debug" mode for them.
(DIR) Post #B1DE5fOVguXLXA8rTc by cy@fedicy.us.to
2025-12-13T17:13:47Z
0 likes, 0 repeats
Rough edges is fine as long as it's documented. Could at least mention it in lua_api.md? I'll try to go to that website if I'm ever stuck again, but it's working fine now! Well, I can't speak for performant, but my computer's a potato, so probably.
(DIR) Post #B1DmaOx4GsNDxN8JTU by luatic@mastodon.social
2025-12-13T23:30:35Z
0 likes, 0 repeats
@cy There seems to be some brief mention in lua_api.md (e.g. on `VoxelArea:index(p)`), but it is easy to overlook; perhaps you missed them.This section of the docs is being touched again, we'll try to make it more clear.I'm not saying it's necessarily as performant as we'd want it to be (there are still some limits stemming e.g. from the use of Lua), but it might be even less performant if it did try to do proper validation in a hot path :p
(DIR) Post #B1DmaPtCmisUrgKk5o by cy@fedicy.us.to
2025-12-13T23:40:24Z
0 likes, 0 repeats
Aww, yeah you're probably right. I did scan them closely, on finding out my blunder, but I could miss a gorilla running by if I was looking for it.Just a mention is enough! More better ofc, but if it's in there, then it's entirely my bad.