Skip to content

Commit

Permalink
Fix auto complete in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
nutyworks committed Mar 19, 2024
1 parent 8b912a9 commit 3b5bd73
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ public interface ChatInputSuggestorFields {

@Accessor
List<OrderedText> getMessages();

@Accessor
boolean getChatScreenSized();
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package works.nuty.calcite.mixin.client;

import com.mojang.brigadier.suggestion.Suggestion;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ChatInputSuggestor;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.List;

@Environment(EnvType.CLIENT)
@Mixin(ChatInputSuggestor.SuggestionWindow.class)
public abstract class SuggestionWindowMixin {
Expand All @@ -22,6 +27,13 @@ public abstract class SuggestionWindowMixin {
@Shadow
public abstract void complete();

@Unique boolean chatScreenSized;

@Inject(at = @At("TAIL"), method = "<init>")
public void init(ChatInputSuggestor chatInputSuggestor, int x, int y, int width, List<Suggestion> suggestions, boolean narrateFirstSuggestion, CallbackInfo ci) {
this.chatScreenSized = ((ChatInputSuggestorFields) chatInputSuggestor).getChatScreenSized();
}

@Inject(at = @At("HEAD"), method = "keyPressed", cancellable = true)
public void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
if ((modifiers & GLFW.GLFW_MOD_CONTROL) > 0 && keyCode == GLFW.GLFW_KEY_N) {
Expand All @@ -36,7 +48,7 @@ public void keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoRet
cir.setReturnValue(true);
cir.cancel();
}
if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER) {
if (!chatScreenSized && (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER)) {
this.complete();
cir.setReturnValue(true);
cir.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public CommandWidget(CommandBlockBlockEntity blockEntity) {
this.commandEdit.setMaxLength(32500);
this.commandEdit.setChangedListener(this::onCommandChanged);

this.commandSuggestor = new ChatInputSuggestor(CalciteCommandScreen.this.client, CalciteCommandScreen.this, this.commandEdit, CalciteCommandScreen.this.textRenderer, true, true, 0, 7, false, Integer.MIN_VALUE);
this.commandSuggestor = new ChatInputSuggestor(CalciteCommandScreen.this.client, CalciteCommandScreen.this, this.commandEdit, CalciteCommandScreen.this.textRenderer, true, true, 0, 10, false, Integer.MIN_VALUE);
this.commandSuggestor.setWindowActive(true);
this.commandSuggestor.refresh();

Expand Down

0 comments on commit 3b5bd73

Please sign in to comment.