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

Deprecation of MinecraftFormattingConverter #18

Open
stephan-gh opened this issue May 7, 2021 · 5 comments
Open

Deprecation of MinecraftFormattingConverter #18

stephan-gh opened this issue May 7, 2021 · 5 comments

Comments

@stephan-gh
Copy link
Member

TerminalConsoleAppender was never meant to be Minecraft-specific. It works just fine for other uses as well. The only Minecraft-specific code that it contains is the MinecraftFormattingConverter that is used to translate legacy color codes (§c etc) to ANSI color codes. I put that here because that was convenient back then when I needed the same code on multiple platforms.

But now legacy formatting codes have been deprecated for a long time, and there is no standard representation of newer features like RGB colors anymore. At this point, it seems easier if the projects that need it (and perhaps even want modern features like RGB support) make a copy of MinecraftFormattingConverter and change it to their needs. For example, Paper has made such a copy in PaperMC/Paper#5205.

As additional inspiration in case someone wants to implement this properly I will briefly describe a completely other, but potentially much cleaner approach that avoids legacy color codes entirely. I never found time to implement it, but I think it should work.

In particular, Log4j2 has the Message interface that can be passed to all log calls instead of a raw String. The idea would be to implement a custom Message class to retain all the properties of a text component (colors, hover events, ...), without having to serialize it into a raw string. Instead of logger.info(component.toLegacy()) you might use logger.info(new ComponentMessage(component)).
Then there is a sub-interface called MultiformatMessage, which can render itself differently based on the output it is appended to. So instead of having to strip color codes to log to a file, we can avoid generating them in the first place!

Something like this could be implemented once for a chat component API like adventure and then shared between projects that make use of adventure.

@zml2008 I believe we discussed this at some point? Did you ever finish implementing it? (I hope it was you, can't remember exactly and also can't find the chat log anymore. :D)

@electronicboy
Copy link

minecrell is alive! 😱

Keep tryna reply to this but I can't quite convey what I wanna say all too well,

Basically, I can understand wanting to get rid of the MC specific stuff, especially when we have divergence with stuff like spigots weird format, ontop of the fact that other platforms generally don't really have any representation of the chat outside of a legacy format we're all tryna convince people to get away from, especially as it's missing a good chunk of the feature set people have come to love

I think having a logger which can deal with adventure would be great, for one, it's adventure, for two, as much as it's tied to MC, it's doesn't seem unusable outside of MC, at least for a lot of typical stuff like text formatting, which is a horror when tryna deal with ansi outside, i'd much prefer to leave that mess to somebody who's not me rather than having to determine in my own apps if ansi is available, what features I can use, etc

@stephan-gh
Copy link
Member Author

I think having a logger which can deal with adventure would be great, for one, it's adventure, for two, as much as it's tied to MC, it's doesn't seem unusable outside of MC, at least for a lot of typical stuff like text formatting, which is a horror when tryna deal with ansi outside, i'd much prefer to leave that mess to somebody who's not me rather than having to determine in my own apps if ansi is available, what features I can use, etc

There is no need to put that code into TerminalConsoleAppender. It could just become some part of Kyori/Adventure I guess and then you can depend on it additionally. Log4j is quite extensible there.

@electronicboy
Copy link

Yea, I was somewhat for adventure support in TCA given that it would be a nice base, but, now that you mention it, it being done over in the adventure side of stuff itself seems a lot more ideal.

imho, having a text format capable of representing colors and formatting and such without having to dig into ansi and determining support, etc, does sound like a cool wider goal, it would just be somewhat weird given that adventure is designed for an environment that supports much more

@zml2008
Copy link

zml2008 commented May 8, 2021

I've done some work on this, but haven't had a chance to finish implementing it. There are some pieces out there so far:

@zml2008
Copy link

zml2008 commented Apr 26, 2022

Just an update on this front -- Mojang has been moving Minecraft to use SLF4J for its logging API, so logging components directly is a bit more complicated. The approach I've chosen with Adventure is to implement a Logger wrapper that overloads every log method to accept a Component parameter (see KyoriPowered/adventure#757). This approach could be applied similarly to create wrappers accepting Minecraft's components directly, or any other implementation.

Unfortunately not much progress on the other elements of the strategy, but this at least shifts those to an implementation detail, so the end-user API can remain consistent while the way components are converted into ansi control sequences is evolved over time.

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

No branches or pull requests

3 participants