TheCSMods / mc-no-unused-chunks

A Minecraft mod that reduces world size by discarding unused chunks.
MIT License
17 stars 2 forks source link

[Bug] With the manual world optimization chunk deletion, structures at chunk edges will have blocks cut off #13

Closed shal0l closed 1 year ago

shal0l commented 1 year ago

Like this: javaw_lqKvK4glYM

It could (handily?) be mitigated if there was logic to maintain the save flag for the neighboring chunks in a radius, of edited/player visited chunks.

Regardless of feasibility, the mod is still great as is. Thank you!

TheCSDev commented 1 year ago

Interesting bug, thanks for reporting it, and also thanks for suggesting how it could be fixed.

Tho, I am having a bit of a hard time trying to figure out what exactly happened here and what caused it. Usually when a chunk is discarded, it is supposed to be re-generated in the same way it was generated prior to being discarded, so having a cut-off tree appear does confuse me a bit.

Also, I was thinking about a similar thing and worrying it might be an issue when it comes larger strustures like fortresses. Specifically, what if the player puts the "save flag" on one half of a structure, and then discards the other half with the mod. But even in that case, the other half should just re-generate with no issues as far as I know.

So how that tree managed to get cut-off instead of re-generated properly does confuse me. If it is because the tree structure refused to generate its other half in a player-modified chunk, then the leaves in that player-modified chunk should have remained from the previous generation unless they got removed manually?

I guess will try to figure out what the issue could be. In the meantime, you could also let me know how you think this took place and what you did to replicate the issue. Thanks again and have a great day!

shal0l commented 1 year ago

Bad report, it's not affecting structures. That was a poor assumption based on the trees. Just trees. While this was my original assumption:

I'd guess it would be due to the tree (analogy to a sapling) belonging to the player edited chunk, and while the structure leaves/blocks may happen to go outside the chunk, the root tree place/coordinate is still at the flagged chunk. 
Therefore, it won't re-generate the leaves because the origin tree of these leaves hasn't been deleted and thus won't generate itself and thus the leaves for the deleted chunk.

After just trying it on a new 1.19.2 world, no mods, latest forge, it seems to be "randomly" picking chunks and doing something with the tree blocks generation, even if the nearby chunks were left untouched, which is mildly concerning. So maybe forget my fix suggestion because it appears to be a whole other issue now.. *Doesn't happen with the mods auto chunk unflagging, only manual blast?

https://imgur.com/a/d71RN9B

TheCSDev commented 1 year ago

Yeah, I guess it does seem mildly concerning, so long as it doesn't cause too much damage.

I guess my best way of figuring out what causes this bug would be to first figure out how Minecraft generates trees and how it handles generating them at chunk borders.

Now I wonder how Minecraft handles trees when you approach a chunk with them at the border, but not close enough to the neighboring chunk for the other half of the tree to generate. Maybe Minecraft uses some sort of flag to track incomplete trees, a kind of flag that is gone after the neighboring chunk is generated and the tree finally completes? And then.. you discard the unused chunk where it got completed, but the flag is now gone, hence the other half of the tree is now gone too? That's the only thing I can thin of that may be causing this bug, but I'm unsure.

If that completely random guess I had turns out to be it, then I guess there's nothing that can be done during the world optimization phase, as there'd be no way to keep track of trees, and the "maintaining the save flag for the neighboring chunks in a radius, of edited/player visited chunks" idea might only offset the issue.. Tho I hope it isn't one of those issues that can not be resolved during world optimization, because then we'd be out of luck.

Edit: or wait.. the idea you had in the initial bug report message might actually be the solution now that i think about it. i will have to experiment with that and see if it fixes the issue.

TheCSDev commented 1 year ago

I will now pin this issue in case anyone else encounters it

If anyone's interested in why it happens, here's why (please click here).

Unfortunately this bug is un-resolvable from my end.

Basically, when Minecraft generates trees at chunk edges next to un-loaded and non-existing chunks, it stores the coordinates and information about those "unfinished' trees on the physical hard drive. The next time you walk close enough to the non-existing chunks next to those trees, the game will retrieve the data about the "unfinished" trees from the hard drive, after which it will "finish" them whenever possible.

The problem is, when removing already previously generated chunks, the trees will go back to being "unfinished", but this time, since they were already generated before, nothing will keep track of them again, resulting in them remaining "unfinished" and "cut-off" after removing unused chunks that are next to them.

This unfortunately, is not possible to fix.