-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Split BuildCreativeModeTabContentsEvent internals to operate on two separate sets #1156
Split BuildCreativeModeTabContentsEvent internals to operate on two separate sets #1156
Conversation
Last commit published: 7b5a8ab43be3cfdab91222515ec56f125d702582. PR PublishingThe artifacts published by this PR:
Repository DeclarationIn order to use the artifacts published by the PR, add the following repository to your buildscript: repositories {
maven {
name 'Maven for PR #1156' // https://github.com/neoforged/NeoForge/pull/1156
url 'https://prmaven.neoforged.net/NeoForge/pr1156'
content {
includeModule('net.neoforged', 'neoforge')
includeModule('net.neoforged', 'testframework')
}
}
} MDK installationIn order to setup a MDK using the latest PR version, run the following commands in a terminal. mkdir NeoForge-pr1156
cd NeoForge-pr1156
curl -L https://prmaven.neoforged.net/NeoForge/pr1156/net/neoforged/neoforge/21.0.90-beta-pr-1156-CreativeTabSort/mdk-pr1156.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip To test a production environment, you can download the installer from here. |
src/main/java/net/neoforged/neoforge/event/BuildCreativeModeTabContentsEvent.java
Outdated
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/common/util/InsertableStrictLinkedHashSet.java
Outdated
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/common/util/InsertableStrictLinkedHashSet.java
Outdated
Show resolved
Hide resolved
Special thanks to dhyces (https://github.com/dhyces) for the new and improved data structure for this PR |
src/main/java/net/neoforged/neoforge/event/BuildCreativeModeTabContentsEvent.java
Outdated
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/event/BuildCreativeModeTabContentsEvent.java
Outdated
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/common/util/InsertableLinkedOpenCustomHashSet.java
Outdated
Show resolved
Hide resolved
tests/src/main/java/net/neoforged/neoforge/oldtest/CreativeModeTabTest.java
Outdated
Show resolved
Hide resolved
@TelepathicGrunt, this PR introduces breaking changes.
|
Breaking changes are intentional. Can’t fix and improve event without breaking things |
src/main/java/net/neoforged/neoforge/common/util/InsertableLinkedOpenCustomHashSet.java
Show resolved
Hide resolved
Add documentation, adjust tests, and cleanup/fix behavior
src/main/java/net/neoforged/neoforge/common/util/InsertableLinkedOpenCustomHashSet.java
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/common/util/MutableHashedLinkedMap.java
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/common/util/strategy/BasicStrategy.java
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/common/util/strategy/BasicStrategy.java
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/common/util/strategy/IdentityStrategy.java
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/common/util/strategy/IdentityStrategy.java
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/event/BuildCreativeModeTabContentsEvent.java
Outdated
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/event/BuildCreativeModeTabContentsEvent.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge when ready.
All xfact's suggestions have been resolved
So bit of background on this. This area has spawned 3 different bugs.
First,
Creative Menu Enchanted Books are not ordered correctly.
.Then
BuildCreativeModeTabContentsEvent uses wrong hashing strategy for entries
.And now,
Creative Category sorting methods don't work
.The root cause is how we were trying to wrestle how vanilla handles the parent tab and the search tab as well as us trying to force a single map to apply in both cases. There's several edge cases to keep track of such as vanilla allowing the same itemstack (same as in item, component, and count) in the original map because they add some Enchanted Books twice. One for the order to do in Parent Tab. And again for the order to do in the Search tab. This is a significant pain point.
But later, vanilla does do an ItemStackLinkedSet.TYPE_AND_TAG strategy check on the NON-SEARCH only entries to make sure a tab does not have equivalent itemstacks in it. Search tab gets a free pass apparently... Even though it doesn't make sense. (Technically I think it is because that was Mojang's hack around the Enchantment Books edge case)
What I tried to do is make BuildCreativeModeTabContentsEvent work with two separate sets of itemstacks instead. One for parent tab. One for search tab. The sets have build-in checks to prevent equivalent itemstacks from being fed into that same set so we give a better error message to modders than vanilla's.
To allow this, new system to work, I tried to keep it where you still give the visibility to BuildCreativeModeTabContentsEvent but the event itself will handle which internal set to manipulate. I also, removed the ability to get the underlying data structure that was exposed for manipulation because BuildCreativeModeTabContentsEvent's new modifying methods have some sanity checks that modders should be going through.
However, I did keep BuildCreativeModeTabContentsEvent's accept method the same so for anyone only using that method, this should not be a breaking change for them! Any other manual manipulation now should go through the event's methods which I tried to mirror the old map's methods to make porting easier. Just swap
event.getEntries().putAfter(
to beevent.putAfter(
. If there's other map methods that we want to restore, we can add them and make sure they are safe and account for edge cases.Also, please give feedback on how to improve InsertableStrictLinkedHashSet. I basically needed a LinkedHashSet but also to support putAfter and putBefore operations as well as support for hashing strategy (we operate on itemstack equivalency, not itemstack objects). There was no existing data structure I could find to fit that use case so had to scrape together InsertableStrictLinkedHashSet. Performance on this isn't... great if you check the code. Need ideas for improvements or people making commits to this PR
Closes #1119