43 lines
1.1 KiB
Java
43 lines
1.1 KiB
Java
|
package io.gitlab.jfronny.slyde.mixin;
|
||
|
|
||
|
import net.minecraft.client.options.DoubleOption;
|
||
|
import net.minecraft.util.math.MathHelper;
|
||
|
import org.spongepowered.asm.mixin.Final;
|
||
|
import org.spongepowered.asm.mixin.Mixin;
|
||
|
import org.spongepowered.asm.mixin.Overwrite;
|
||
|
import org.spongepowered.asm.mixin.Shadow;
|
||
|
|
||
|
@Mixin(DoubleOption.class)
|
||
|
public class DoubleOptionMixin {
|
||
|
@Shadow @Final protected float step;
|
||
|
|
||
|
@Shadow @Final protected double min;
|
||
|
|
||
|
@Shadow protected double max;
|
||
|
|
||
|
/**
|
||
|
* @author JFronny
|
||
|
*/
|
||
|
@Overwrite
|
||
|
public double getRatio(double value) {
|
||
|
return (this.adjust(value) - this.min) / (this.max - this.min);
|
||
|
}
|
||
|
/**
|
||
|
* @author JFronny
|
||
|
*/
|
||
|
@Overwrite
|
||
|
public double getValue(double ratio) {
|
||
|
return this.adjust(MathHelper.lerp(ratio, this.min, this.max));
|
||
|
}
|
||
|
/**
|
||
|
* @author JFronny
|
||
|
*/
|
||
|
@Overwrite
|
||
|
private double adjust(double value) {
|
||
|
if (this.step > 0.0F) {
|
||
|
value = this.step * (float)Math.round(value / (double)this.step);
|
||
|
}
|
||
|
return value;
|
||
|
}
|
||
|
}
|