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

Start working on codecs #87

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

OroArmor
Copy link
Member

@OroArmor OroArmor commented Feb 25, 2024

Documents codecs and their usage.

See preview on Cloudflare Pages: https://preview-87.developer-wiki.pages.dev

Copy link
Member

@Pyrofab Pyrofab left a 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>>
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
## 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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Let's start off with the primative `Codec`s.
Let's start off with the primitive `Codec`s.

@OroArmor
Copy link
Member Author

Yep id say it's 1/3 done

@ix0rai ix0rai added content Relates to the content of the wiki new page adds a new wiki page labels Feb 26, 2024
@ix0rai
Copy link
Member

ix0rai commented Mar 17, 2024

just dropping this here: I quite like https://gist.github.com/Drullkus/1bca3f2d7f048b1fe03be97c28f87910

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Relates to the content of the wiki new page adds a new wiki page
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants