Skip to content

Commit

Permalink
Lower case Feature Flags and add newline before code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ApexModder committed Nov 14, 2024
1 parent 416361d commit 5db5bb9
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions docs/advanced/featureflags.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ A common use case would be gating experimental features/elements behind a experi

### Creating a Feature Flag

To create new Feature Flags, a JSON file needs to be created and referenced in your `neoforge.mods.toml` file with the `featureFlags` entry inside of your `[[mods]]` block. The specified path must be relative to the `resources` directory:
To create new Feature flags, a JSON file needs to be created and referenced in your `neoforge.mods.toml` file with the `featureFlags` entry inside of your `[[mods]]` block. The specified path must be relative to the `resources` directory:

```toml
# In neoforge.mods.toml:
[[mods]]
Expand All @@ -15,22 +16,23 @@ To create new Feature Flags, a JSON file needs to be created and referenced in y
featureFlags="feature_flags.json"
```

The definition of the entry consists of a list of Feature Flag names, which will be loaded and registered during game initialization.
The definition of the entry consists of a list of Feature flag names, which will be loaded and registered during game initialization.

```json5
{
"flags": [
// Identifier of a Feature Flag to be registered
// Identifier of a Feature flag to be registered
"examplemod:experimental"
]
}
```

### Retrieving the Feature Flag
### Retrieving the Feature flag

The registered Feature Flag can be retrieved via `FeatureFlagRegistry.getFlag(ResourceLocation)`. This can be done at any time during your mod's initialization and is recommended to be stored somewhere for future use, rather than looking up the registry each time you require your flag.
The registered Feature flag can be retrieved via `FeatureFlagRegistry.getFlag(ResourceLocation)`. This can be done at any time during your mod's initialization and is recommended to be stored somewhere for future use, rather than looking up the registry each time you require your flag.

```java
// Look up the 'examplemod:experimental' Feature Flag
// Look up the 'examplemod:experimental' Feature flag
public static final FeatureFlag EXPERIMENTAL = FeatureFlags.REGISTRY.getFlag(ResourceLocation.fromNamespaceAndPath("examplemod", "experimental"));
```

Expand All @@ -51,7 +53,7 @@ The following is a complete list of all registries which directly implement the

#### Flagging elements

In order to flag a given `FeatureElement` as requiring your Feature Flag, you simply pass it and any other desired flags into the respective registration method:
In order to flag a given `FeatureElement` as requiring your Feature flag, you simply pass it and any other desired flags into the respective registration method:

- `Item`: `Item.Properties#requiredFeatures`
- `Block`: `BlockBehaviour.Properties#requiredFeatures`
Expand Down Expand Up @@ -148,11 +150,12 @@ itemStack.isItemEnabled(enabledFeatures);
_See also: [Resource Packs](../resources/index.md#assets), [Data Packs](../resources/index.md#data) and [Pack.mcmeta](../resources/index.md#packmcmeta)_

Feature packs are a type of pack that not only loads resources and/or data, but also has the ability to toggle on a given set of feature flags. These flags are defined in the `pack.mcmeta` JSON file at the root of this pack, which follows the below format:

```json5
{
"features": [
"enabled": [
// Identifier of a Feature Flag to be enabled
// Identifier of a Feature flag to be enabled
// Must be a valid registered flag
"examplemod:experimental"
]
Expand All @@ -165,6 +168,7 @@ There are a couple of ways for users to obtain a feature pack, namely installing
**Built-In**

Built-in packs are bundled with your mod and are made available to the game using the `AddPackFindersEvent` event.

```java
@SubscribeEvent
public static void addFeaturePacks(final AddPackFindersEvent event) {
Expand Down Expand Up @@ -263,7 +267,7 @@ public static void gatherData(final GatherDataEvent event) {
// Description displayed in the Experiments screen
Component.literal("Enabled experimental features for ExampleMod"),
// Set of Feature Flags this pack should enable
// Set of Feature flags this pack should enable
FeatureFlagSet.of(EXPERIMENTAL)
));
Expand Down

1 comment on commit 5db5bb9

@neoforged-pages-deployments
Copy link

Choose a reason for hiding this comment

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

Deploying with Cloudflare Pages

Name Result
Last commit: 5db5bb9ff55b17513f203c890a0fe2cebd49e609
Status: ✅ Deploy successful!
Preview URL: https://37e3b9bc.neoforged-docs-previews.pages.dev
PR Preview URL: https://pr-184.neoforged-docs-previews.pages.dev

Please sign in to comment.