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: public/wiki/cardinal-components-api/modules/world.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,13 @@ breadcrumb: Worlds
6
6
7
7
This module allows mods to attach components to `World` objects. World components can be automatically synchronized by implementing `SyncedComponent`, most commonly through the `WorldSyncedComponent` helper interface.
8
8
9
+
### A note about access
10
+
11
+
World objects are among the easiest to access in your code (notably available on the client through `MinecraftClient#world` and on the server
12
+
through `MinecraftServer#getWorld`), with the caveat that a client cannot retrieve data for a `World` that they are not currently in.
13
+
If you need your clients to be aware of the custom data for another dimension (<i>e.g.</i> for fancy portal effects), you may be interested
14
+
in a global data store like [Cardinal Components Scoreboard](./scoreboard).
15
+
9
16
## Usage
10
17
### Registration
11
18
World components are registered by a [`WorldComponentInitializer`](https://github.com/Ladysnake/Cardinal-Components-API/blob/master/cardinal-components-world/src/main/java/org/ladysnake/cca/api/v3/world/WorldComponentInitializer.java), exposed as `cardinal-components-world` in the mod json (more information on the [component registration page](../registration#2-attaching-your-component)). Once a component factory is registered, its associated component will be available on every `World` instance, on both clients and servers.
Copy file name to clipboardExpand all lines: public/wiki/cardinal-components-api/synchronization.md
+26-2Lines changed: 26 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,10 @@ public class SyncedIntComponent implements IntComponent, AutoSyncedComponent {
28
28
// getters, setters, and serialization methods omitted for brevity
29
29
}
30
30
```
31
-
With that, all the data that you save through your serialization methods gets automatically synchronized whenever a player starts tracking the provider to which your component is attached. If your component has its value set during initialization and never changes, this would *technically* be enough. However, most components store *dynamic* values, which means you need to notify players of your changes. For that, all you need to do is call [`ComponentKey#sync`](https://github.com/Ladysnake/Cardinal-Components-API/blob/master/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/ComponentKey.java#L110) whenever you update your component.
31
+
With that, all the data that you save through your serialization methods gets automatically synchronized whenever a player starts tracking the provider to which your component is attached.
32
+
If your component has its value set during initialization and never changes, this would *technically* be enough.
33
+
However, most components store *dynamic* values, which means you need to notify players of your changes.
34
+
For that, all you need to do is call [`ComponentKey#sync`](https://github.com/Ladysnake/Cardinal-Components-API/blob/master/cardinal-components-base/src/main/java/org/ladysnake/cca/api/v3/component/ComponentKey.java#L110) whenever you update your component.
32
35
33
36
*For information on how to obtain a `ComponentKey`, refer to the [Registering and using a component](registration) page.*
34
37
@@ -129,4 +132,25 @@ public class SyncedIntComponent implements IntComponent, AutoSyncedComponent {
129
132
}
130
133
}
131
134
}
132
-
```
135
+
```
136
+
137
+
## Client-optional components
138
+
139
+
Since Cardinal Components API 6.0, **attempting to sync a component to a player who does not have your mod installed clientside
140
+
will now result in a disconnection.**
141
+
142
+
If the client is missing Cardinal Components API, they will receive a message saying "This server requires Cardinal Components API".
143
+
144
+
To disable this behaviour, you can override the `isRequiredOnClient` method in your `PlayerSyncPredicate` (typically your `AutoSyncComponent` implementation).
145
+
For example:
146
+
147
+
```java
148
+
public class MyClientOptionalComponent implements AutoSyncedComponent {
0 commit comments