Skip to content

Commit

Permalink
Add autoprefix command (#647)
Browse files Browse the repository at this point in the history
* try adding autoprefix

* remove nix files

* add working auto prefix command

* remove more nix files

* add comments on why shift by -2

* use `@ModifyReceiver` for mixin instead

* fix review

* i forgot the alphabet

* fix bug and add custom parameter

* dont include nix stuff in gitignore

* Use a config for setting autoprefix instead

* dont specify getter/setter
  • Loading branch information
ImUrX authored Nov 27, 2024
1 parent 322761d commit b751737
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/earthcomputer/clientcommands/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public static void setMaxChorusItemThrows(int maxChorusItemThrows) {
Configs.maxChorusItemThrows = Mth.clamp(maxChorusItemThrows, 0, 1000000);
}

@Config(temporary = true)
public static String autoPrefix = "";

@Config(temporary = true, condition = "conditionLessThan1_21")
public static boolean infiniteTools = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
package net.earthcomputer.clientcommands.mixin.commands.generic;

import com.llamalad7.mixinextras.injector.ModifyReceiver;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import net.earthcomputer.clientcommands.ClientCommands;
import net.earthcomputer.clientcommands.Configs;
import net.earthcomputer.clientcommands.command.VarCommand;
import net.minecraft.client.gui.screens.ChatScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(ChatScreen.class)
public class ChatScreenMixin {
// replace the text before the Fabric Command API executes it,
// but ensure the message is added to the history in its raw form.
@ModifyVariable(method = "handleChatInput", at = @At(value = "INVOKE", target = "Ljava/lang/String;startsWith(Ljava/lang/String;)Z", remap = false), argsOnly = true)
private String onHandleChatInput(String message) {
String command = VarCommand.replaceVariables(message);
@ModifyReceiver(method = "handleChatInput", at = @At(value = "INVOKE", target = "Ljava/lang/String;startsWith(Ljava/lang/String;)Z", remap = false))
private String onHandleChatInput(String instance, String slash, @Local(argsOnly = true) LocalRef<String> message) {
String prefix = Configs.autoPrefix;
if (prefix.isEmpty() || instance.startsWith("/")) {
prefix = "";
} else {
prefix = prefix + " ";
}

String command = VarCommand.replaceVariables(prefix + instance);
if (command.startsWith("/")) {
ClientCommands.sendCommandExecutionToServer(command.substring(1));
}

message.set(command);
return command;
}
}

0 comments on commit b751737

Please sign in to comment.