Skip to content

Commit 8cf4d40

Browse files
committed
docs: update docs to new codec based data loading api
1 parent 6ce8015 commit 8cf4d40

3 files changed

Lines changed: 110 additions & 50 deletions

File tree

versioned_docs/version-26.1.2/advanced/custom-conditions.md

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,86 @@ sidebar_position: 40
66

77
Mods can add custom conditions that can be used to lock entries or categories. To this end you need to:
88

9-
1. Create ResourceLocation for the new condition (e.g. "mymod:my_condition")
10-
2. Create a custom condition class
11-
3. Register the custom condition
9+
1. Create a `ResourceLocation` ID for the new condition (e.g. `mymod:my_condition`)
10+
2. Create a custom condition class with `ID`, `CODEC`, and `STREAM_CODEC`
11+
3. Register the condition via a dedicated registry class
1212
4. For datagen: create a condition model class
1313
5. Finally use the condition in your book
1414

1515
:::tip
1616

17-
The ResourceLocation is what you will use in your entries and categories to gate them behind your custom condition.
17+
The `ResourceLocation` is what you will use in your entries and categories to gate them behind your custom condition.
1818

1919
:::
2020

2121
## Condition Class
2222

23-
Conditions need to extend `BookCondition` in the package `com.klikli_dev.modonomicon.book.conditions`.
24-
In addition to implementing the interface methods that your IDE will suggest you need two static methods `fromJson` and `fromNetwork` which you will need when registering the condition.
23+
Conditions need to extend `BookCondition` in the package `com.klikli_dev.modonomicon.book.conditions`.
2524

26-
in `getType()` return your ResourceLocation.
25+
Each condition class must declare three static fields:
2726

28-
See https://github.com/klikli-dev/modonomicon/blob/-/common/src/main/java/com/klikli_dev/modonomicon/book/conditions/BookAdvancementCondition.java for an example condition.
27+
- `ID` — a `ResourceLocation` (use `Modonomicon.loc(...)` or `new ResourceLocation("mymod", "my_condition")`)
28+
- `CODEC` — a `MapCodec<T>` for JSON deserialization, typically built with `RecordCodecBuilder.mapCodec(...)`
29+
- `STREAM_CODEC` — a `StreamCodec<RegistryFriendlyByteBuf, T>` for network serialization, typically built with `StreamCodec.composite(...)`
30+
31+
You must also override `type()` to return the corresponding `BookConditionType<T>` from your registry class.
32+
33+
See these example conditions for reference:
34+
- [`BookModLoadedCondition`](https://github.com/klikli-dev/modonomicon/blob/-/common/src/main/java/com/klikli_dev/modonomicon/book/conditions/BookModLoadedCondition.java)
35+
- [`BookFalseCondition`](https://github.com/klikli-dev/modonomicon/blob/-/common/src/main/java/com/klikli_dev/modonomicon/book/conditions/BookFalseCondition.java)
36+
- [`BookResearchNodeUnlockedCondition`](https://github.com/klikli-dev/modonomicon/blob/-/common/src/main/java/com/klikli_dev/modonomicon/book/conditions/BookResearchNodeUnlockedCondition.java)
2937

3038
## Condition Registration
3139

32-
To register the condition call LoaderRegistry.registerConditionLoader(...).
33-
For the BookAdvancementCondition this call looks as follows: `registerConditionLoader(Condition.ADVANCEMENT, BookAdvancementCondition::fromJson, BookAdvancementCondition::fromNetwork);`
40+
Create a dedicated registry class to hold your condition registrations. Use `public static final` fields initialized via `BookConditionTypeRegistry.register(...)`, and provide an empty `bootstrap()` method to trigger class loading:
41+
42+
```java
43+
public final class MyModModonomiconConditionRegistry {
44+
45+
public static final BookConditionType<BookMyCustomCondition> MY_CUSTOM =
46+
BookConditionTypeRegistry.register(
47+
BookMyCustomCondition.ID,
48+
BookMyCustomCondition.CODEC,
49+
BookMyCustomCondition.STREAM_CODEC
50+
);
51+
52+
private MyModModonomiconConditionRegistry() {
53+
}
54+
55+
public static void bootstrap() {
56+
}
57+
}
58+
```
3459

35-
This needs to be called from both the client and server side mod initialization.
36-
In Fabric: Call in `onInitialize` in your `ModInitializer`.
37-
In (Neo)Forge: Call in `onCommonSetup` (your `FMLCommonSetupEvent` handler).
60+
Then call `bootstrap()` during `FMLCommonSetupEvent` (NeoForge) or your `ModInitializer.onInitialize` (Fabric):
61+
62+
```java
63+
// NeoForge
64+
public void onCommonSetup(FMLCommonSetupEvent event) {
65+
MyModModonomiconConditionRegistry.bootstrap();
66+
}
67+
68+
// Fabric
69+
@Override
70+
public void onInitialize() {
71+
MyModModonomiconConditionRegistry.bootstrap();
72+
}
73+
```
3874

3975
## Condition Datagen Model
4076

41-
The model class helps you to generate the condition json files via DataGen.
77+
The model class helps you to generate the condition JSON files via DataGen.
4278

43-
See https://github.com/klikli-dev/modonomicon/blob/2a067357bacaf3e15a5f490520a4headaf64807fe83e/common/src/main/java/com/klikli_dev/modonomicon/api/datagen/book/condition/BookAdvancementConditionModel.java for a reference model class.
79+
Extend `BookConditionModel<T>` and override `toBookCondition(HolderLookup.Provider)` to return the runtime condition instance. Pass the condition's `ID` to the `super(...)` constructor.
4480

45-
(On 1.20.1 it looks a bit more complicated:
46-
https://github.com/klikli-dev/modonomicon/blob/bdf639c835908393198f695999c70f2ac53e154c/common/src/main/java/com/klikli_dev/modonomicon/api/datagen/book/condition/BookAdvancementConditionModel.java )
81+
See these example models for reference:
82+
- [`BookModLoadedConditionModel`](https://github.com/klikli-dev/modonomicon/blob/-/common/src/main/java/com/klikli_dev/modonomicon/api/datagen/book/condition/BookModLoadedConditionModel.java)
83+
- [`BookFalseConditionModel`](https://github.com/klikli-dev/modonomicon/blob/-/common/src/main/java/com/klikli_dev/modonomicon/api/datagen/book/condition/BookFalseConditionModel.java)
84+
- [`BookResearchNodeUnlockedConditionModel`](https://github.com/klikli-dev/modonomicon/blob/-/common/src/main/java/com/klikli_dev/modonomicon/api/datagen/book/condition/BookResearchNodeUnlockedConditionModel.java)
4785

48-
:::tip
86+
:::tip
4987
You need not register the model.
50-
:::
88+
:::
5189

5290
## Usage
5391

@@ -61,6 +99,6 @@ On your entry or category, add:
6199
},
62100
...
63101
}
64-
```
102+
```
65103

66104
See also [Unlock Conditions](../basics/unlock-conditions) for more information on how to use conditions.

versioned_docs/version-26.1.2/basics/formatting.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,12 @@ Macro instructions (ab)use the link syntax as follows: to start a macro use `[{}
260260
[{}](my.dynamic.key) could be replaced to show a config value!
261261
```
262262

263-
To register that macro call the following code during server setup:
263+
To register that macro call the following code during `FMLCommonSetupEvent` (NeoForge) or your `ModInitializer.onInitialize` (Fabric):
264264

265265
```java
266-
LoaderRegistry.registerDynamicTextMacroLoader(<my-book-id>, () -> {
267-
return Map.of(
268-
"my.dynamic.key", MyConfig.SOME_VALUE.get()
269-
);
270-
});
266+
DynamicTextMacroRegistry.register(myBookId, () -> Map.of(
267+
"my.dynamic.key", MyConfig.SOME_VALUE.get()
268+
));
271269
```
272270

273271
:::info

versioned_docs/version-26.1.2/multiblocks/state-matchers/predicate-matcher.md

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@ sidebar_position: 50
44

55
# Predicate Matchers
66

7-
# Tag Matcher
8-
97
**Type:** `modonomicon:predicate`
108

11-
Predicate matchers can use advanced logic to match blocks. The matching logic must be provided as Java Code and registerd with a Resource Location ID.
12-
Tag matchers will check if the placed block is part of the provided tag. Additionally BlockState properties can be provided to match against, in that case the matcher will only match if the block is in the tag, and has the provided properties.
9+
Predicate matchers can use advanced logic to match blocks. The matching logic must be provided as Java code and registered with a `ResourceLocation` ID.
1310

1411
## Attributes
1512

1613
### **predicate** (ResourceLocation, _mandatory_)
17-
14+
1815
The ID of the predicate to use for the matcher.
1916

20-
### **display** (BlockState, _mandatory_)
21-
22-
The block to display in the multiblock preview.
17+
### **display** (BlockState, _optional_)
18+
19+
The block to display in the multiblock preview.
2320

2421
:::info
2522

@@ -29,33 +26,54 @@ Tag matchers will check if the placed block is part of the provided tag. Additio
2926

3027
### **counts_towards_total_blocks** (boolean, _optional_, default: `true`)
3128

32-
If set to `false` the block will not count towards the total number of blocks required to complete the multiblock.
29+
If set to `false` the block will not count towards the total number of blocks required to complete the multiblock.
3330
E.g. for the `modonomicon:air` predicate you would set this to `false`.
3431
If set to `true` the block will count towards the total number of blocks required to complete the multiblock, which in the case of air and air-like blocks would lead to an insane number of blocks shown as still required to complete.
3532

3633
## Registering Predicates
3734

38-
Predicates are registered in the `FMLCommonSetupEvent`:
35+
Create a dedicated registry class and register your predicates via `PredicateRegistry.register(...)`:
3936

40-
```java
41-
public void onCommonSetup(FMLCommonSetupEvent event) {
42-
LoaderRegistry.registerPredicate(new ResourceLocation("modonomicon:air"), (getter, pos, state) -> state.isAir());
37+
```java
38+
public final class MyModModonomiconPredicateRegistry {
39+
40+
public static final PredicateType MY_PREDICATE = PredicateRegistry.register(
41+
new ResourceLocation("mymod", "my_predicate"),
42+
(getter, pos, state) -> state.isSolid() && pos.getY() > 64
43+
);
44+
45+
private MyModModonomiconPredicateRegistry() {
46+
}
47+
48+
public static void bootstrap() {
49+
}
4350
}
4451
```
4552

46-
You can of course define any predicate you like that fits a
47-
```java
48-
TriPredicate<BlockGetter, BlockPos, BlockState>
53+
The predicate lambda must match the `TriPredicate<BlockGetter, BlockPos, BlockState>` signature.
54+
55+
Then call `bootstrap()` during `FMLCommonSetupEvent` (NeoForge) or your `ModInitializer.onInitialize` (Fabric):
56+
57+
```java
58+
// NeoForge
59+
public void onCommonSetup(FMLCommonSetupEvent event) {
60+
MyModModonomiconPredicateRegistry.bootstrap();
61+
}
62+
63+
// Fabric
64+
@Override
65+
public void onInitialize() {
66+
MyModModonomiconPredicateRegistry.bootstrap();
67+
}
4968
```
50-
:::caution
5169

52-
To access the `LoaderRegistry` you need to define a dependency on the full modonomicon jar in your `build.gralde` (See **[Maven Dependencies](../../getting-started/maven-dependencies)**)
53-
If you then call `LoaderRegistry.registerPredicate` in your `FMLCommonSetupEvent` like above you effectively create a hard dependency on Modonomicon.
54-
You can avoid this by calling `LoaderRegistry.registerPredicate` in a separate class, and only call that classes Methods if Modonomicon is loaded.
70+
:::caution
71+
72+
To access `PredicateRegistry` you need to define a dependency on the full modonomicon jar in your `build.gradle` (See **[Maven Dependencies](../../getting-started/maven-dependencies)**).
5573

56-
:::
74+
If you then call `PredicateRegistry.register(...)` directly you effectively create a hard dependency on Modonomicon. You can avoid this by calling `PredicateRegistry.register(...)` in a separate class, and only calling that class's methods if Modonomicon is loaded.
5775

58-
<!-- TODO: Link to an article that explains in detail how to guard against no class def -->
76+
:::
5977

6078
## Builtin Predicates
6179

@@ -65,14 +83,20 @@ You can avoid this by calling `LoaderRegistry.registerPredicate` in a separate c
6583

6684
Matches air blocks. Requires players to remove any blocks in the location of this matcher.
6785

86+
### Non-Solid Predicate
87+
88+
**Predicate ID:** `modonomicon:non_solid`
89+
90+
Matches blocks that are not solid.
91+
6892
## Usage Examples
6993

70-
Match air predicate and display .. nothing
94+
Match air predicate and display nothing:
7195

7296
```json
7397
{
7498
"type": "modonomicon:predicate",
7599
"predicate": "modonomicon:air",
76100
"display": "minecraft:air"
77101
}
78-
```
102+
```

0 commit comments

Comments
 (0)