Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ maven_group = tools.redstone
archives_base_name = redstonetools

loader_version=0.16.10
mod_version = v3.1.1
mod_version = v3.1.2

minecraft_version=1.21.8
minecraft_version_out=1.21.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public static class Toggles {
}

public static class ClientData {
public static final ConfigBoolean ENABLE_MATH_VARIABLES = new ConfigBoolean("Enable math and variables for the chat input suggester", true,
"""
Whether or not to try to inject variables and math expressions into the command input suggester.

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.
With this disabled, variables and math expressions will still be inserted upon sending a chat command""");
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");
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");
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.");
Expand All @@ -68,6 +74,7 @@ public static class ClientData {
public static final List<IConfigBase> OPTIONS = new ArrayList<>();

static {
OPTIONS.add(ENABLE_MATH_VARIABLES);
OPTIONS.add(VARIABLE_BEGIN_STRING);
OPTIONS.add(VARIABLE_END_STRING);
OPTIONS.add(MATH_BEGIN_STRING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import tools.redstone.redstonetools.malilib.config.Configs;
import tools.redstone.redstonetools.utils.StringUtils;

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

@Unique
private boolean justEntered;
@Unique
private int cursor;
@Unique
private int lastCursor;

@Inject(method = "refresh", at = @At("HEAD"), cancellable = true)
@Inject(method = "refresh", at = @At("HEAD"))
private void meowww(CallbackInfo ci) {
if (justEntered) {
ci.cancel();
return;
}
justEntered = true;
cursor = textField.getCursor();
if (!Configs.ClientData.ENABLE_MATH_VARIABLES.getBooleanValue()) return;
unmodifiedCommand.add(textField.getText());
textField.setText(StringUtils.insertVariablesAndMath(textField.getText()));
((TextFieldAccessor)textField).setText2(StringUtils.insertVariablesAndMath(textField.getText()));
}

@Inject(method = "refresh", at = @At("RETURN"))
private void mrawww(CallbackInfo ci) {
textField.setText(unmodifiedCommand.getLast());
if (lastCursor != cursor) {
textField.setCursor(cursor, false);
}
if (!Configs.ClientData.ENABLE_MATH_VARIABLES.getBooleanValue()) return;
((TextFieldAccessor)textField).setText2(unmodifiedCommand.getLast());
unmodifiedCommand.removeLast();
justEntered = false;
lastCursor = textField.getCursor();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package tools.redstone.redstonetools.mixin.features;

import net.minecraft.client.gui.widget.TextFieldWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(TextFieldWidget.class)
public interface TextFieldAccessor {
@Accessor(value = "text")
void setText2(String s);
}
1 change: 1 addition & 0 deletions src/client/resources/redstonetools.client.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"features.CommandSourceMixin",
"features.ItemBindItemStackMixin",
"features.SuggestionWindowMixin",
"features.TextFieldAccessor",
"features.WorldRendererInvoker",
"macros.AddMacroButtonMixin",
"macros.InitializeMacroManagerMixin"
Expand Down