Skip to content

Commit

Permalink
Create custom TextFieldWidget to work with both 1.20.0 and 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinrobot committed Jun 29, 2024
1 parent 303c85a commit af37118
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
root = true

[*]
end_of_line = lf
indent_size = 4
indent_style = tab
insert_final_newline = true
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {

// WebP support for animated WebP using official Google's native library
modClientImplementation "com.github.Vinrobot.WebPDecoderJN:lib:${project.webpdecoderjn_version}"
include "com.github.Vinrobot.WebPDecoderJN:lib:${rootProject.webpdecoderjn_version}"
include "com.github.Vinrobot.WebPDecoderJN:lib:${project.webpdecoderjn_version}"

modImplementation "org.apache.httpcomponents:httpclient-cache:${project.httpcomponents_version}"
include "org.apache.httpcomponents:httpclient-cache:${project.httpcomponents_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;
import net.vinrobot.mcemote.config.Configuration;
Expand All @@ -24,7 +23,7 @@ public class ConfigurationScreen extends BaseScreen {
private final ConfigurationManager configManager;

private ButtonWidget doneButton;
private TextFieldWidget twitchIdField;
private CustomTextFieldWidget twitchIdField;
private SliderFieldWidget emoteScalingField;

public ConfigurationScreen(final Screen parent, final ConfigurationManager configManager) {
Expand All @@ -45,7 +44,7 @@ protected void init() {
final int widgetX = (this.width - widgetWidth) / 2;
final Configuration config = this.configManager.getConfig();

this.twitchIdField = new TextFieldWidget(this.textRenderer, widgetX, 75, widgetWidth, widgetHeight, TWITCH_ID_LABEL);
this.twitchIdField = new CustomTextFieldWidget(this.textRenderer, widgetX, 75, widgetWidth, widgetHeight, TWITCH_ID_LABEL);
this.twitchIdField.setMaxLength(32);
this.twitchIdField.setText(config.twitchId().get());
this.twitchIdField.setChangedListener((value) -> this.validateInputs());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.vinrobot.mcemote.client.widget;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.text.Text;

public class CustomTextFieldWidget extends TextFieldWidget {
private final Runnable tickMethod;

public CustomTextFieldWidget(final TextRenderer textRenderer, final int x, final int y, final int width, final int height, final Text text) {
super(textRenderer, x, y, width, height, text);
this.tickMethod = getTickMethod();
}

public void tick() {
this.tickMethod.run();
}

private Runnable getTickMethod() {
try {
super.tick();
return () -> super.tick();
} catch (final NoSuchMethodError e) {
e.printStackTrace();
return () -> {
};
}
}
}

0 comments on commit af37118

Please sign in to comment.