Skip to content

Commit 891fb1b

Browse files
committed
✨ Render all emotes if you only have : in your chat
1 parent f63bd94 commit 891fb1b

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/main/java/dev/renoux/emotes/mixins/ChatScreenMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected void init(CallbackInfo ci) {
3131
}
3232

3333

34-
@Inject(method = "render", at = @At("HEAD"))
34+
@Inject(method = "render", at = @At("TAIL"))
3535
public void render(GuiGraphics guiGraphics, int i, int j, float f, CallbackInfo ci) {
3636
if (emojiSuggestionHelper != null && EmoteUtil.getInstance().showSuggestions()) emojiSuggestionHelper.render(guiGraphics);
3737
}

src/main/java/dev/renoux/emotes/utils/EmojiSuggestionHelper.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class EmojiSuggestionHelper extends IDrawableGuiListener {
5959
private boolean updating;
6060
private String inputFieldTextLast;
6161

62+
private boolean render = false;
63+
6264
public EmojiSuggestionHelper(ChatScreen screen) {
6365
this.chatScreen = screen;
6466
this.updating = false;
@@ -95,6 +97,9 @@ private static String trim(String text, String textAll) {
9597

9698
@Override
9799
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
100+
if (keyCode == 262 || keyCode == 263) {
101+
render = false;
102+
}
98103
if (this.suggestions != null && this.suggestions.onKeyPressed(keyCode)) {
99104
return true;
100105
} else if (keyCode == 258) {
@@ -112,7 +117,6 @@ public void updateSuggestionList(boolean skip) {
112117
this.chatScreen.input.setSuggestion(null);
113118
this.suggestions = null;
114119
}
115-
116120
final StringReader stringreader = new StringReader(s);
117121
if (stringreader.canRead()) {
118122
final int cursorPosition = this.chatScreen.input.getCursorPosition();
@@ -137,14 +141,15 @@ public void showSuggestions() {
137141
if (!suggestions.getList().isEmpty()) {
138142
for (final Suggestion suggestion : suggestions.getList())
139143
i = Math.max(i, Minecraft.getInstance().font.width(suggestion.getText()));
140-
final int j = Minecraft.getInstance().font.width(this.chatScreen.input.getValue().substring(0, this.chatScreen.input.getCursorPosition() - suggestions.getRange().getLength() + 2));
144+
String text = suggestions.getRange().getLength() == 1 ? this.chatScreen.input.getValue() + "thisisdebugcodedontlookatit" : this.chatScreen.input.getValue();
145+
final int j = Minecraft.getInstance().font.width(text.substring(0, this.chatScreen.input.getCursorPosition() - suggestions.getRange().getLength() + 2));
141146
this.suggestions = new EmojiSuggestions(j, this.chatScreen.height - 12, i, suggestions);
142147
}
143148
}
144149
}
145150

146151
public void render(GuiGraphics matrixStack) {
147-
if (this.suggestions != null) {
152+
if (this.suggestions != null && render) {
148153
this.suggestions.render(matrixStack);
149154
}
150155
checkTextUpdate();
@@ -193,24 +198,30 @@ public void setIndex(int i) {
193198
}
194199

195200
public boolean onKeyPressed(int keyCode) {
201+
if (suggestions.getRange().getLength() > 1) {
202+
EmojiSuggestionHelper.this.render = true;
203+
}
196204
if (keyCode == 265) {
197205
offsetIndex(-1);
198206
return true;
199207
} else if (keyCode == 264) {
200208
offsetIndex(1);
201209
return true;
202210
} else if (keyCode == 258) {
203-
applySuggestion();
211+
if (suggestions.getRange().getLength() > 1) applySuggestion();
212+
EmojiSuggestionHelper.this.render = true;
204213
return true;
205-
} else if ((keyCode == 257 || keyCode == 335)) {
214+
} else if ((keyCode == 257 || keyCode == 335) && suggestions.getRange().getLength() > 1) {
206215
applySuggestion();
207216
return true;
208217
} else if (keyCode == 256) {
209218
removeSuggestion();
219+
EmojiSuggestionHelper.this.render = false;
210220
return true;
211221
} else if ((keyCode == 262 || keyCode == 263)) {
212222
EmojiSuggestionHelper.this.chatScreen.input.setSuggestion("");
213223
removeSuggestion();
224+
EmojiSuggestionHelper.this.render = false;
214225
return false;
215226
} else
216227
return false;

0 commit comments

Comments
 (0)