Fix mte traits being treated as duplicate #1690
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
This PR fixes a bug where MTETraits would all be treated as duplicate. This is because it was stored in the MTE's trait map before initializing the
name
andnetworkId
of the trait. Therefore, themteTraitByNetworkId
map in MTE treated each trait as the same, breaking network sync. This PR fixes this.Additionally, the
networkId
stored in the trait itself was always zero, due to using the result ofmap#put
to initialize it. This was another problem, since the return value ofmap#put
is the old value, which is always 0 for unique traits, and is not the new id.This problem is linked to machine animations not working, recipe search sometimes not starting, likely sounds not functioning, and possibly many other issues.
Implementation Details
The MTETrait
name
field is now stored as a constant instead of being created each time. The creation of the name has moved to anprotected abstract
methodcreateName()
, while the getter has been madefinal
and concrete.Outcome
Fixes MTETraits being treated as duplicates. Closes #1692.
Potential Compatibility Issues
Mods which adopted the new MTETrait system will have to change their override of
getName()
, which is now concrete and final, tocreateName()
.