Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer, no wait, Network...ah, Stream Codecs! #80

Merged
merged 18 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/advanced/extensibleenums.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public enum ExampleEnumInit implements net.neoforged.neoforge.common.IExtensible

[Enum codecs][codec] generally take in the `values` array and resolve the codec instantly. As the array is evaluated before any mod entries are added, no mod entries will be supported. There are two solutions to this problem, which to choose depends on whether the enum implements the `StringRepresentable` interface or not.

For normal, non-`StringRepresentable` enums, the codec can be wrapped via `Codec#lazyInitialized` or `NeoForgeStreamCodecs#lazy`. These prevent the codec from being resolved until first usage, which will always be after all mod entries are added.
For normal, non-`StringRepresentable` enums, the codec can be wrapped via `Codec#lazyInitialized` or [`NeoForgeStreamCodecs#lazy`][streamcodec]. These prevent the codec from being resolved until first usage, which will always be after all mod entries are added.

```java
// For some enum with codec
Expand Down Expand Up @@ -219,3 +219,4 @@ public enum ExampleEnumStringCodec implements StringRepresentable, net.neoforged
```

[codec]: ../datastorage/codecs.md
[streamcodec]: ../networking/streamcodecs.md#vanilla-and-neoforge
3 changes: 2 additions & 1 deletion docs/items/datacomponents.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ExampleClass {

A standard `DataComponentType` can be created via `DataComponentType#builder` and built using `DataComponentType.Builder#build`. The builder contains three settings: `persistent`, `networkSynchronized`, `cacheEncoding`.

`persistent` specifies the [`Codec`][codec] used to read and write the component value to disk. `networkSynchronized` specifies the `StreamCodec` used to read and write the component across the network. If `networkSynchronized` is not specified, then the `Codec` provided in `persistent` will be wrapped and used as the `StreamCodec`.
`persistent` specifies the [`Codec`][codec] used to read and write the component value to disk. `networkSynchronized` specifies the `StreamCodec` used to read and write the component across the network. If `networkSynchronized` is not specified, then the `Codec` provided in `persistent` will be wrapped and used as the [`StreamCodec`][streamcodec].

:::warning
Either `persistent` or `networkSynchronized` must be provided in the builder; otherwise, a `NullPointerException` will be thrown. If no data should be sent across the network, then set `networkSynchronized` to `StreamCodec#unit`, providing the default component value.
Expand Down Expand Up @@ -323,3 +323,4 @@ public class ExampleHolder implements MutableDataComponentHolder {
[codec]: ../datastorage/codecs.md
[modbus]: ../concepts/events.md#event-buses
[network]: ../networking/payload.md
[streamcodec]: ../networking/streamcodecs.md
3 changes: 2 additions & 1 deletion docs/networking/payload.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Dissecting the code above we can notice a couple of things:
- The registrar uses a `*Bidirectional` method, that can be used for registering payloads which are sent to both the logical server and logical client.
- Not visible in this code are the methods `*ToClient` and `*ToServer`; however, they can also be used to register payloads to only the logical client or only the logical server, respectively.
- The type of the payload is used as a unique identifier for the payload.
- The stream codec is used to read and write the payload to and from the buffer sent across the network
- The [stream codec][streamcodec] is used to read and write the payload to and from the buffer sent across the network
- The payload handler is a callback for when the payload arrives on one of the logical sides.
- If a `*Bidirectional` method is used, a `DirectionalPayloadHandler` can be used to provide two separate payload handlers for each of the logical sides.

Expand Down Expand Up @@ -106,3 +106,4 @@ Now that you know how you can facilitate the communication between the client an
With your own payloads you can then use those to configure the client and server using [Configuration Tasks][configuration].

[configuration]: ./configuration-tasks.md
[streamcodec]: ./streamcodecs.md
Loading
Loading