i am not sure
This commit is contained in:
parent
43939452fc
commit
c04380b420
1 changed files with 40 additions and 37 deletions
|
@ -6,7 +6,6 @@ import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||||
import land.chipmunk.chipmunkmod.command.CommandManager;
|
import land.chipmunk.chipmunkmod.command.CommandManager;
|
||||||
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
|
|
||||||
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
|
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;
|
||||||
|
@ -52,52 +51,56 @@ 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) {
|
||||||
if (slashOptional) return;
|
try {
|
||||||
|
if (slashOptional) return;
|
||||||
|
|
||||||
final CommandManager commandManager = CommandManager.INSTANCE;
|
final CommandManager commandManager = CommandManager.INSTANCE;
|
||||||
|
|
||||||
final String text = this.textField.getText();
|
final String text = this.textField.getText();
|
||||||
final int cursor = this.textField.getCursor();
|
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) {
|
if (!text.contains(" ") && text.startsWith(chomeNSPrefix) && player != null) {
|
||||||
final String textUpToCursor = text.substring(0, cursor);
|
final String textUpToCursor = text.substring(0, cursor);
|
||||||
|
|
||||||
final List<String> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands
|
final List<String> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands
|
||||||
.stream()
|
.stream()
|
||||||
.map((command) -> command.name)
|
.map((command) -> command.name)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
pendingSuggestions = CommandSource.suggestMatching(
|
pendingSuggestions = CommandSource.suggestMatching(
|
||||||
commands,
|
commands,
|
||||||
new SuggestionsBuilder(
|
new SuggestionsBuilder(
|
||||||
textUpToCursor,
|
textUpToCursor,
|
||||||
getStartOfCurrentWord(textUpToCursor)
|
getStartOfCurrentWord(textUpToCursor)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
pendingSuggestions.thenRun(() -> {
|
pendingSuggestions.thenRun(() -> {
|
||||||
if (!pendingSuggestions.isDone()) return;
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue