Skip to content

Commit 3b5bd73

Browse files
committed
Fix auto complete in chat
1 parent 8b912a9 commit 3b5bd73

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/client/java/works/nuty/calcite/mixin/client/ChatInputSuggestorFields.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ public interface ChatInputSuggestorFields {
2525

2626
@Accessor
2727
List<OrderedText> getMessages();
28+
29+
@Accessor
30+
boolean getChatScreenSized();
2831
}

src/client/java/works/nuty/calcite/mixin/client/SuggestionWindowMixin.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package works.nuty.calcite.mixin.client;
22

3+
import com.mojang.brigadier.suggestion.Suggestion;
34
import net.fabricmc.api.EnvType;
45
import net.fabricmc.api.Environment;
56
import net.minecraft.client.gui.screen.ChatInputSuggestor;
67
import org.lwjgl.glfw.GLFW;
78
import org.spongepowered.asm.mixin.Mixin;
89
import org.spongepowered.asm.mixin.Shadow;
10+
import org.spongepowered.asm.mixin.Unique;
911
import org.spongepowered.asm.mixin.injection.At;
1012
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1114
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1215

16+
import java.util.List;
17+
1318
@Environment(EnvType.CLIENT)
1419
@Mixin(ChatInputSuggestor.SuggestionWindow.class)
1520
public abstract class SuggestionWindowMixin {
@@ -22,6 +27,13 @@ public abstract class SuggestionWindowMixin {
2227
@Shadow
2328
public abstract void complete();
2429

30+
@Unique boolean chatScreenSized;
31+
32+
@Inject(at = @At("TAIL"), method = "<init>")
33+
public void init(ChatInputSuggestor chatInputSuggestor, int x, int y, int width, List<Suggestion> suggestions, boolean narrateFirstSuggestion, CallbackInfo ci) {
34+
this.chatScreenSized = ((ChatInputSuggestorFields) chatInputSuggestor).getChatScreenSized();
35+
}
36+
2537
@Inject(at = @At("HEAD"), method = "keyPressed", cancellable = true)
2638
public void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
2739
if ((modifiers & GLFW.GLFW_MOD_CONTROL) > 0 && keyCode == GLFW.GLFW_KEY_N) {
@@ -36,7 +48,7 @@ public void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoRet
3648
cir.setReturnValue(true);
3749
cir.cancel();
3850
}
39-
if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER) {
51+
if (!chatScreenSized && (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER)) {
4052
this.complete();
4153
cir.setReturnValue(true);
4254
cir.cancel();

src/client/java/works/nuty/calcite/screen/CalciteCommandScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public CommandWidget(CommandBlockBlockEntity blockEntity) {
371371
this.commandEdit.setMaxLength(32500);
372372
this.commandEdit.setChangedListener(this::onCommandChanged);
373373

374-
this.commandSuggestor = new ChatInputSuggestor(CalciteCommandScreen.this.client, CalciteCommandScreen.this, this.commandEdit, CalciteCommandScreen.this.textRenderer, true, true, 0, 7, false, Integer.MIN_VALUE);
374+
this.commandSuggestor = new ChatInputSuggestor(CalciteCommandScreen.this.client, CalciteCommandScreen.this, this.commandEdit, CalciteCommandScreen.this.textRenderer, true, true, 0, 10, false, Integer.MIN_VALUE);
375375
this.commandSuggestor.setWindowActive(true);
376376
this.commandSuggestor.refresh();
377377

0 commit comments

Comments
 (0)