Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed removal of "separate" parts #244

Merged
merged 1 commit into from
Aug 4, 2024
Merged

Conversation

GrandpaScout
Copy link
Contributor

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.

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, `: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.
@GrandpaScout
Copy link
Contributor Author

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

@UnlikePaladin UnlikePaladin merged commit aa77a73 into FiguraMC:1.20 Aug 4, 2024
1 check passed
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.

2 participants