-
-
Notifications
You must be signed in to change notification settings - Fork 138
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] Add Experimental FeatureFlag #1167
Open
ApexModder
wants to merge
10
commits into
neoforged:1.21.x
Choose a base branch
from
ApexModder:pr/experiment-flag
base: 1.21.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d7876e
Fix data provider merge issue
ApexModder 04fba14
Add helper for generating mod builtin packs
ApexModder 2f3ee07
Initial implementation
ApexModder c767412
Clean up packfinder code
ApexModder 2ca5e54
Add data provider for experiments DP
ApexModder b3e254d
Add documentation to FeatureFlags.MOD_EXPERIMENTAL
ApexModder 6a03141
Update en_us.json
ApexModder 5f08bf8
Clean up data gen code
ApexModder 9f78110
Fix pack position
ApexModder d2b5348
Add simple test mods
ApexModder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- a/net/minecraft/world/flag/FeatureFlags.java | ||
+++ b/net/minecraft/world/flag/FeatureFlags.java | ||
@@ -13,6 +_,20 @@ | ||
public static final Codec<FeatureFlagSet> CODEC; | ||
public static final FeatureFlagSet VANILLA_SET; | ||
public static final FeatureFlagSet DEFAULT_FLAGS; | ||
+ /** | ||
+ * A <b>feature flag</b> for use with experimental features that may introduce unexpected or potentially bug-inducing behaviors.<br> | ||
+ * Unlike the standard set of flags, which can change frequently, this flag remains consistent across major version updates.<br> | ||
+ * <br><p> | ||
+ * Modders can reference this flag during built-in feature registration.<br> | ||
+ * However, they must provide their own flagged datapacks to associate datapack features (such as recipes and enchantments) with this flag.<br> | ||
+ * These datapacks can be provided either as optional files or via the {@linkplain net.neoforged.neoforge.event.AddPackFindersEvent} event. | ||
+ * </p> | ||
+ * <br><p> | ||
+ * It is highly recommended that modders document which features are experimental and which ones are not.<br> | ||
+ * Due to the nature of this flag being a <i>‘catch-all’</i>, it enables any and all modded experiments that may exist. | ||
+ * </p> | ||
+ */ | ||
+ public static final FeatureFlag MOD_EXPERIMENTAL; | ||
|
||
public static String printMissingFlags(FeatureFlagSet p_250581_, FeatureFlagSet p_250326_) { | ||
return printMissingFlags(REGISTRY, p_250581_, p_250326_); | ||
@@ -33,6 +_,7 @@ | ||
VANILLA = featureflagregistry$builder.createVanilla("vanilla"); | ||
BUNDLE = featureflagregistry$builder.createVanilla("bundle"); | ||
TRADE_REBALANCE = featureflagregistry$builder.createVanilla("trade_rebalance"); | ||
+ MOD_EXPERIMENTAL = featureflagregistry$builder.create(ResourceLocation.fromNamespaceAndPath("neoforge", "mod_experimental")); | ||
REGISTRY = featureflagregistry$builder.build(); | ||
CODEC = REGISTRY.codec(); | ||
VANILLA_SET = FeatureFlagSet.of(VANILLA); |
17 changes: 17 additions & 0 deletions
17
src/generated/resources/data/neoforge/datapacks/mod_experimental/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"features": { | ||
"enabled": [ | ||
"neoforge:mod_experimental" | ||
] | ||
}, | ||
"pack": { | ||
"description": { | ||
"translate": "pack.neoforge.experimental.description" | ||
}, | ||
"pack_format": 48, | ||
"supported_formats": [ | ||
0, | ||
2147483647 | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...res/data/neotests_experimental_tests_moda/advancement/recipes/misc/diamond_from_dirt.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"parent": "minecraft:recipes/root", | ||
"criteria": { | ||
"has_dirt": { | ||
"conditions": { | ||
"items": [ | ||
{ | ||
"items": "minecraft:dirt" | ||
} | ||
] | ||
}, | ||
"trigger": "minecraft:inventory_changed" | ||
}, | ||
"has_the_recipe": { | ||
"conditions": { | ||
"recipe": "neotests_experimental_tests_moda:diamond_from_dirt" | ||
}, | ||
"trigger": "minecraft:recipe_unlocked" | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"has_the_recipe", | ||
"has_dirt" | ||
] | ||
], | ||
"rewards": { | ||
"recipes": [ | ||
"neotests_experimental_tests_moda:diamond_from_dirt" | ||
] | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...experimental_features/data/neotests_experimental_tests_moda/recipe/diamond_from_dirt.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"type": "minecraft:crafting_shapeless", | ||
"category": "misc", | ||
"group": "experimental", | ||
"ingredients": [ | ||
{ | ||
"item": "minecraft:dirt" | ||
} | ||
], | ||
"result": { | ||
"count": 1, | ||
"id": "minecraft:diamond" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...sources/data/neotests_experimental_tests_moda/datapacks/experimental_features/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"features": { | ||
"enabled": [ | ||
"neoforge:mod_experimental" | ||
] | ||
}, | ||
"pack": { | ||
"description": "Enables experimental features (neotests_experimental_tests_moda)", | ||
"pack_format": 48 | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...res/data/neotests_experimental_tests_modb/advancement/recipes/misc/dirt_from_diamond.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"parent": "minecraft:recipes/root", | ||
"criteria": { | ||
"has_diamond": { | ||
"conditions": { | ||
"items": [ | ||
{ | ||
"items": "#c:gems/diamond" | ||
} | ||
] | ||
}, | ||
"trigger": "minecraft:inventory_changed" | ||
}, | ||
"has_the_recipe": { | ||
"conditions": { | ||
"recipe": "neotests_experimental_tests_modb:dirt_from_diamond" | ||
}, | ||
"trigger": "minecraft:recipe_unlocked" | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"has_the_recipe", | ||
"has_diamond" | ||
] | ||
], | ||
"rewards": { | ||
"recipes": [ | ||
"neotests_experimental_tests_modb:dirt_from_diamond" | ||
] | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...experimental_features/data/neotests_experimental_tests_modb/recipe/dirt_from_diamond.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"type": "minecraft:crafting_shapeless", | ||
"category": "misc", | ||
"group": "experimental", | ||
"ingredients": [ | ||
{ | ||
"tag": "c:gems/diamond" | ||
} | ||
], | ||
"result": { | ||
"count": 1, | ||
"id": "minecraft:dirt" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...sources/data/neotests_experimental_tests_modb/datapacks/experimental_features/pack.mcmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"features": { | ||
"enabled": [ | ||
"neoforge:mod_experimental" | ||
] | ||
}, | ||
"pack": { | ||
"description": "Enables experimental features (neotests_experimental_tests_modb)", | ||
"pack_format": 48 | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
tests/src/main/java/net/neoforged/neoforge/debug/resources/ExperimentalTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.debug.resources; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.UnaryOperator; | ||
import net.minecraft.core.HolderLookup; | ||
import net.minecraft.data.DataGenerator; | ||
import net.minecraft.data.metadata.PackMetadataGenerator; | ||
import net.minecraft.data.recipes.RecipeCategory; | ||
import net.minecraft.data.recipes.RecipeOutput; | ||
import net.minecraft.data.recipes.RecipeProvider; | ||
import net.minecraft.data.recipes.ShapelessRecipeBuilder; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.packs.PackType; | ||
import net.minecraft.server.packs.repository.Pack; | ||
import net.minecraft.server.packs.repository.PackSource; | ||
import net.minecraft.world.flag.FeatureFlagSet; | ||
import net.minecraft.world.flag.FeatureFlags; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.Items; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
import net.neoforged.neoforge.common.Tags; | ||
import net.neoforged.neoforge.data.event.GatherDataEvent; | ||
import net.neoforged.neoforge.event.AddPackFindersEvent; | ||
import net.neoforged.testframework.DynamicTest; | ||
import net.neoforged.testframework.annotation.ForEachTest; | ||
import net.neoforged.testframework.annotation.TestHolder; | ||
import org.apache.commons.lang3.function.TriConsumer; | ||
|
||
@ForEachTest | ||
public final class ExperimentalTests { | ||
@TestHolder(value = "experimental_tests_base", description = "Test providing experimental items and blocks") | ||
private static void baseMod(DynamicTest test) { | ||
var registration = test.registrationHelper(); | ||
var items = registration.items(); | ||
|
||
items.registerSimpleItem("experimental_item", new Item.Properties().requiredFeatures(FeatureFlags.MOD_EXPERIMENTAL)); | ||
|
||
var block = registration.blocks().registerSimpleBlock("experimental_block", BlockBehaviour.Properties.ofFullCopy(Blocks.STONE).requiredFeatures(FeatureFlags.MOD_EXPERIMENTAL)); | ||
items.registerSimpleBlockItem(block); | ||
} | ||
|
||
@TestHolder(value = "experimental_tests_moda", description = "Test providing experimental feature pack (dirt -> diamond recipe)") | ||
private static void modA(DynamicTest test) { | ||
commonMod(test, (event, pack, lookupProvider) -> pack.addProvider(output -> new RecipeProvider(output, lookupProvider) { | ||
@Override | ||
protected void buildRecipes(RecipeOutput output) { | ||
// recipe for dirt -> diamond enabled when MOD_EXPERIMENTAL is enabled | ||
ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, Items.DIAMOND) | ||
.requires(Items.DIRT) | ||
.unlockedBy("has_dirt", has(Items.DIRT)) | ||
.group("experimental") | ||
.save(output, ResourceLocation.fromNamespaceAndPath(test.createModId(), "diamond_from_dirt")); | ||
} | ||
})); | ||
} | ||
|
||
@TestHolder(value = "experimental_tests_modb", description = "Test providing experimental feature pack (diamond -> dirt recipe)") | ||
private static void modB(DynamicTest test) { | ||
commonMod(test, (event, pack, lookupProvider) -> pack.addProvider(output -> new RecipeProvider(output, lookupProvider) { | ||
@Override | ||
protected void buildRecipes(RecipeOutput output) { | ||
// recipe for diamond -> dirt enabled when MOD_EXPERIMENTAL is enabled | ||
ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, Items.DIRT) | ||
.requires(Tags.Items.GEMS_DIAMOND) | ||
.unlockedBy("has_diamond", has(Tags.Items.GEMS_DIAMOND)) | ||
.group("experimental") | ||
.save(output, ResourceLocation.fromNamespaceAndPath(test.createModId(), "dirt_from_diamond")); | ||
} | ||
})); | ||
} | ||
|
||
private static void commonMod(DynamicTest test, TriConsumer<DataGenerator, DataGenerator.PackGenerator, CompletableFuture<HolderLookup.Provider>> gatherData) { | ||
var packName = "experimental_features"; | ||
var modBus = test.framework().modEventBus(); | ||
var modId = test.createModId(); | ||
|
||
// register pack finder for experimental features pack | ||
modBus.addListener(AddPackFindersEvent.class, event -> event.addPackFinders( | ||
ResourceLocation.fromNamespaceAndPath("neotests", "data/" + modId + "/datapacks/" + packName), | ||
PackType.SERVER_DATA, | ||
Component.literal("Experimental Features (" + modId + ")"), | ||
PackSource.create(UnaryOperator.identity(), false), | ||
false, | ||
Pack.Position.BOTTOM)); | ||
|
||
modBus.addListener(GatherDataEvent.class, event -> { | ||
var generator = event.getGenerator(); | ||
var pack = generator.getBuiltinDatapack(event.includeServer(), modId, packName); | ||
// generate pack metadata for experimental features pack | ||
pack.addProvider(output -> PackMetadataGenerator.forFeaturePack(output, Component.literal("Enables experimental features (" + modId + ")"), FeatureFlagSet.of(FeatureFlags.MOD_EXPERIMENTAL))); | ||
// generate any additional data for this pack | ||
gatherData.accept(generator, pack, event.getLookupProvider()); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs javadoc on what the flag is for, and how modders should actually use it -- notably, they have to register their own pack using it in
AddPackFindersEvent
, which isn't necessarily obvious!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Java docs have been added stating what this flag is, how and when to use it, and stating that it is recommended that modders document their experimental features somewhere.