Files
MidnightLib/src/main/java/eu/midnightdust/lib/config/MidnightSliderWidget.java
Martin Prokoph 8138e17b42 dev: switch to stonecutter build system
- This will allow us to build the library for different Minecraft versions at the same time
- Right now, only Fabric and Neoforge 1.21.10 are fully working
- As a bonus, the jar is now even smaller!
2025-11-04 22:21:15 +01:00

30 lines
1.1 KiB
Java

package eu.midnightdust.lib.config;
import net.minecraft.client.gui.components.AbstractSliderButton;
import net.minecraft.network.chat.Component;
public class MidnightSliderWidget extends AbstractSliderButton {
private final EntryInfo info;
private final MidnightConfig.Entry e;
public MidnightSliderWidget(int x, int y, int width, int height, Component text, double value, EntryInfo info) {
super(x, y, width, height, text, value);
this.e = info.entry;
this.info = info;
}
@Override
public void updateMessage() {
this.setMessage(Component.nullToEmpty(info.tempValue));
}
@Override
public void applyValue() {
if (info.dataType == int.class) info.setValue(((Number) (e.min() + value * (e.max() - e.min()))).intValue());
else if (info.dataType == double.class)
info.setValue(Math.round((e.min() + value * (e.max() - e.min())) * (double) e.precision()) / (double) e.precision());
else if (info.dataType == float.class)
info.setValue(Math.round((e.min() + value * (e.max() - e.min())) * (float) e.precision()) / (float) e.precision());
}
}