electrodynamics/electrical/src/main/scala/resonantinduction/electrical/encoder/coding/args/ArgumentDoubleData.java
2014-03-23 17:19:47 +08:00

41 lines
979 B
Java

package resonantinduction.electrical.encoder.coding.args;
import net.minecraft.util.MathHelper;
import resonantinduction.core.ArgumentData;
import universalelectricity.api.energy.UnitDisplay;
/**
* Used to create argument data for the encoder. Should only be used if the value needs to be
* clearly limited inside the encoder display.
*
* @author DarkGuardsman
*/
public class ArgumentDoubleData extends ArgumentData
{
protected double max, min;
public ArgumentDoubleData(String name, double value, double max, double min)
{
super(name, value);
this.max = max;
this.min = min;
}
@Override
public boolean isValid(Object object)
{
if (super.isValid())
{
double value = MathHelper.parseDoubleWithDefault("" + object, min - 100);
return value != min - 100 && value >= min && value <= max;
}
return false;
}
@Override
public String warning()
{
return "" + UnitDisplay.roundDecimals(min, 2) + " - " + UnitDisplay.roundDecimals(max, 2);
}
}