FiguraMC / Figura

Extensively customize your character with Figura!
https://modrinth.com/mod/figura
GNU Lesser General Public License v2.1
225 stars 44 forks source link

Fixed removal of "separate" parts #244

Closed GrandpaScout closed 1 month ago

GrandpaScout commented 1 month ago

This fixes issues involving removal or addition of parts with parent types considered "separate." (World, Hud, Elytra, etc.) This is done by running AvatarRenderer.sortParts() when it should be run.

Basic testing was done and it seems to work for every case I gave it.

Due to the nature of this bug, FiguraModelPart.removeChild() always has to sort parts again even if the child being removed is not separate because that child could contain a child that is separate (and so on.)
If anyone has a better solution feel free to do whatever.


This bug caused world parts to continue to be rendered even after being removed with :remove() or not render at all if added with :moveTo() or :addChild().

The easiest way to test this bug is to create a model with the structure root > World > cube and then remove root:

function show_bug()
  models.model.root:remove()
end

Note how the cube is still visible after removal.

Using the same structure, the other side of the bug can be shown:

function show_bug2()
  local copy = models.model.root.World:copy("foo")
  copy:setPos(16, 0, 0) -- move the copy so it doesn't intersect with the original
  copy:moveTo(models.model.root)
end

A second cube should not appear.

In 0.1.4, this issue can be avoided by first setting the parent type of parts that this bug affects to "None" before doing these operations. The parent type can be set back after the operations are completed.

GrandpaScout commented 1 month ago

Gradle did not want to cooperate with me while I was making this so let me know if I missed something.