forked from ChomeNS/chipmunkmod
FIX THE FUCKING SHIT BY A SINGLE FUCKING LINE OF THE FUCKING CODE
This commit is contained in:
parent
c04380b420
commit
08c3773660
2 changed files with 32 additions and 39 deletions
|
@ -10,6 +10,7 @@ import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
|
||||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.command.CommandSource;
|
||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
|
@ -28,10 +29,6 @@ public class ChatInputSuggestorMixin {
|
||||||
@Shadow
|
@Shadow
|
||||||
private CompletableFuture<Suggestions> pendingSuggestions;
|
private CompletableFuture<Suggestions> pendingSuggestions;
|
||||||
|
|
||||||
@Final
|
|
||||||
@Shadow
|
|
||||||
private boolean slashOptional;
|
|
||||||
|
|
||||||
@Shadow
|
@Shadow
|
||||||
public void show (boolean narrateFirstSuggestion) {}
|
public void show (boolean narrateFirstSuggestion) {}
|
||||||
|
|
||||||
|
@ -51,56 +48,51 @@ public class ChatInputSuggestorMixin {
|
||||||
|
|
||||||
@Inject(at = @At("TAIL"), method = "refresh()V")
|
@Inject(at = @At("TAIL"), method = "refresh()V")
|
||||||
public void refresh (CallbackInfo ci) {
|
public void refresh (CallbackInfo ci) {
|
||||||
try {
|
final CommandManager commandManager = CommandManager.INSTANCE;
|
||||||
if (slashOptional) return;
|
|
||||||
|
|
||||||
final CommandManager commandManager = CommandManager.INSTANCE;
|
final String text = this.textField.getText();
|
||||||
|
final int cursor = this.textField.getCursor();
|
||||||
|
|
||||||
final String text = this.textField.getText();
|
final ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
||||||
final int cursor = this.textField.getCursor();
|
|
||||||
|
|
||||||
final ClientPlayerEntity player = MinecraftClient.getInstance().player;
|
final String chomeNSPrefix = ChipmunkMod.CONFIG.bots.chomens.prefix;
|
||||||
|
|
||||||
final String chomeNSPrefix = ChipmunkMod.CONFIG.bots.chomens.prefix;
|
if (!text.contains(" ") && text.startsWith(chomeNSPrefix) && player != null) {
|
||||||
|
final String textUpToCursor = text.substring(0, cursor);
|
||||||
|
|
||||||
if (!text.contains(" ") && text.startsWith(chomeNSPrefix) && player != null) {
|
final List<String> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands
|
||||||
final String textUpToCursor = text.substring(0, cursor);
|
.stream()
|
||||||
|
.map((command) -> command.name)
|
||||||
|
.toList();
|
||||||
|
|
||||||
final List<String> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands
|
pendingSuggestions = CommandSource.suggestMatching(
|
||||||
.stream()
|
commands,
|
||||||
.map((command) -> command.name)
|
new SuggestionsBuilder(
|
||||||
.toList();
|
textUpToCursor,
|
||||||
|
getStartOfCurrentWord(textUpToCursor)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
pendingSuggestions = CommandSource.suggestMatching(
|
pendingSuggestions.thenRun(() -> {
|
||||||
commands,
|
if (!pendingSuggestions.isDone()) return;
|
||||||
new SuggestionsBuilder(
|
|
||||||
textUpToCursor,
|
|
||||||
getStartOfCurrentWord(textUpToCursor)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
pendingSuggestions.thenRun(() -> {
|
|
||||||
if (!pendingSuggestions.isDone()) return;
|
|
||||||
|
|
||||||
show(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cursor < commandManager.prefix.length() || !text.startsWith(commandManager.prefix)) return;
|
|
||||||
|
|
||||||
|
show(true);
|
||||||
|
});
|
||||||
|
} else if (cursor > commandManager.prefix.length() && text.startsWith(commandManager.prefix)) {
|
||||||
final StringReader reader = new StringReader(text);
|
final StringReader reader = new StringReader(text);
|
||||||
reader.setCursor(commandManager.prefix.length()); // Skip the prefix
|
reader.setCursor(commandManager.prefix.length()); // Skip the prefix
|
||||||
|
|
||||||
final CommandDispatcher<FabricClientCommandSource> dispatcher = commandManager.dispatcher;
|
|
||||||
final MinecraftClient client = MinecraftClient.getInstance();
|
final MinecraftClient client = MinecraftClient.getInstance();
|
||||||
final FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getNetworkHandler().getCommandSource();
|
|
||||||
|
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
|
||||||
|
|
||||||
|
if (networkHandler == null) return;
|
||||||
|
|
||||||
|
final CommandDispatcher<FabricClientCommandSource> dispatcher = commandManager.dispatcher;
|
||||||
|
final FabricClientCommandSource commandSource = (FabricClientCommandSource) networkHandler.getCommandSource();
|
||||||
|
|
||||||
pendingSuggestions = dispatcher.getCompletionSuggestions(dispatcher.parse(reader, commandSource), cursor);
|
pendingSuggestions = dispatcher.getCompletionSuggestions(dispatcher.parse(reader, commandSource), cursor);
|
||||||
show(true);
|
show(true);
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ public class ChatScreenMixin extends Screen {
|
||||||
this.chatField.setFocusUnlocked(false);
|
this.chatField.setFocusUnlocked(false);
|
||||||
this.addSelectableChild(this.chatField);
|
this.addSelectableChild(this.chatField);
|
||||||
this.chatInputSuggestor = new ChatInputSuggestor(this.client, this, this.chatField, this.textRenderer, false, false, 1, 10, true, -805306368);
|
this.chatInputSuggestor = new ChatInputSuggestor(this.client, this, this.chatField, this.textRenderer, false, false, 1, 10, true, -805306368);
|
||||||
|
this.chatInputSuggestor.setCanLeave(false);
|
||||||
this.chatInputSuggestor.refresh();
|
this.chatInputSuggestor.refresh();
|
||||||
this.setInitialFocus(this.chatField);
|
this.setInitialFocus(this.chatField);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue