-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
Start working on codecs #87
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a solid start, I think the structure is good to understand codecs bit by bit. I mostly have stylistic feedback, though I think we also need a section about the Codecs
class and its utilities.
Let's look more into the `DataResult`: | ||
```java | ||
... | ||
.result() // Option<Pair<Boolean, JsonElement>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't you been doing a bit too much rust lately? :P
Then finally, we call `getFirst` on `com.mojang.datafixers.util.Pair` to get the first half of the pair | ||
|
||
Wow. That sure was a lot. | ||
Now, I know this may seem like the `Codec` system is complicated right now, but unfortunately we have only scratched the surface. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the first person in a wiki article feels a bit weird to me, especially given that they end up written by several people. In this case, I think "Now, this may seem" would be enough.
|
||
Ok, thats not too bad. | ||
One nice thing about this is that Mojang did a lot of magic behind the scene to make this feel nice. | ||
Trust me, I (OroArmor) once wrote a similar library and partially gave up on doing the right thing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the same reasons as above, I think you could rewrite this as "Some of us (like OroArmor) attempted to write equivalents, only to partially give up on doing the right things"
But also are these two sentences really necessary ? They feel a bit out of place in a wiki article.
As shown in the comments above, the type of the input and a generic parameter on `ops` must match. | ||
This is because the `ops` needs to know about how the `input` functions. | ||
In this example, we use `com.mojang.serialization.JsonOps.INSTANCE`, which operates on json elements from `gson`. | ||
We then pass in a `JsonPrimative` with a value of `true` for this example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We then pass in a `JsonPrimative` with a value of `true` for this example. | |
We then pass in a `JsonPrimitive` with a value of `true` for this example. |
In this case we know that it is safe due to the simplicity of the example. | ||
Then finally, we call `getFirst` on `com.mojang.datafixers.util.Pair` to get the first half of the pair | ||
|
||
Wow. That sure was a lot. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would note here that using codecs directly is actually fairly rare in Minecraft. Most of the time, you have other code doing it for you and you really just have to build the codec (also makes for a convenient transition with the next section).
|
||
<!-- TODO: Is this div needed? The basic example is getting pushed to the bottom of the page for some reason --> | ||
<div> | ||
## Primative Codecs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Primative Codecs | |
## Primitive Codecs |
The `Codec` class from [DataFixerUpper](https://github.com/Mojang/DataFixerUpper) is the backbone of content serialization and deserialization. | ||
It provides an abstraction layer between Java Objects and serialization types, such as `json`, `nbt`, and more. | ||
Each `Codec` is made of a `Encoder` and a `Decoder`, but you rarely need to create a raw `Codec` from scratch. | ||
Let's start off with the primative `Codec`s. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's start off with the primative `Codec`s. | |
Let's start off with the primitive `Codec`s. |
Yep id say it's 1/3 done |
just dropping this here: I quite like https://gist.github.com/Drullkus/1bca3f2d7f048b1fe03be97c28f87910 |
Documents codecs and their usage.
See preview on Cloudflare Pages: https://preview-87.developer-wiki.pages.dev