Class ValueHelpers
java.lang.Object
org.cyclops.integrateddynamics.core.evaluate.variable.ValueHelpers
A collection of helpers for variables, values and value types.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areValuesEqual
(IValue v1, IValue v2) Check if the two given values are equal.static boolean
correspondsTo
(IValueType t1, IValueType t2) Bidirectional checking of correspondence.static boolean
correspondsTo
(IVariable<?> variable, IValueType type) Check if the variable corresponds to the given type.static net.minecraft.resources.ResourceLocation
Create a ResourceLocation from the given value.static IValue
deserialize
(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Deserialize the given NBT tag to a value.static <T extends IValue>
TdeserializeRaw
(ValueDeseralizationContext valueDeseralizationContext, IValueType<T> valueType, net.minecraft.nbt.Tag valueString) Deserialize the given value string to a value.static IValue
evaluateOperator
(IOperator operator, IValue... values) Evaluate an operator for the given values.static IValue
evaluateOperator
(IOperator operator, IVariable... variables) Evaluate an operator for the given variables.static net.minecraft.network.chat.Component[]
from
(IValueType<?>... valueTypes) Create a new unlocalized name array from the given variableFacades array element-wise.static IValueType[]
Create a new value type array from the given variable array element-wise.static IValueType<?>[]
from
(IVariableFacade... variableFacades) Create a new value type array from the given variableFacades array element-wise.static org.apache.commons.lang3.tuple.Pair<net.minecraft.network.chat.MutableComponent,
Integer> getSafeReadableValue
(IVariable variable) Get the human readable value of the given value in a safe way.static <T extends IValue>
TparseString
(IValueType<T> valueType, String value) Parse the given string representation of a value.static net.minecraft.nbt.CompoundTag
Serialize the given value to NBT.static net.minecraft.nbt.Tag
serializeRaw
(IValue value) Serialize the given value to a raw tag without its value type.toString
(T value) Get the string representation of the given value.static void
validatePredicateOutput
(IOperator predicate, IValue result) Check if the given result (from the given operator) is a boolean.static <V extends IValue,
C extends IValueType<V>>
CvariableUnpackAnyType
(IVariable variable, IOperator operator, IValueTypeCategory<V> category, Class<? super C> categoryClazz) If the given variable has type ANY, attempt to cast the type to the given category type, or throw.
-
Constructor Details
-
ValueHelpers
public ValueHelpers()
-
-
Method Details
-
from
Create a new value type array from the given variable array element-wise. If a variable would be null, that corresponding value type would be null as well.- Parameters:
variables
- The variables.- Returns:
- The value types array corresponding element-wise to the variables array.
-
from
Create a new value type array from the given variableFacades array element-wise. If a variableFacade would be null, that corresponding value type would be null as well.- Parameters:
variableFacades
- The variables facades.- Returns:
- The value types array corresponding element-wise to the variables array.
-
from
Create a new unlocalized name array from the given variableFacades array element-wise.- Parameters:
valueTypes
- The value types.- Returns:
- The unlocalized names array corresponding element-wise to the value types array.
-
areValuesEqual
Check if the two given values are equal. If they are both null, they are also considered equal.- Parameters:
v1
- Value onev2
- Value two- Returns:
- If they are equal.
-
correspondsTo
Bidirectional checking of correspondence.- Parameters:
t1
- First type.t2
- Second type.- Returns:
- If they correspond to each other in some direction.
-
correspondsTo
Check if the variable corresponds to the given type.- Parameters:
variable
- Variable.type
- First type.- Returns:
- If they correspond to each.
-
evaluateOperator
public static IValue evaluateOperator(IOperator operator, IValue... values) throws EvaluationException Evaluate an operator for the given values.- Parameters:
operator
- The operator.values
- The values.- Returns:
- The resulting value.
- Throws:
EvaluationException
- If something went wrong during operator evaluation.
-
evaluateOperator
public static IValue evaluateOperator(IOperator operator, IVariable... variables) throws EvaluationException Evaluate an operator for the given variables.- Parameters:
operator
- The operator.variables
- The variables.- Returns:
- The resulting value.
- Throws:
EvaluationException
- If something went wrong during operator evaluation.
-
serializeRaw
Serialize the given value to a raw tag without its value type.- Parameters:
value
- The value.- Returns:
- The NBT tag.
-
serialize
Serialize the given value to NBT.- Parameters:
value
- The value.- Returns:
- The NBT tag.
-
deserialize
public static IValue deserialize(ValueDeseralizationContext valueDeseralizationContext, net.minecraft.nbt.CompoundTag tag) Deserialize the given NBT tag to a value.- Parameters:
valueDeseralizationContext
- The deserialization context.tag
- The NBT tag containing a value.- Returns:
- The value.
-
deserializeRaw
public static <T extends IValue> T deserializeRaw(ValueDeseralizationContext valueDeseralizationContext, IValueType<T> valueType, net.minecraft.nbt.Tag valueString) Deserialize the given value string to a value.- Type Parameters:
T
- The type of value.- Parameters:
valueDeseralizationContext
- The deserialization context.valueType
- The value type to deserialize for.valueString
- The value tag.- Returns:
- The value.
-
toString
Get the string representation of the given value. This is useful for cases when the value needs to be edited in a GUI. This corresponds toparseString(IValueType, String)
.- Type Parameters:
T
- The value type.- Parameters:
value
- A value.- Returns:
- A string representation of the given value.
-
parseString
public static <T extends IValue> T parseString(IValueType<T> valueType, String value) throws EvaluationException Parse the given string representation of a value. This corresponds totoString(IValue)
.- Type Parameters:
T
- The value type.- Parameters:
valueType
- The value type to parse by.value
- A string representation of a value.- Returns:
- A value.
- Throws:
EvaluationException
- If parsing failed.
-
validatePredicateOutput
public static void validatePredicateOutput(IOperator predicate, IValue result) throws EvaluationException Check if the given result (from the given operator) is a boolean.- Parameters:
predicate
- A predicate, used for error logging.result
- A result from the given predicate- Throws:
EvaluationException
- If the value was not a boolean.
-
getSafeReadableValue
public static org.apache.commons.lang3.tuple.Pair<net.minecraft.network.chat.MutableComponent,Integer> getSafeReadableValue(@Nullable IVariable variable) Get the human readable value of the given value in a safe way.- Parameters:
variable
- A nullable variable.- Returns:
- A pair of a string and color.
-
createResourceLocationInEvaluation
public static net.minecraft.resources.ResourceLocation createResourceLocationInEvaluation(String value) throws EvaluationException Create a ResourceLocation from the given value. Any ResourceLocationExceptions will be emitted as EvaluationException.- Parameters:
value
- A ResourceLocation value.- Returns:
- A ResourceLocation
- Throws:
EvaluationException
- If a ResourceLocationException was thrown.
-
variableUnpackAnyType
public static <V extends IValue,C extends IValueType<V>> C variableUnpackAnyType(IVariable variable, IOperator operator, IValueTypeCategory<V> category, Class<? super C> categoryClazz) throws EvaluationException If the given variable has type ANY, attempt to cast the type to the given category type, or throw.- Type Parameters:
V
- The value type.C
- The category type.- Parameters:
variable
- The variable.operator
- An operator to include in the error message.category
- The category to check.categoryClazz
- The category class.- Returns:
- The cast value type.
- Throws:
EvaluationException
- If casting failed.
-