Interface ConfigValue
- All Superinterfaces:
ConfigTag
- All Known Implementing Classes:
ConfigValueImpl
ConfigTag with a value
of a specific type.
Created by covers1624 on 17/4/22.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanGets thebooleanvalue of this tag.booleanGets the defaultbooleanvalue of this tag.doubleGets the defaultdoublevalue of this tag.intGets the defaultintvalue stored as a Hex String of this tag.intGets the defaultintvalue of this tag.longGets the defaultlongvalue of this tag.Gets the defaultStringvalue of this tag.doubleGets thedoublevalue of this tag.intgetHex()Gets theintvalue stored as a Hex String of this tag.intgetInt()Gets theintvalue of this tag.longgetLong()Gets thelongvalue of this tag.@Nullable RestrictionGets theRestrictionpredicate for this tag.Gets theStringvalue of this tag.getType()Gets the type of theConfigValue.onSync(ConfigCallback<ConfigValue> callback) Called when this tag, or any children, are modified.setBoolean(boolean value) Sets thebooleanvalue of this tag.setComment(String comment) Sets the comment for this tag.
Will be split on\n.setComment(String... comment) Sets the comment for this tag.setComment(List<String> comment) Sets the comment for this tag.setDefaultBoolean(boolean value) Sets the defaultbooleanvalue of this tag.setDefaultDouble(double value) Sets the defaultdoublevalue of this tag.setDefaultHex(int value) Sets the defaultintvalue represented as a hex String of this tag.setDefaultInt(int value) Sets the defaultintvalue of this tag.setDefaultLong(long value) Sets the defaultlongvalue of this tag.setDefaultString(String value) Sets the defaultStringvalue of this tag.setDouble(double value) Sets thedoublevalue of this tag.setHex(int value) Sets theintvalue represented as a hex String of this tag.setInt(int value) Sets theintvalue of this tag.setLong(long value) Sets thelongvalue of this tag.setRestriction(Restriction restriction) Set theRestrictionfor thisConfigValue.Sets theStringvalue of this tag.Sets this tag as requiring syncing to the client.Methods inherited from interface codechicken.lib.config.ConfigTag
copy, delete, forceSync, getComment, getDesc, getName, getParent, isDirty, isNetworkTag, read, requiresClientSync, reset, resetFromNetwork, runSync, save, write
-
Method Details
-
getType
ValueType getType()Gets the type of theConfigValue.- Returns:
- The
ValueTypeof this tag.
-
getBoolean
boolean getBoolean()Gets thebooleanvalue of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The boolean value or the default.
- Throws:
IllegalStateException- If thegetType()is notValueType.BOOLEAN, or in the event of a missing value, no default is set.
-
getString
String getString()Gets theStringvalue of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The String value or the default.
- Throws:
IllegalStateException- If thegetType()is notValueType.STRING, or in the event of a missing value, no default is set.
-
getInt
int getInt()Gets theintvalue of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The int value or the default.
- Throws:
IllegalStateException- If thegetType()is notValueType.INT, or in the event of a missing value, no default is set.
-
getLong
long getLong()Gets thelongvalue of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The long value or the default.
- Throws:
IllegalStateException- If thegetType()is notValueType.LONG, or in the event of a missing value, no default is set.
-
getHex
int getHex()Gets theintvalue stored as a Hex String of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The int value or the default.
- Throws:
IllegalStateException- If thegetType()is notValueType.HEX, or in the event of a missing value, no default is set.
-
getDouble
double getDouble()Gets thedoublevalue of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The double value or the default.
- Throws:
IllegalStateException- If thegetType()is notValueType.DOUBLE, or in the event of a missing value, no default is set.
-
setBoolean
Sets thebooleanvalue of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- Thebooleanvalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.BOOLEAN.
-
setString
Sets theStringvalue of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- TheStringvalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.STRING.
-
setInt
Sets theintvalue of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- Theintvalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.INT.
-
setLong
Sets thelongvalue of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- Thelongvalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.LONG.
-
setHex
Sets theintvalue represented as a hex String of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- Theintvalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.HEX.
-
setDouble
Sets thedoublevalue of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- Thedoublevalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.DOUBLE.
-
getDefaultBoolean
boolean getDefaultBoolean()Gets the defaultbooleanvalue of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The default boolean value.
- Throws:
IllegalStateException- If thegetType()is notValueType.BOOLEAN, or when no default is set.
-
getDefaultString
String getDefaultString()Gets the defaultStringvalue of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The default
Stringvalue. - Throws:
IllegalStateException- If thegetType()is notValueType.STRING, or when no default is set.
-
getDefaultInt
int getDefaultInt()Gets the defaultintvalue of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The default int value.
- Throws:
IllegalStateException- If thegetType()is notValueType.INT, or when no default is set.
-
getDefaultLong
long getDefaultLong()Gets the defaultlongvalue of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The default long value.
- Throws:
IllegalStateException- If thegetType()is notValueType.LONG, or when no default is set.
-
getDefaultHex
int getDefaultHex()Gets the defaultintvalue stored as a Hex String of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The default int value.
- Throws:
IllegalStateException- If thegetType()is notValueType.HEX, or when no default is set.
-
getDefaultDouble
double getDefaultDouble()Gets the defaultdoublevalue of this tag.No attempt to convert between tag types is made, this must be called on a tag which has a non
ValueType.UNKNOWNtype.- Returns:
- The default double value.
- Throws:
IllegalStateException- If thegetType()is notValueType.DOUBLE, or when no default is set.
-
setDefaultBoolean
Sets the defaultbooleanvalue of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- Thebooleanvalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.BOOLEAN.
-
setDefaultString
Sets the defaultStringvalue of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- TheStringvalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.STRING.
-
setDefaultInt
Sets the defaultintvalue of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- Theintvalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.INT.
-
setDefaultLong
Sets the defaultlongvalue of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- Thelongvalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.LONG.
-
setDefaultHex
Sets the defaultintvalue represented as a hex String of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- Theintvalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.HEX.
-
setDefaultDouble
Sets the defaultdoublevalue of this tag.If the tag has an
ValueType.UNKNOWNvalue type, this function will set it appropriately.- Parameters:
value- Thedoublevalue.- Returns:
- The same
ConfigValue. - Throws:
IllegalStateException- If thegetType()is notValueType.UNKNOWNorValueType.DOUBLE.
-
setRestriction
Set theRestrictionfor thisConfigValue.A restriction is just a
Predicate, and can be used for anything, but is most commonly used for int/float value ranges on tags.If the restriction is violated, either by the tag being loaded from disk, or via a set method, it will be reset to default.
TODO, in the future, provide a function to choose what to do when a value is invalid, allow the value to be altered (clamped), removed, or reset entirely to default. It is invalid for the restriction to not accept the tag's default value, if the restriction does not, it will throw an
IllegalArgumentExceptioneither when the restriction is set, or the default is set, whichever comes last.See
Restrictionfor more information.- Parameters:
restriction- The restriction to set.- Returns:
- The same
ConfigValue. - See Also:
-
getRestriction
Gets theRestrictionpredicate for this tag.- Returns:
- The
Restriction
-
syncTagToClient
ConfigValue syncTagToClient()Sets this tag as requiring syncing to the client.Register your root tag via
ConfigSyncManager.registerSync(ResourceLocation, ConfigTag).- Specified by:
syncTagToClientin interfaceConfigTag
-
onSync
Called when this tag, or any children, are modified.This is commonly used for when tags are synced to the client and inversely, reverted when disconnecting.
Additionally, one can manually fire all sync callbacks using
ConfigTag.forceSync()See
ConfigCallbackfor more info.- Parameters:
callback- TheConfigCallback.- Returns:
- The same
ConfigValue. - See Also:
-
setComment
Sets the comment for this tag.
Will be split on\n.- Specified by:
setCommentin interfaceConfigTag- Parameters:
comment- The comment line.- Returns:
- The same config tag.
-
setComment
Sets the comment for this tag.- Specified by:
setCommentin interfaceConfigTag- Parameters:
comment- The comment lines.- Returns:
- The same config tag.
-
setComment
Sets the comment for this tag.- Specified by:
setCommentin interfaceConfigTag- Parameters:
comment- The comment lines.- Returns:
- The same config tag.
-