Add `neoforge:alternatives` to conditional codecs
This PR adds a neoforge:alternatives list to conditional codecs, that will try to find an alternative to load by checking the conditions of each one, in order and if they match return the object.
To achieve that the WithConditions record has been made into a sealed class, and a new ConditionalObject children has been added. When a ConditionalObject is detected at the root, the encoder will write its alternatives.
Only the root object can have alternatives, and an alternative cannot be of the type ConditionalObject.
- [x] Publish PR to GitHub Packages
Last commit published: da6fa9993c52f50fe2092004a1b7571da67c6a2a.
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 #436' // https://github.com/neoforged/NeoForge/pull/436
url 'https://prmaven.neoforged.net/NeoForge/pr436'
content {
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-pr436.
On Powershell you will need to remove the -L flag from the curl invocation.
mkdir NeoForge-pr436
cd NeoForge-pr436
curl -L https://prmaven.neoforged.net/NeoForge/pr436/net/neoforged/neoforge/20.4.69-beta-pr-436-condcodec-alternatives/mdk-pr436.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.
The datagen is grossly implemented, and we need to make sure the format makes sense as well.
With respect to the datagen: do you mean the api surface or the actual inner implementation that is hidden from the modder?
To be clear on the behavior, if the root object fails it's conditions, then each alternative is tried one at a time until an object passes, otherwise the object is skipped entirely? In other words, alternatives is strictly a fallback, it's never considered first?
The one functionally conditional recipes had that this lacks is the ability to apply a condition to all alternatives, as before the outer condition skipped the entire loader while the inner one skipped the alternative in favor of the next. Not sure this is needed functionally, just a difference in behavior that stood out.
Also worth asking, what happens if alternatives is present when condition is absent? I assume alternatives would do nothing, may be worth making that a parsing error.
To be clear on the behavior, if the root object fails it's conditions, then each alternative is tried one at a time until an object passes, otherwise the object is skipped entirely? In other words, alternatives is strictly a fallback, it's never considered first?
That's correct. And yes, when there's no condition in the outer alternatives will not be considered, so maybe it should be an error indeed.
@Matyrobbrt, do you still intend on updating this PR to 1.21 and resolving the outstanding requested changes?
I don't plan to continue this PR for the foreseeable future, especially since the implementation is tricky in a generic fashion.