electrodynamics/src/main/java/resonantinduction/electrical/encoder/coding/args/ArgumentData.java

81 lines
1.5 KiB
Java
Raw Normal View History

2014-01-11 06:59:55 +01:00
package resonantinduction.electrical.encoder.coding.args;
import net.minecraft.nbt.NBTTagCompound;
2014-01-14 11:20:10 +01:00
import calclavia.lib.utility.nbt.ISaveObj;
import calclavia.lib.utility.nbt.NBTUtility;
2014-01-08 15:18:24 +01:00
/**
* Used to store arguments in a way that can be easier to read, limit, and understand
*
2014-01-08 15:18:24 +01:00
* @author DarkGuardsman
*/
public class ArgumentData implements ISaveObj
{
2014-01-08 15:18:24 +01:00
protected String name;
protected Object currentValue;
protected final Object defaultValue;
2014-01-08 15:18:24 +01:00
public ArgumentData(String name, Object defaultValue)
{
this.name = name;
this.defaultValue = defaultValue;
this.currentValue = defaultValue;
}
2014-01-08 15:18:24 +01:00
/**
* Sets the value
*
* @return true if the value was accepted
*/
public boolean setData(Object object)
{
if (this.isValid(object))
{
this.currentValue = object;
return true;
}
return false;
}
2014-01-08 15:18:24 +01:00
/** Gets the value of the stored data */
public Object getData()
{
return this.currentValue;
}
2014-01-08 15:18:24 +01:00
public String getName()
{
return this.name;
}
2014-01-08 15:18:24 +01:00
public boolean isValid(Object object)
{
return object != null;
}
2014-01-08 15:18:24 +01:00
/** Is this argument valid. */
public boolean isValid()
{
return true;
}
2014-01-08 15:18:24 +01:00
/** Used by things like a gui to give a warning such as limits of data this can accept */
public String warning()
{
return "";
}
2014-01-08 15:18:24 +01:00
@Override
public void save(NBTTagCompound nbt)
{
NBTUtility.saveObject(nbt, "ObjectData", this.currentValue);
2014-01-08 15:18:24 +01:00
}
2014-01-08 15:18:24 +01:00
@Override
public void load(NBTTagCompound nbt)
{
this.currentValue = NBTUtility.loadObject(nbt, "ObjectData");
2014-01-08 15:18:24 +01:00
}
}