i am not sure

This commit is contained in:
Chayapak 2023-10-01 11:37:48 +07:00
parent 43939452fc
commit c04380b420

View file

@ -6,7 +6,6 @@ import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.command.CommandManager;
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
@ -52,52 +51,56 @@ public class ChatInputSuggestorMixin {
@Inject(at = @At("TAIL"), method = "refresh()V")
public void refresh (CallbackInfo ci) {
if (slashOptional) return;
try {
if (slashOptional) return;
final CommandManager commandManager = CommandManager.INSTANCE;
final CommandManager commandManager = CommandManager.INSTANCE;
final String text = this.textField.getText();
final int cursor = this.textField.getCursor();
final String text = this.textField.getText();
final int cursor = this.textField.getCursor();
final ClientPlayerEntity player = MinecraftClient.getInstance().player;
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 String textUpToCursor = text.substring(0, cursor);
final List<String> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands
.stream()
.map((command) -> command.name)
.toList();
final List<String> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands
.stream()
.map((command) -> command.name)
.toList();
pendingSuggestions = CommandSource.suggestMatching(
commands,
new SuggestionsBuilder(
textUpToCursor,
getStartOfCurrentWord(textUpToCursor)
)
);
pendingSuggestions = CommandSource.suggestMatching(
commands,
new SuggestionsBuilder(
textUpToCursor,
getStartOfCurrentWord(textUpToCursor)
)
);
pendingSuggestions.thenRun(() -> {
if (!pendingSuggestions.isDone()) return;
pendingSuggestions.thenRun(() -> {
if (!pendingSuggestions.isDone()) return;
show(true);
});
show(true);
});
return;
return;
}
if (cursor < commandManager.prefix.length() || !text.startsWith(commandManager.prefix)) return;
final StringReader reader = new StringReader(text);
reader.setCursor(commandManager.prefix.length()); // Skip the prefix
final CommandDispatcher<FabricClientCommandSource> dispatcher = commandManager.dispatcher;
final MinecraftClient client = MinecraftClient.getInstance();
final FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getNetworkHandler().getCommandSource();
pendingSuggestions = dispatcher.getCompletionSuggestions(dispatcher.parse(reader, commandSource), cursor);
show(true);
} catch (Exception e) {
e.printStackTrace();
}
if (cursor < commandManager.prefix.length() || !text.startsWith(commandManager.prefix)) return;
final StringReader reader = new StringReader(text);
reader.setCursor(commandManager.prefix.length()); // Skip the prefix
final CommandDispatcher<FabricClientCommandSource> dispatcher = commandManager.dispatcher;
final MinecraftClient client = MinecraftClient.getInstance();
final FabricClientCommandSource commandSource = (FabricClientCommandSource) client.getNetworkHandler().getCommandSource();
pendingSuggestions = dispatcher.getCompletionSuggestions(dispatcher.parse(reader, commandSource), cursor);
show(true);
}
}