Skip to content

Don't pre-generate the pattern on wandering trader scrolls - #1363

Open
Robotgiggle wants to merge 9 commits into
mainfrom
trader-scroll-fix
Open

Robotgiggle wants to merge 9 commits into
mainfrom
trader-scroll-fix

Conversation

@Robotgiggle

@Robotgiggle Robotgiggle commented Nov 2, 2026 •

Copy link
Copy Markdown
Member
  • Fixes Pattern on wandering trader scrolls can be read via F3+I without purchasing them #1357.
  • Fixes Ancient Scrolls immediately refilling themselves when you try to erase them.
  • Streamlines the "get a random great spell ResourceKey" and "get all the great spell IDs" behavior in various places
  • Changes the item name for non-large ancient scrolls to the standard Ancient Scroll of <spell> rather than How did you get this item of <spell> since packmakers should be able to use other sizes if they want to.

@Robotgiggle Robotgiggle added enhancement New feature or request 1.20 labels Nov 2, 2026
@github-project-automation github-project-automation Bot moved this to 📋 Backlog in Hex Casting Nov 2, 2026
@Robotgiggle

Robotgiggle commented Nov 2, 2026 •

Copy link
Copy Markdown
Member Author

Registry#getTagOrEmpty produces Iterable<Holder<T>>, and Registry#getRandomElementOf produces Optional<Holder<T>>. Both of these will eventually get unwrapped into a T, which in this case is an ActionRegistryEntry, but that's not what the various methods here actually need - they need a ResourceKey<ActionRegistryEntry>, because that's what PatternRegistryManifest#getCanonicalStrokesPerWorld uses to look up great spell patterns. The lookup system does seem like it could be reworked to directly use ActionRegistryEntry rather than ResourceKey<ActionRegistryEntry>, but that would break ABI in a ton of places and would have to go into 1.21.

Also, there's no way to select a random element from an Iterable without turning it into a proper List first, and the code necessary to do that (and also to convert each element to a ResourceKey) would be just as long as the current isOfTag system.

@Robotgiggle

Robotgiggle commented Nov 2, 2026 •

Copy link
Copy Markdown
Member Author

Hmm actually, I could probably just add an overload for getCanonicalStrokesPerWorld that takes ActionRegistryEntry and then leave the rest of the lookup system alone - lemme look into that.

@Robotgiggle

Robotgiggle commented Nov 3, 2026 •

Copy link
Copy Markdown
Member Author

Turns out the mechanism used by Registry#getRandomElementOf in 1.21 already exists in 1.20, it just doesn't have a dedicated method to invoke it - so I just used in manually in the two places that need it. Running through the whole list to generate the creative scrolls was a little more annoying but I was able to set up a stream() to do it.

In 1.21, we can properly use Registry#getRandomElementOf, and I might also add a boolean argument to AddPerWorldPatternToScrollFunc#doStatic that controls whether the pattern is added alongside the action ID, so that I can just call it for the wandering trader rather than duplicating the whole registry lookup.

It's annoying that there's no way to filter registry keys by tag rather than entries, because that would make all of this a lot simpler. Doing a whole chain of method calls to get the ActionRegistryEntry and then plugging it right back into Registry#getResourceKey to get its key feels kinda weird.

AddPerWorldPatternToScrollFunc.doStatic(scroll, rand, self.getServer().overworld());
var actionID = IXplatAbstractions.INSTANCE.getActionRegistry().getTag(HexTags.Actions.PER_WORLD_PATTERN)
.flatMap(set -> set.getRandomElement(rand)).flatMap(Holder::unwrapKey)
.map(key -> key.location().toString()).orElseThrow();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map(key -> key.location().toString()).orElseThrow();
.map(Identifier::location).orElseThrow().toString();

more beautiful :P

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.20 enhancement New feature or request

Projects

Status: 📋 Backlog

Development

Successfully merging this pull request may close these issues.

Pattern on wandering trader scrolls can be read via F3+I without purchasing them

3 participants