Skip to content

Commit dd8c382

Browse files
authored
Merge pull request #403 from RedstoneTools/dev
v3.1.2
2 parents 5e606dd + 9a8af92 commit dd8c382

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ maven_group = tools.redstone
66
archives_base_name = redstonetools
77

88
loader_version=0.16.10
9-
mod_version = v3.1.1
9+
mod_version = v3.1.2
1010

1111
minecraft_version=1.21.8
1212
minecraft_version_out=1.21.8

src/client/java/tools/redstone/redstonetools/malilib/config/Configs.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public static class Toggles {
5757
}
5858

5959
public static class ClientData {
60+
public static final ConfigBoolean ENABLE_MATH_VARIABLES = new ConfigBoolean("Enable math and variables for the chat input suggester", true,
61+
"""
62+
Whether or not to try to inject variables and math expressions into the command input suggester.
63+
64+
With this enabled, Redstone tools will attempt to prevent chat suggestion from breaking if you're using variables and or math expressions inside of a command.
65+
With this disabled, variables and math expressions will still be inserted upon sending a chat command""");
6066
public static final ConfigString VARIABLE_BEGIN_STRING = new ConfigString("Variable begin string", "'", "The string that should be used to denote the start of a variable. Can be empty");
6167
public static final ConfigString VARIABLE_END_STRING = new ConfigString("Variable end string", "'", "The string that should be used to denote the end of a variable. Can be empty");
6268
public static final ConfigString MATH_BEGIN_STRING = new ConfigString("Math begin string", "{", "The string that should be used to denote the start of a math expression. Can be empty, unsure if you'd want that though.");
@@ -68,6 +74,7 @@ public static class ClientData {
6874
public static final List<IConfigBase> OPTIONS = new ArrayList<>();
6975

7076
static {
77+
OPTIONS.add(ENABLE_MATH_VARIABLES);
7178
OPTIONS.add(VARIABLE_BEGIN_STRING);
7279
OPTIONS.add(VARIABLE_END_STRING);
7380
OPTIONS.add(MATH_BEGIN_STRING);

src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggesterMixin.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import org.spongepowered.asm.mixin.Final;
66
import org.spongepowered.asm.mixin.Mixin;
77
import org.spongepowered.asm.mixin.Shadow;
8-
import org.spongepowered.asm.mixin.Unique;
98
import org.spongepowered.asm.mixin.injection.At;
109
import org.spongepowered.asm.mixin.injection.Inject;
1110
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
import tools.redstone.redstonetools.malilib.config.Configs;
1212
import tools.redstone.redstonetools.utils.StringUtils;
1313

1414
import static tools.redstone.redstonetools.utils.StringUtils.unmodifiedCommand;
@@ -19,33 +19,17 @@ public class ChatInputSuggesterMixin {
1919
@Shadow
2020
TextFieldWidget textField;
2121

22-
@Unique
23-
private boolean justEntered;
24-
@Unique
25-
private int cursor;
26-
@Unique
27-
private int lastCursor;
28-
29-
@Inject(method = "refresh", at = @At("HEAD"), cancellable = true)
22+
@Inject(method = "refresh", at = @At("HEAD"))
3023
private void meowww(CallbackInfo ci) {
31-
if (justEntered) {
32-
ci.cancel();
33-
return;
34-
}
35-
justEntered = true;
36-
cursor = textField.getCursor();
24+
if (!Configs.ClientData.ENABLE_MATH_VARIABLES.getBooleanValue()) return;
3725
unmodifiedCommand.add(textField.getText());
38-
textField.setText(StringUtils.insertVariablesAndMath(textField.getText()));
26+
((TextFieldAccessor)textField).setText2(StringUtils.insertVariablesAndMath(textField.getText()));
3927
}
4028

4129
@Inject(method = "refresh", at = @At("RETURN"))
4230
private void mrawww(CallbackInfo ci) {
43-
textField.setText(unmodifiedCommand.getLast());
44-
if (lastCursor != cursor) {
45-
textField.setCursor(cursor, false);
46-
}
31+
if (!Configs.ClientData.ENABLE_MATH_VARIABLES.getBooleanValue()) return;
32+
((TextFieldAccessor)textField).setText2(unmodifiedCommand.getLast());
4733
unmodifiedCommand.removeLast();
48-
justEntered = false;
49-
lastCursor = textField.getCursor();
5034
}
5135
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package tools.redstone.redstonetools.mixin.features;
2+
3+
import net.minecraft.client.gui.widget.TextFieldWidget;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.gen.Accessor;
6+
7+
@Mixin(TextFieldWidget.class)
8+
public interface TextFieldAccessor {
9+
@Accessor(value = "text")
10+
void setText2(String s);
11+
}

src/client/resources/redstonetools.client.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"features.CommandSourceMixin",
2828
"features.ItemBindItemStackMixin",
2929
"features.SuggestionWindowMixin",
30+
"features.TextFieldAccessor",
3031
"features.WorldRendererInvoker",
3132
"macros.AddMacroButtonMixin",
3233
"macros.InitializeMacroManagerMixin"

0 commit comments

Comments
 (0)