Fix wrong position calculation when min and max value are equal
This commit is contained in:
@@ -41,24 +41,21 @@ public class GuiSlider<T> extends GuiButton
|
||||
|
||||
private void initStorage(double min, double max, double start)
|
||||
{
|
||||
if(this.storage.getObject() == null || this.storage.getObject().getMin() != min || this.storage.getObject().getMax() != max)
|
||||
if(this.storage.getObject() == null)
|
||||
{
|
||||
if(this.storage.getObject() == null)
|
||||
if(min == max)
|
||||
{
|
||||
if(min == max)
|
||||
{
|
||||
this.storage.setObject(new SliderStorage(min, max, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.storage.setObject(new SliderStorage(min, max, (start - min) / (max - min)));
|
||||
}
|
||||
this.storage.setObject(new SliderStorage(min, max, 0.0D));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.storage.setObject(new SliderStorage(min, max, (int) MathHelper.clamp(this.getValue(), min, max)));
|
||||
this.storage.setObject(new SliderStorage(min, max, (start - min) / (max - min)));
|
||||
}
|
||||
}
|
||||
else if(this.storage.getObject().getMin() != min || this.storage.getObject().getMax() != max)
|
||||
{
|
||||
this.storage.setObject(new SliderStorage(min, max, (int) MathHelper.clamp(this.getValue(), min, max)));
|
||||
}
|
||||
}
|
||||
|
||||
private void setPosition(double position)
|
||||
|
||||
@@ -3,6 +3,7 @@ package exopandora.worldhandler.gui.button.storage;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class SliderStorage
|
||||
{
|
||||
@@ -10,17 +11,21 @@ public class SliderStorage
|
||||
private final double max;
|
||||
private double position;
|
||||
|
||||
public SliderStorage(double min, double max, double position)
|
||||
private SliderStorage(double min, double max)
|
||||
{
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public SliderStorage(double min, double max, double position)
|
||||
{
|
||||
this(min, max);
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public SliderStorage(double min, double max, int value)
|
||||
{
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this(min, max);
|
||||
this.position = this.valueToPosition(value);
|
||||
}
|
||||
|
||||
@@ -56,6 +61,11 @@ public class SliderStorage
|
||||
|
||||
private double valueToPosition(int value)
|
||||
{
|
||||
if(this.min == this.max)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (value - this.min) / (this.max - this.min);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user