You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: versioned_docs/version-26.1.2/advanced/custom-conditions.md
+58-20Lines changed: 58 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,48 +6,86 @@ sidebar_position: 40
6
6
7
7
Mods can add custom conditions that can be used to lock entries or categories. To this end you need to:
8
8
9
-
1. Create ResourceLocationfor 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
12
12
4. For datagen: create a condition model class
13
13
5. Finally use the condition in your book
14
14
15
15
:::tip
16
16
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.
18
18
19
19
:::
20
20
21
21
## Condition Class
22
22
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`.
25
24
26
-
in `getType()` return your ResourceLocation.
25
+
Each condition class must declare three static fields:
27
26
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.
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:
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.
42
78
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.
Copy file name to clipboardExpand all lines: versioned_docs/version-26.1.2/multiblocks/state-matchers/predicate-matcher.md
+48-24Lines changed: 48 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,22 +4,19 @@ sidebar_position: 50
4
4
5
5
# Predicate Matchers
6
6
7
-
# Tag Matcher
8
-
9
7
**Type:**`modonomicon:predicate`
10
8
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.
13
10
14
11
## Attributes
15
12
16
13
### **predicate** (ResourceLocation, _mandatory_)
17
-
14
+
18
15
The ID of the predicate to use for the matcher.
19
16
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.
23
20
24
21
:::info
25
22
@@ -29,33 +26,54 @@ Tag matchers will check if the placed block is part of the provided tag. Additio
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.
33
30
E.g. for the `modonomicon:air` predicate you would set this to `false`.
34
31
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.
35
32
36
33
## Registering Predicates
37
34
38
-
Predicates are registered in the `FMLCommonSetupEvent`:
35
+
Create a dedicated registry class and register your predicates via `PredicateRegistry.register(...)`:
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)**).
55
73
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.
57
75
58
-
<!-- TODO: Link to an article that explains in detail how to guard against no class def -->
76
+
:::
59
77
60
78
## Builtin Predicates
61
79
@@ -65,14 +83,20 @@ You can avoid this by calling `LoaderRegistry.registerPredicate` in a separate c
65
83
66
84
Matches air blocks. Requires players to remove any blocks in the location of this matcher.
0 commit comments