mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-16 09:15:10 +01:00
- 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!
30 lines
1.1 KiB
Java
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());
|
|
}
|
|
}
|