-
Notifications
You must be signed in to change notification settings - Fork 109
Fix newline characters not rendering as line breaks #840
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
Open
alppp
wants to merge
5
commits into
GTNewHorizons:master
Choose a base branch
from
alppp:hodgepodge-chat-newlines
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f9a4fc8
fix newline characters not rendering as line breaks
alppp 757d902
Merge branch 'master' into hodgepodge-chat-newlines
Dream-Master 7c3e46c
fix PR review: preserve chat id, hover/click
alppp 9b817e2
spotless
alppp f5b74e2
fix PR review: @WrapMethod for newline mixins
alppp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...va/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinFontRenderer_NewlineSupport.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.mitchej123.hodgepodge.mixins.early.minecraft; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import net.minecraft.client.gui.FontRenderer; | ||
|
|
||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Shadow; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
|
||
| @Mixin(FontRenderer.class) | ||
| public abstract class MixinFontRenderer_NewlineSupport { | ||
|
|
||
| @Shadow | ||
| public int FONT_HEIGHT; | ||
|
|
||
| @Shadow | ||
| public abstract List<String> listFormattedStringToWidth(String str, int wrapWidth); | ||
|
|
||
| @Shadow | ||
| private int renderString(String text, int x, int y, int color, boolean shadow) { | ||
| return 0; | ||
| } | ||
|
|
||
| @Inject(method = "renderString", at = @At("HEAD"), cancellable = true) | ||
| private void hodgepodge$handleNewlines(String text, int x, int y, int color, boolean shadow, | ||
| CallbackInfoReturnable<Integer> cir) { | ||
| if (text == null || text.indexOf('\n') < 0) return; | ||
|
|
||
| List<String> lines = this.listFormattedStringToWidth(text, Integer.MAX_VALUE); | ||
| int lastX = 0; | ||
| for (int i = 0; i < lines.size(); i++) { | ||
| lastX = this.renderString(lines.get(i), x, y + i * this.FONT_HEIGHT, color, shadow); | ||
| } | ||
| cir.setReturnValue(lastX); | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
...ava/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinGuiNewChat_FixChatNewlines.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.mitchej123.hodgepodge.mixins.early.minecraft; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import net.minecraft.client.gui.FontRenderer; | ||
| import net.minecraft.client.gui.GuiNewChat; | ||
| import net.minecraft.util.ChatComponentText; | ||
| import net.minecraft.util.IChatComponent; | ||
|
|
||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Unique; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
|
||
| @Mixin(GuiNewChat.class) | ||
| public class MixinGuiNewChat_FixChatNewlines { | ||
|
|
||
| @Inject(method = "printChatMessageWithOptionalDeletion", at = @At("HEAD"), cancellable = true) | ||
| private void hodgepodge$splitNewlines(IChatComponent component, int id, CallbackInfo ci) { | ||
| String formatted = component.getFormattedText(); | ||
| if (formatted.indexOf('\n') < 0) return; | ||
|
|
||
| List<IChatComponent> lines = hodgepodge$splitOnNewlines(formatted); | ||
| for (int i = 0; i < lines.size(); i++) { | ||
| ((GuiNewChat) (Object) this).printChatMessageWithOptionalDeletion(lines.get(i), i == 0 ? id : 0); | ||
| } | ||
| ci.cancel(); | ||
| } | ||
|
|
||
| @Unique | ||
| private static List<IChatComponent> hodgepodge$splitOnNewlines(String formatted) { | ||
| String[] parts = formatted.split("\n", -1); | ||
| List<IChatComponent> lines = new ArrayList<>(); | ||
| String carryFormat = ""; | ||
|
|
||
| for (String part : parts) { | ||
| String fullLine = carryFormat + part; | ||
| lines.add(new ChatComponentText(fullLine)); | ||
| carryFormat = FontRenderer.getFormatFromString(fullLine); | ||
| } | ||
|
|
||
| return lines; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.