Skip to content

Commit

Permalink
Update components.md
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTheodor authored Sep 3, 2024
1 parent 8c00181 commit fffd927
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions content/development/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,37 @@ This approach is not practical, unless you have a lot of components.

You can create a custom ID like this:
```java
public static final IdLike MY_ID = new
public static final IdLike MY_ID = new new AbstractId<>("MY_ID", MyComponentHandler::new, MyComponentHandler.class);
```

(It's highly recommended to use a full caps & snake case name for the ID)
It's also important to register it:
```java
TardisComponentRegistry.register(MY_ID);
```
TardisComponentRegistry.getInstance().register(MY_ID);
```

# Ticking
All components can receive a server tick event (serverside only).

To do that, you can just implement the `TardisTickable` interface and override the default `#tick(MinecraftServer)` method.

# Synching
It's recommended to use [V2 properties](properties) for this, but in case your data structure is too complex to be implemented using the properties API, you can use this method.

You can call `TardisComponent#sync` to force sync the full component data _from server to client_. It won't work the other way around.

The reason why this is not recommended to use, is that it syncs ALL of the component data, which is bad if you have a lot of fields in the handler.

# Storing data
If you don't need to sync data at all, you can just use plain fields, although it's recommended to use the `@Exclude` annotation on them.

To exclude something from getting saved or synced just apply the excluding annotation.

By default, the annotation stops the data of the field it gets applied to from being serialized for both networking and storing.

You can change the strategy by supplying arguments to the annotation via an enum.

If you choose the `FILE` strategy, the data will not be persisted and will not be saved to the file, however it will sync.

If you choose the `NETWORK` strategy, the data will be saved to the data file, but it won't be sent over the network, meaning that the client will get the default values for the fields (`0` for numbers, `false` for booleans, `null` for objects, etc).

0 comments on commit fffd927

Please sign in to comment.