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.next] Modded feature flag #1322

Closed
wants to merge 26 commits into from

Conversation

ApexModder
Copy link
Contributor

@ApexModder ApexModder commented Jul 16, 2024

This PR introduces a custom flag system for marking elements as locked behind a set of required flags.

Although vanilla provides a FeatureFlag system, modders should not use it in its current state. This PR offers a similar system specifically for modders.

To use this system, a registry element must implement FlagElement and provide a set of required flags via the requiredFlags method. All vanilla feature elements have been patched to support this new flag system directly. For example, Items and Blocks can be assigned a set of flags during registration through their Properties objects.

To check if a given flag is enabled, you need an instance of FlagManager, which can be obtained via a MinecraftServer instance. The isEnabled method of feature elements has been patched to check if their respective flags are enabled.

All currently enabled flags are appended to crash reports, making it easy for modders to know which crashes are potentially caused by flagged elements and which are not

All flags are disabled by default. To enable a flag, a server admin must use the command /neoforge flag enable <flag>.

A new ICondition has been implemented (RequiredFlagsCondition), which allows marking data files as requiring a set of flags.
Due to when flags are loaded and how they are currently toggled, after setting a flags state a /reload will be required to reload the data files with the correct flag states.

Example mod - This mod registers a new Block and Item to the game, which are both locked behind a new modded flag flag_example_mod:experimental.


TODO

  • Enable flags via data packs

@ApexModder ApexModder added enhancement New (or improvement to existing) feature or request request for comments For gathering opinions on some topic or subject 1.21.1 Targeted at Minecraft 1.21.1 labels Jul 16, 2024
@neoforged-pr-publishing
Copy link

neoforged-pr-publishing bot commented Jul 16, 2024

  • Publish PR to GitHub Packages

Last commit published: 4489345c5b2af213e7763a5ce28427b43a34284b.

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

mkdir NeoForge-pr1322
cd NeoForge-pr1322
curl -L https://prmaven.neoforged.net/NeoForge/pr1322/net/neoforged/neoforge/21.0.188-pr-1322-pr-modded-flags/mdk-pr1322.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 Jul 16, 2024

@ApexModder, this PR introduces breaking changes.
Unfortunately, this project is not accepting breaking changes right now.
Please revert them before this PR can be merged.
Last checked commit: 4489345c5b2af213e7763a5ce28427b43a34284b.

Compatibility checks

neoforge (:neoforge)

  • net/neoforged/neoforge/common/extensions/IMenuTypeExtension
    • create(Lnet/neoforged/neoforge/network/IContainerFactory;)Lnet/minecraft/world/inventory/MenuType;: ❗ API method was removed
  • net/neoforged/neoforge/client/extensions/IMinecraftExtension
    • getModdedFlagManager()Lnet/neoforged/neoforge/flag/FlagManager;: ❗ Method was made abstract
  • net/minecraft/world/inventory/MenuType
    • <init>(Lnet/minecraft/world/inventory/MenuType$MenuSupplier;Lnet/minecraft/world/flag/FeatureFlagSet;)V: ❗ API method was removed
  • net/neoforged/neoforge/common/extensions/ILevelReaderExtension
    • getModdedFlagManager()Lnet/neoforged/neoforge/flag/FlagManager;: ❗ Method was made abstract
  • net/minecraft/world/entity/EntityType
    • <init>(Lnet/minecraft/world/entity/EntityType$EntityFactory;Lnet/minecraft/world/entity/MobCategory;ZZZZLcom/google/common/collect/ImmutableSet;Lnet/minecraft/world/entity/EntityDimensions;FIILnet/minecraft/world/flag/FeatureFlagSet;Ljava/util/function/Predicate;Ljava/util/function/ToIntFunction;Ljava/util/function/ToIntFunction;)V: ❗ API method was removed

@ApexModder ApexModder added the breaking change Breaks binary compatibility label Jul 16, 2024
@ApexModder ApexModder changed the title [1.21.next] Modded feature flag - Proof of concept [1.21.next] Modded feature flag Aug 3, 2024
@neoforged-automation
Copy link

@ApexModder, this pull request has conflicts, please resolve them for this PR to move forward.

@neoforged-automation
Copy link

@ApexModder, this pull request has conflicts, please resolve them for this PR to move forward.

shartte and others added 10 commits August 8, 2024 18:23
Add coloring to flag list command

Remove ability to mark flags as enabled by default
GameTest validates the following
- flag can be enabled and disabled
- all flagged elements match the expected enabled state

register flagged block & entity type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21.1 Targeted at Minecraft 1.21.1 breaking change Breaks binary compatibility enhancement New (or improvement to existing) feature or request request for comments For gathering opinions on some topic or subject
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants