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

fix: Usage of TextContent::Translate resulted in a bad packet #455

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jonasborsch
Copy link

Description

As a heads up, I've never developed in rust before, so please give me the hardest feedback you can.

The usage of TextContent::Translate resulted in a bad packet. This was due to the implementation causing the TextComponent's from the with vector to be serialized into a byte array. I would guess, that for the same reason the temporary struct was used.

I tried different solutions but the only viable for me seemed to be a wrapper. With that the whole temporary struct could be removed. The TextComponent now handles JSON-serialization and the TextComponentNbt is the NBT binary representation.

Testing

Now we can edit the assets/synced_registries.json file and we see that the /say command uses the correct translation.
image


image

The usage of TextContent::Translate resulted in a bad package. This was due to the implementation causing the TextComponent's from the with vector to be serialized into a byte array.
I would guess, that for the same reason the temporary struct was used.
@jonasborsch
Copy link
Author

jonasborsch commented Jan 5, 2025

Feel free to review, but still a draft because there are still two things open:

  1. Messages from the /say command do not appear in the console
  2. Need to add tests for the TextComponent
  3. My format is probably shit

@Snowiiii Snowiiii linked an issue Jan 5, 2025 that may be closed by this pull request
1 task
pumpkin-core/Cargo.toml Outdated Show resolved Hide resolved
@Snowiiii
Copy link
Member

Snowiiii commented Jan 5, 2025

Really impressive for someone who just Started with Rust 👍. Your approche is similar to valence (which is not a bad thing). One thing you have to fix is the CI, In particulier some clippy checks are failing, make sure to fix every warning produced when running cargo clippy --all-targets

Overall good work, Thank you @jonasborsch

@jonasborsch
Copy link
Author

jonasborsch commented Jan 5, 2025

Really impressive for someone who just Started with Rust 👍. Your approche is similar to valence (which is not a bad thing). One thing you have to fix is the CI, In particulier some clippy checks are failing, make sure to fix every warning produced when running cargo clippy --all-targets

Overall good work, Thank you @jonasborsch

Thanks for the feedback! If I knew there was already an implementation of that I could've saved couple hours of my time. 🥲

Anyway, I'll work on the fixes and then mark the PR as ready for review

TextComponentNbt
* simplified name to Text
* convert to inline struct
* implement From<TextComponent> trait for conventient use

Also added console output to say command. For that the translations also had to be evaluated on the server. The official minecraft server does that using the en_us language. I copied the language file into the assets/lang folder
@jonasborsch
Copy link
Author

jonasborsch commented Jan 5, 2025

Had to add the assets/lang/en_us.json file to allow server logs to be translated. This PR turns out the be an implementation of chat type instead of the simple translate fix.

There is still some work left:

  • easier use of chat types (maybe an enum?)
  • (optional) use the provided arguments list of the chat decorators. Java uses a context and dynamically resolves the arguments from that context
  • check if the pumpkin-core/src//lang/mod.rs is any good
  • refactor to_pretty_console() (my first thought was Visitor-Pattern)

@Snowiiii
Copy link
Member

Snowiiii commented Jan 5, 2025

All files in the assets are coming from our Extractor. Can you may modify the extractor so it produces the latest en-US.json

@jonasborsch
Copy link
Author

jonasborsch commented Jan 6, 2025

All files in the assets are coming from our Extractor. Can you may modify the extractor so it produces the latest en-US.json

That‘s definitely more convenient. I will work on it in the next couple of days. Thanks for the tip

@jonasborsch
Copy link
Author

All files in the assets are coming from our Extractor. Can you may modify the extractor so it produces the latest en-US.json

See Pumpkin-MC/Extractor#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TextContent::Translate.with Serialization is not working
2 participants