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

[1.21.3] Encourage more usage of IConditionBuider #1716

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

Conversation

ApexModder
Copy link
Contributor

@ApexModder ApexModder commented Nov 28, 2024

This PR aims to encourage modders to make more use of IConditionBuilder rather than constructing condition instances themselves

this is done by

  • patching DataProviders which support conditions to now implement IConditionBuilder making all of its helpers freely available to all inheritors.
  • adding a static of method allowing users to construct an instance in places where they do not have a DataProvider or can implement it themselves.
  • deprecating and moving all shortcut constructors into ICondtionBuilder
  • deprecating the old TRUE/FALSE conditions in favor of the new always/never conditions

@ApexModder ApexModder added the 1.21.3 Targeted at Minecraft 1.21.3 label Nov 28, 2024
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Nov 28, 2024

  • Publish PR to GitHub Packages

Last commit published: e2da34f7dfabb3644c92149210097427b2ad9131.

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 #1716' // https://github.com/neoforged/NeoForge/pull/1716
        url 'https://prmaven.neoforged.net/NeoForge/pr1716'
        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-pr1716.
On Powershell you will need to remove the -L flag from the curl invocation.

mkdir NeoForge-pr1716
cd NeoForge-pr1716
curl -L https://prmaven.neoforged.net/NeoForge/pr1716/net/neoforged/neoforge/21.3.57-beta-pr-1716-pr-condition-builder/mdk-pr1716.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.

import org.slf4j.Logger;

public interface DataProvider {
-public interface DataProvider {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really want it in every data provider? Or should we be more selective and only implement it where we know it is usable?

Copy link
Contributor Author

@ApexModder ApexModder Nov 28, 2024

Choose a reason for hiding this comment

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

I remembered seeing this PR (#1315) and thought our condition system supported any data file now, but guess I my assumption on that was wrong as it was closed not merged.

I can go through and find all the providers which directly support conditions, rather than implementing onto DataProvider.

/**
* @deprecated Use {@link IConditionBuilder}
*/
@Deprecated(forRemoval = true, since = "1.12.3")
Copy link
Member

Choose a reason for hiding this comment

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

1.12.3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, should be fixed now

@@ -46,8 +45,8 @@ static void conditionalDatapackEntries(final DynamicTest test, final Registratio
event.getLookupProvider(),
builder,
conditions -> {
conditions.accept(CONDITIONAL_FALSE_DAMAGE_TYPE, FalseCondition.INSTANCE);
conditions.accept(CONDITIONAL_TRUE_DAMAGE_TYPE, TrueCondition.INSTANCE);
conditions.accept(CONDITIONAL_FALSE_DAMAGE_TYPE, IConditionBuilder.of().never());
Copy link
Member

Choose a reason for hiding this comment

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

Makes me wonder if static methods in the builder would work instead. 🤔

Copy link
Contributor Author

@ApexModder ApexModder Nov 28, 2024

Choose a reason for hiding this comment

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

I was thinking that too, but that would have to wait until 21.4
Since afaik cant make static versions cause the method signature will conflict the the default ones.

@@ -17,14 +19,32 @@ default ICondition and(ICondition... values) {
return new AndCondition(List.of(values));
}

default ICondition FALSE() {
default ICondition never() {
// TODO: Maybe also rename class and registry entry to 'never' as well
Copy link
Member

Choose a reason for hiding this comment

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

This kind of TODO will get forgotten and come back to haunt us in a few years. :P

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deprecated the old TRUE/FALSE in favor of newly added always/never conditions

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants