It's time for another episode of explaining stupid bugs! I am given to understand that the more normal thing to do with game bugs is to quickly fix them and never speak of them again, but I just find them too entertaining. This time around: every once in a while in combat, the whole ground would suddenly fall away, buildings and all. Awkward. But why?
The ground is the same kind of object as floating rocks, only set to be immobile. With version 6, I added some code to split up these land formations if they became disconnected. So if you smash into a tree trunk, the now-disconnected top of the tree becomes an independently moving entity. If it didn't, it would hover in midair.
No one would ever buy a game with such broken physics, I tell you!
OK, so if the ground is in multiple disconnected parts, the disconnected parts become independent entities. But what's the ground, and what the disconnected part? The code to determine this divides the land formation into contiguous regions by repeatedly finding the earliest block not yet in a region and adding all of its connected blocks into a new region. If there's more than one region, the additional regions get hived off into their own entities.
So if we have a disconnected bit of foliage really high up, that's region one, and the rest of the ground is region two - which gets put into a new entity, which doesn't have the "immobile" flag set - and falls down! The ground breaks off the foliage, rather than the other way around.
How to fix this? Well, conveniently, the real ground can be distinguished by an unique property: it contains bedrock blocks. So instead of searching through all the blocks from the top left, a first pass of the region code will seek out bedrock blocks first, and add all of them and their connected blocks to the first region. This guarantees that the ground will keep on being the ground, and anything that breaks off gets their own entity. What a relief.