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

Simplify FlagCondition #1713

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

Conversation

Technici4n
Copy link
Member

Simplification of #1712, coming after the fact since it was merged so quickly. 😉

@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Nov 27, 2024

  • Publish PR to GitHub Packages

Last commit published: fc5a7a94a4bc06f7e9af4104a62d4fc81fad5a1c.

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 #1713' // https://github.com/neoforged/NeoForge/pull/1713
        url 'https://prmaven.neoforged.net/NeoForge/pr1713'
        content {
            includeModule('net.neoforged', 'neoforge')
            includeModule('net.neoforged', 'testframework')
        }
    }
}

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-pr1713.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr1713
cd NeoForge-pr1713
curl -L https://prmaven.neoforged.net/NeoForge/pr1713/net/neoforged/neoforge/21.3.52-beta-pr-1713-cleanup-1712/mdk-pr1713.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.

@neoforged-compatibility-checks
Copy link

neoforged-compatibility-checks bot commented Nov 27, 2024

@Technici4n, 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: fc5a7a94a4bc06f7e9af4104a62d4fc81fad5a1c.

Compatibility checks

neoforge (:neoforge)

  • net/neoforged/neoforge/common/conditions/FlagCondition
    • ❗ API class no longer exists
  • net/neoforged/neoforge/common/conditions/IConditionBuilder
    • isFeatureEnabled(Lnet/minecraft/world/flag/FeatureFlag;)Lnet/neoforged/neoforge/common/conditions/ICondition;: ❗ API method was removed
    • isFeatureEnabled(Lnet/minecraft/world/flag/FeatureFlag;[Lnet/minecraft/world/flag/FeatureFlag;)Lnet/neoforged/neoforge/common/conditions/ICondition;: ❗ API method was removed
    • isFeatureDisabled(Lnet/minecraft/world/flag/FeatureFlag;[Lnet/minecraft/world/flag/FeatureFlag;)Lnet/neoforged/neoforge/common/conditions/ICondition;: ❗ API method was removed
    • isFeatureEnabled(Lnet/minecraft/world/flag/FeatureFlagSet;)Lnet/neoforged/neoforge/common/conditions/ICondition;: ❗ API method was removed
    • isFeatureDisabled(Lnet/minecraft/world/flag/FeatureFlagSet;)Lnet/neoforged/neoforge/common/conditions/ICondition;: ❗ API method was removed
    • isFeatureDisabled(Lnet/minecraft/world/flag/FeatureFlag;)Lnet/neoforged/neoforge/common/conditions/ICondition;: ❗ API method was removed
  • net/neoforged/neoforge/common/NeoForgeMod
    • FEATURE_FLAG_CONDITION:Lnet/neoforged/neoforge/registries/DeferredHolder;: ❗ API field was removed

@ApexModder ApexModder added cleanup Change that isn't an enhancement or a bug fix 1.21.3 Targeted at Minecraft 1.21.3 labels Nov 27, 2024
Comment on lines -53 to -70
public static ICondition isEnabled(FeatureFlag requiredFlag) {
return isEnabled(FeatureFlagSet.of(requiredFlag));
}

public static ICondition isEnabled(FeatureFlag requiredFlag, FeatureFlag... requiredFlags) {
return isEnabled(FeatureFlagSet.of(requiredFlag, requiredFlags));
}

public static ICondition isDisabled(FeatureFlagSet requiredFeatures) {
return new FlagCondition(requiredFeatures, false);
}

public static ICondition isDisabled(FeatureFlag requiredFlag) {
return isDisabled(FeatureFlagSet.of(requiredFlag));
}

public static ICondition isDisabled(FeatureFlag requiredFlag, FeatureFlag... requiredFlags) {
return isDisabled(FeatureFlagSet.of(requiredFlag, requiredFlags));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please retain these methods, I find them much better to read and understand then new NotCondition(FlagCondition.of(...)) and given that they return ICondition, the actual implementation does not matter

Copy link
Member

Choose a reason for hiding this comment

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

Creating the conditions manually is not the recommended way of creating them, using the builder is. The builder is simply not(...)

Copy link
Contributor

@ApexModder ApexModder Nov 27, 2024

Choose a reason for hiding this comment

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

even going that route not(featureFlags()) doesnt really explain what it does by simply reading the methods names, where as not(featureFlagsEnabled()) or not(isFeatureEnabled()) does.

and having nice simple utilities like isFeatureDisabled while sure can be fully implemented with not is still nice to have and makes overall code easier to read and understand.

Copy link
Member

Choose a reason for hiding this comment

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

I do agree with renaming the methods. However we don't have modIsntLoaded or itemDoesntExist or tagIsntEmpty or andNot or orNot utilities. Conditions are boolean composition and we would be bloating the api surface by introducing combinations instead of having people compose the condition exactly as it would be output in the json.

Comment on lines -51 to -68
default ICondition isFeatureEnabled(FeatureFlag requiredFlag) {
return FlagCondition.isEnabled(requiredFlag);
}

default ICondition isFeatureEnabled(FeatureFlag requiredFlag, FeatureFlag... requiredFlags) {
return FlagCondition.isEnabled(requiredFlag, requiredFlags);
}

default ICondition isFeatureDisabled(FeatureFlagSet requiredFeatures) {
return FlagCondition.isDisabled(requiredFeatures);
}

default ICondition isFeatureDisabled(FeatureFlag requiredFlag) {
return FlagCondition.isDisabled(requiredFlag);
}

default ICondition isFeatureDisabled(FeatureFlag requiredFlag, FeatureFlag... requiredFlags) {
return FlagCondition.isDisabled(requiredFlag, requiredFlags);
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment above

@Override
protected void buildRecipes() {
// recipe available when above flag is enabled
shapeless(RecipeCategory.MISC, Items.DIAMOND)
.requires(ItemTags.DIRT)
.unlockedBy("has_dirt", has(ItemTags.DIRT))
.save(output.withConditions(FlagCondition.isEnabled(flag)), enabledRecipeName);
.save(output.withConditions(featureFlagsEnabled(flag)), enabledRecipeName);

// recipe available when above flag is disabled
shapeless(RecipeCategory.MISC, Items.DIRT)
Copy link
Member

Choose a reason for hiding this comment

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

I would just remove this now.

Copy link
Contributor

@ApexModder ApexModder Nov 27, 2024

Choose a reason for hiding this comment

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

just to clarify i would remove the disabled flag test yeah, test linked is the enabled flag test
cant see why would want to remove both tests, good to keep a test to ensure it continues working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.3 Targeted at Minecraft 1.21.3 cleanup Change that isn't an enhancement or a bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants