Skip to content

Make GameRule a FeatureDependant #12429

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

Merged
merged 5 commits into from
Apr 14, 2025

Conversation

DerEchtePilz
Copy link
Contributor

So I was playing around with game rules a bit and after running into an issue that GameRule#values() does contain even game rules that are disabled because the experimental data pack isn't enabled, I was wondering if there was a way to check if a game rule is enabled or not.

What I've found is that World#getGameRules() should contain only enabled game rules, however that wasn't applicable for my usecase since I didn't have a world available.

This PR adds an isEnabled() method to the GameRule class to make it possible to check if the game rule is enabled without needing access to a world.

@DerEchtePilz DerEchtePilz requested a review from a team as a code owner April 13, 2025 16:12
@github-project-automation github-project-automation bot moved this to Awaiting review in Paper PR Queue Apr 13, 2025
@lynxplay
Copy link
Contributor

We already have a system for that around FeatureDependant and FeatureFlagSetHolder.
GameRule should implement FeatureDependant

@DerEchtePilz
Copy link
Contributor Author

That doesn't seem to be the case.

@lynxplay
Copy link
Contributor

Yea it doesn't rn xD SOrry I wasnt clear, the PR should do that instead of adding a new system.

@DerEchtePilz
Copy link
Contributor Author

Okay, I'll do that then 👍

@DerEchtePilz DerEchtePilz force-pushed the gamerule-accessiblity branch from d67e869 to dffa034 Compare April 13, 2025 18:25
@DerEchtePilz DerEchtePilz changed the title Add an isEnabled method to GameRule Make GameRule a FeatureDependant Apr 13, 2025
Copy link
Contributor

@lynxplay lynxplay left a comment

Choose a reason for hiding this comment

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

Generally LGTM!
I do wonder however if it would be smart to patch the GameRules internals to also maintain a Map<String, GameRule.Type<?>> for faster access.
The fact that this method is going to be pretty spam-heavy for checks would mean such optimisations would have a hopefully measurable effect.

@github-project-automation github-project-automation bot moved this from Awaiting review to Awaiting final testing in Paper PR Queue Apr 13, 2025
@lynxplay lynxplay force-pushed the gamerule-accessiblity branch from 584a7c1 to ab35a42 Compare April 14, 2025 10:07
@lynxplay lynxplay merged commit 121a7bf into PaperMC:main Apr 14, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this from Awaiting final testing to Merged in Paper PR Queue Apr 14, 2025
@DerEchtePilz DerEchtePilz deleted the gamerule-accessiblity branch April 16, 2025 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

3 participants