Skip to content

Commit a6fe4a2

Browse files
committed
Add info about client-optional components
1 parent c0fa95e commit a6fe4a2

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

public/wiki/cardinal-components-api/modules/world.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ breadcrumb: Worlds
66

77
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.
88

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+
916
## Usage
1017
### Registration
1118
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.

public/wiki/cardinal-components-api/synchronization.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ public class SyncedIntComponent implements IntComponent, AutoSyncedComponent {
2828
// getters, setters, and serialization methods omitted for brevity
2929
}
3030
```
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.
3235

3336
*For information on how to obtain a `ComponentKey`, refer to the [Registering and using a component](registration) page.*
3437

@@ -129,4 +132,25 @@ public class SyncedIntComponent implements IntComponent, AutoSyncedComponent {
129132
}
130133
}
131134
}
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 {
149+
@Override
150+
public boolean isRequiredOnClient() {
151+
return false;
152+
}
153+
154+
// ...
155+
}
156+
```

0 commit comments

Comments
 (0)