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

Split BuildCreativeModeTabContentsEvent internals to operate on two separate sets #1156

Open
wants to merge 22 commits into
base: 1.21.x
Choose a base branch
from

Conversation

TelepathicGrunt
Copy link
Contributor

@TelepathicGrunt TelepathicGrunt commented Jun 21, 2024

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 be event.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

@TelepathicGrunt TelepathicGrunt added bug A bug or error breaking change Breaks binary compatibility 1.21 Targeted at Minecraft 1.21 labels Jun 21, 2024
@TelepathicGrunt TelepathicGrunt self-assigned this Jun 21, 2024
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Jun 21, 2024

  • Publish PR to GitHub Packages

Last commit published: b25bdfb123d389b12b48f7dec9c475d5bae02fce.

PR Publishing

The artifacts published by this PR:

Repository Declaration

In 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', 'testframework')
            includeModule('net.neoforged', 'neoforge')
        }
    }
}

MDK installation

In order to setup a MDK using the latest PR version, run the following commands in a terminal.
The script works on both *nix and Windows as long as you have the JDK bin folder on the path.
The script will clone the MDK in a folder named NeoForge-pr1156.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr1156
cd NeoForge-pr1156
curl -L https://prmaven.neoforged.net/NeoForge/pr1156/net/neoforged/neoforge/21.0.74-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.

@TelepathicGrunt TelepathicGrunt changed the title Split BuildCreativeModeTabContentsEvent to operate on two separate sets Split BuildCreativeModeTabContentsEvent internals to operate on two separate sets Jun 21, 2024
@TelepathicGrunt
Copy link
Contributor Author

Special thanks to dhyces (https://github.com/dhyces) for the new and improved data structure for this PR

@neoforged-compatibility-checks
Copy link

neoforged-compatibility-checks bot commented Jun 24, 2024

@TelepathicGrunt, this PR introduces breaking changes.
Fortunately, this project is currently accepting breaking changes, but if they are not intentional, please revert them.
Last checked commit: b25bdfb123d389b12b48f7dec9c475d5bae02fce.

neoforge (:neoforge)

  • net/neoforged/neoforge/common/util/MutableHashedLinkedMap
    • IDENTITY:Lit/unimi/dsi/fastutil/Hash$Strategy;: ❗ API field was removed
    • BASIC:Lit/unimi/dsi/fastutil/Hash$Strategy;: ❗ API field was removed
  • net/neoforged/neoforge/event/BuildCreativeModeTabContentsEvent
    • <init>(Lnet/minecraft/world/item/CreativeModeTab;Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/item/CreativeModeTab$ItemDisplayParameters;Lnet/neoforged/neoforge/common/util/MutableHashedLinkedMap;)V: ⚠ API method was removed
    • getEntries()Lnet/neoforged/neoforge/common/util/MutableHashedLinkedMap;: ❗ API method was removed

@TelepathicGrunt
Copy link
Contributor Author

Breaking changes are intentional. Can’t fix and improve event without breaking things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21 Targeted at Minecraft 1.21 breaking change Breaks binary compatibility bug A bug or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[1.21] Creative Category sorting methods don't work
6 participants