Skip to content

Commit e56dc95

Browse files
committed
fix: small changes for 1.21.11
1 parent 8e0079c commit e56dc95

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

common/src/client/java/io/github/jamalam360/jamlib/client/config/gui/entry/ConfigEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public ConfigEntry(String modId, String configName, ConfigField<T, V> field) {
7171
public List<AbstractWidget> createWidgets(int width) {
7272
List<AbstractWidget> widgets = new ArrayList<>();
7373

74-
StringWidget title = new StringWidget(12, Minecraft.getInstance().font.lineHeight / 2 + 1, width / 2 - 10, Minecraft.getInstance().font.lineHeight, Component.translatable(this.translationKey), Minecraft.getInstance().font);
74+
StringWidget title = new StringWidget(12, Minecraft.getInstance().font.lineHeight / 2 + 1, width / 2 - 10, Minecraft.getInstance().font.lineHeight, Component.translatable(this.translationKey), Minecraft.getInstance().font).setMaxWidth(width / 2 - 10, StringWidget.TextOverflow.SCROLLING);
7575

7676
if (this.tooltip != null) {
7777
title.setTooltip(Tooltip.create(this.tooltip));

common/src/client/java/io/github/jamalam360/jamlib/client/config/gui/entry/NumberConfigEntry.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public List<AbstractWidget> createElementWidgets(int left, int width) {
5656
current = range.min();
5757
}
5858

59+
//noinspection unchecked
5960
this.slider = new SliderButton(
6061
left,
6162
0,
@@ -65,11 +66,8 @@ public List<AbstractWidget> createElementWidgets(int left, int width) {
6566
range.min(),
6667
range.max(),
6768
current.doubleValue(),
68-
value -> {
69-
//noinspection unchecked
70-
this.setFieldValue((V) value);
71-
return this.getComponent(value);
72-
}
69+
value -> this.setFieldValue((V) value),
70+
this::getComponent
7371
);
7472
return List.of(this.slider);
7573
} else {
@@ -104,7 +102,7 @@ public void resetToDefault() {
104102
if (this.editBox != null) {
105103
this.editBox.setValue(DECIMAL_FORMAT.format(this.getFieldValue().doubleValue()));
106104
} else if (this.slider != null) {
107-
this.slider.setValue(this.getFieldValue().doubleValue());
105+
this.slider.updateValue(this.getFieldValue().doubleValue());
108106
}
109107
}
110108
}

common/src/client/java/io/github/jamalam360/jamlib/client/config/gui/entry/SliderButton.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,35 @@
44
import net.minecraft.network.chat.Component;
55
import net.minecraft.util.Mth;
66

7+
import java.util.function.Consumer;
78
import java.util.function.Function;
89

910
public class SliderButton extends AbstractSliderButton {
1011
private final double min;
1112
private final double max;
12-
private final Function<Double, Component> onChange;
13+
private final Consumer<Double> onChange;
14+
private final Function<Double, Component> toString;
1315

14-
protected SliderButton(int x, int y, int width, int height, Component message, double min, double max, double value, Function<Double, Component> onChange) {
15-
super(x, y, width, height, message, value);
16+
protected SliderButton(int x, int y, int width, int height, Component message, double min, double max, double value, Consumer<Double> onChange, Function<Double, Component> toString) {
17+
super(x, y, width, height, message, ((Mth.clamp((float) value, min, max) - min) / (max - min)));
1618
this.min = min;
1719
this.max = max;
1820
this.onChange = onChange;
19-
this.value = ((Mth.clamp((float) value, this.min, this.max) - this.min) / (this.max - this.min));
21+
this.toString = toString;
2022
}
2123

22-
public void setValue(double value) {
24+
public void updateValue(double value) {
2325
this.value = ((Mth.clamp((float) value, this.min, this.max) - this.min) / (this.max - this.min));
26+
this.updateMessage();
2427
}
2528

2629
@Override
2730
protected void updateMessage() {
31+
this.setMessage(this.toString.apply(Mth.lerp(Mth.clamp(this.value, 0.0F, 1.0F), this.min, this.max)));
2832
}
2933

3034
@Override
3135
protected void applyValue() {
32-
this.setMessage(this.onChange.apply(Mth.lerp(Mth.clamp(this.value, 0.0F, 1.0F), this.min, this.max)));
36+
this.onChange.accept(Mth.lerp(Mth.clamp(this.value, 0.0F, 1.0F), this.min, this.max));
3337
}
3438
}

0 commit comments

Comments
 (0)