public class MaxHealthValueProcessor extends AbstractSpongeValueProcessor<Double,org.spongepowered.api.data.value.mutable.MutableBoundedValue<Double>>
Constructor and Description |
---|
MaxHealthValueProcessor() |
Modifier and Type | Method and Description |
---|---|
org.spongepowered.api.data.value.mutable.MutableBoundedValue<Double> |
constructValue(Double defaultValue)
Builds a
Value of the type produced by this processor from an
input, actual value. |
Optional<Double> |
getValueFromContainer(org.spongepowered.api.data.value.ValueContainer<?> container)
Gets the underlying value as an
Optional . |
org.spongepowered.api.data.DataTransactionResult |
offerToStore(org.spongepowered.api.data.value.ValueContainer<?> container,
Double value)
Offers the provided
BaseValue containing a value of the
appropriate value type of this ValueProcessor to offer
back to the ValueContainer . |
org.spongepowered.api.data.DataTransactionResult |
removeFrom(org.spongepowered.api.data.value.ValueContainer<?> container)
Attempts to remove the known keyed data associated with this
ValueProcessor from the provided ValueContainer . |
boolean |
supports(org.spongepowered.api.data.value.ValueContainer<?> container)
Checks if the provided
ValueContainer is compatible with the
value of data associated with this ValueProcessor . |
getApiValueFromContainer, getKey, getPriority
public org.spongepowered.api.data.value.mutable.MutableBoundedValue<Double> constructValue(Double defaultValue)
AbstractSpongeValueProcessor
Value
of the type produced by this processor from an
input, actual value.constructValue
in class AbstractSpongeValueProcessor<Double,org.spongepowered.api.data.value.mutable.MutableBoundedValue<Double>>
defaultValue
- The actual valueValue
public Optional<Double> getValueFromContainer(org.spongepowered.api.data.value.ValueContainer<?> container)
ValueProcessor
Optional
. This is the direct
implementation of ValueContainer.get(Key)
. As well, since the
return type is Optional
, this method too is applicable for
ValueContainer.getOrNull(Key)
and
ValueContainer.getOrElse(Key, Object)
as they are simply
additional methods called from Optional.orNull()
and
Optional.or(Object)
.
To truly understand the use of this method, the thought process
is that a ValueContainer
being mixed in to existing minecraft
classes will require a pseudo lookup of the Key
to associate to
a field belonging to provided ValueContainer
. Being that the
Value
is very specific, the only assumption of mixed in
implementations will have no room for extra possibilities. Therefor,
this method serves as a "guarantee" that we've found the type of
Value
we want to retrieve, and all we need to do is validate
that the Value
is infact compatible with the provided
ValueContainer
.
An example of this type of interaction is getting the health from an
Entity
. Normally, when you have an Entity
, you can
grab health two ways:
entity.get(Keys.HEALTH)
entity.get(HealthData.class).health()
ValueContainer.get(Key)
will result in a call to this method for a
ValueProcessor
handling specifically the health value. The
second case will use the same ValueProcessor
but be retrieving
the values directly from the HealthData
DataManipulator
.
This differs with object creation as the second method will result in an
unecessary DataManipulator
to be created, and then finally a
ValueProcessor
method call for the DataManipulator
instead of the Entity
having a direct call.
The cases where this type of value usage is not preferable is with
more complex Value
s, such as CollectionValue
,
values found for MobSpawnerData
and CommandData
. Using
the ValueContainer.get(Key)
and
DataManipulator.set(Key, Object)
remains to be the optimal methods
to use as they do not rely on the implementation attempting to guess which
Key
, Value
and ValueProcessor
is needed to
manipulate the data.
container
- The value container to retrieve the value fromspublic boolean supports(org.spongepowered.api.data.value.ValueContainer<?> container)
ValueProcessor
ValueContainer
is compatible with the
value of data associated with this ValueProcessor
.container
- The value container to checkpublic org.spongepowered.api.data.DataTransactionResult offerToStore(org.spongepowered.api.data.value.ValueContainer<?> container, Double value)
ValueProcessor
BaseValue
containing a value of the
appropriate value type of this ValueProcessor
to offer
back to the ValueContainer
.container
- The value containervalue
- The valuepublic org.spongepowered.api.data.DataTransactionResult removeFrom(org.spongepowered.api.data.value.ValueContainer<?> container)
ValueProcessor
ValueProcessor
from the provided ValueContainer
. If
the result is not possible, the result will be an expected
DataTransactionResult.Type.FAILURE
.container
- The value container to remove data from