Skip to content

Commit

Permalink
chore(docs): Add links to stream codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChampionAsh5357 committed May 21, 2024
1 parent 601b875 commit 313995a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
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
3 changes: 2 additions & 1 deletion docs/resources/server/recipes/custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Only two methods need to be implemented for a `RecipeSerializer`:
| Method | Description
|:-----------:|:----------
`codec` | A [map codec][codec] used to read and write the recipe to disk.
`streamCodec` | A stream codec used to send the recipe through the network.
`streamCodec` | A [stream codec][streamcodec] used to send the recipe through the network.

The `RecipeSerializer` instance must then be returned by `Recipe#getSerializer` in the new recipe subtype.

Expand Down Expand Up @@ -123,3 +123,4 @@ All custom recipes, regardless of input or output data, can be provided to `Reci
[codec]: ../../../datastorage/codecs.md
[manager]: ./index.md#recipe-manager
[datagen]: ../../../datagen/recipes.md#custom-recipe-serializers
[streamcodec]: ../../../networking/streamcodecs.md
3 changes: 2 additions & 1 deletion docs/resources/server/recipes/ingredients.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ There are four important methods to implement:

### IngredientType

`IngredientType` contains two values: a [map codec][codec] used to encode and decode the ingredient, and a `StreamCodec` to sync the ingredient if `ICustomIngredient#isSimple` returns `false`. If `#isSimple` is `true`, then `IngredientType` has a constructor overload that only takes in the map codec.
`IngredientType` contains two values: a [map codec][codec] used to encode and decode the ingredient, and a [`StreamCodec`][streamcodec] to sync the ingredient if `ICustomIngredient#isSimple` returns `false`. If `#isSimple` is `true`, then `IngredientType` has a constructor overload that only takes in the map codec.

The `IngredientType` needs to be [registered][registering].

Expand All @@ -127,3 +127,4 @@ public IngredientType<?> getType() {
[codec]: ../../../datastorage/codecs.md
[datagen]: ../../../datagen/recipes.md
[datacomponents]: ../../../items/datacomponents.md
[streamcodec]: ../../../networking/streamcodecs.md

1 comment on commit 313995a

@neoforged-pages-deployments
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploying with Cloudflare Pages

Name Result
Last commit: 313995a2568633603f7d704c19e495e7776268e7
Status: ✅ Deploy successful!
Preview URL: https://317dfa67.neoforged-docs-previews.pages.dev
PR Preview URL: https://pr-80.neoforged-docs-previews.pages.dev

Please sign in to comment.