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

ItemType Random Safety Improvements #6886

Merged

Conversation

APickledWalrus
Copy link
Member

Description

This PR aims to fix usages of ItemType#getRandom that did not properly check whether it is null (as is possible due to 1.21 changes).

I've updated ItemType#getMaterial to instead return a random Material rather than the material of the first ItemData. Some places do not need a random ItemStack, just a random Material (which can never be null).

Additionally, I've added a new method, getRandomStackOrMaterial (terrible I know, suggestions welcome) which grabs a random ItemData from the ItemType, and returns its ItemStack or Material (if it does not have stack). This is for cases where either an ItemStack or a Material is valid (e.g. max stack size). We may also choose to not return values for these materials, even though they exist. Thoughts welcome 🙂


Target Minecraft Versions: any
Requirements: none
Related Issues:

@APickledWalrus APickledWalrus added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. 2.9 Targeting a 2.9.X version release labels Jul 8, 2024
@APickledWalrus APickledWalrus merged commit d48a261 into SkriptLang:dev/feature Jul 12, 2024
5 checks passed
@APickledWalrus APickledWalrus deleted the patch/itemtype-random branch July 12, 2024 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.9 Targeting a 2.9.X version release bug An issue that needs to be fixed. Alternatively, a PR fixing an issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants