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)
|
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.0D));
|
||||||
{
|
|
||||||
this.storage.setObject(new SliderStorage(min, max, 0));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.storage.setObject(new SliderStorage(min, max, (start - min) / (max - min)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
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)
|
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.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class SliderStorage
|
public class SliderStorage
|
||||||
{
|
{
|
||||||
@@ -10,17 +11,21 @@ public class SliderStorage
|
|||||||
private final double max;
|
private final double max;
|
||||||
private double position;
|
private double position;
|
||||||
|
|
||||||
public SliderStorage(double min, double max, double position)
|
private SliderStorage(double min, double max)
|
||||||
{
|
{
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SliderStorage(double min, double max, double position)
|
||||||
|
{
|
||||||
|
this(min, max);
|
||||||
this.position = position;
|
this.position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SliderStorage(double min, double max, int value)
|
public SliderStorage(double min, double max, int value)
|
||||||
{
|
{
|
||||||
this.min = min;
|
this(min, max);
|
||||||
this.max = max;
|
|
||||||
this.position = this.valueToPosition(value);
|
this.position = this.valueToPosition(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +61,11 @@ public class SliderStorage
|
|||||||
|
|
||||||
private double valueToPosition(int value)
|
private double valueToPosition(int value)
|
||||||
{
|
{
|
||||||
|
if(this.min == this.max)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return (value - this.min) / (this.max - this.min);
|
return (value - this.min) / (this.max - this.min);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user