use of org.spongepowered.api.util.weighted.VariableAmount in project SpongeCommon by SpongePowered.
the class OptionalVarianceBuilder method buildContent.
@Override
protected Optional<VariableAmount.OptionalAmount> buildContent(DataView container) throws InvalidDataException {
if (!container.contains(Queries.VARIABLE_BASE, Queries.VARIABLE_VARIANCE, Queries.VARIABLE_CHANCE)) {
return Optional.empty();
}
final double base = container.getInt(Queries.VARIABLE_BASE).get();
final double chance = container.getDouble(Queries.VARIABLE_CHANCE).get();
final VariableAmount amount = container.getSerializable(Queries.VARIABLE_VARIANCE, VariableAmount.class).get();
return Optional.of((VariableAmount.OptionalAmount) VariableAmount.baseWithOptionalVariance(base, amount, chance));
}
use of org.spongepowered.api.util.weighted.VariableAmount in project SpongeCommon by SpongePowered.
the class BaseAndAdditionBuilder method buildContent.
@Override
protected Optional<VariableAmount.BaseAndAddition> buildContent(DataView container) throws InvalidDataException {
if (!container.contains(Queries.VARIABLE_BASE, Queries.VARIABLE_VARIANCE)) {
return Optional.empty();
}
final int base = container.getInt(Queries.VARIABLE_BASE).get();
final VariableAmount amount = container.getSerializable(Queries.VARIABLE_VARIANCE, VariableAmount.class).get();
return Optional.of((VariableAmount.BaseAndAddition) VariableAmount.baseWithRandomAddition(base, amount));
}
use of org.spongepowered.api.util.weighted.VariableAmount in project SpongeCommon by SpongePowered.
the class BaseAndVarianceBuilder method buildContent.
@Override
protected Optional<VariableAmount.BaseAndVariance> buildContent(DataView container) throws InvalidDataException {
if (!container.contains(Queries.VARIABLE_BASE, Queries.VARIABLE_VARIANCE)) {
return Optional.empty();
}
final int base = container.getInt(Queries.VARIABLE_BASE).get();
final VariableAmount amount = container.getSerializable(Queries.VARIABLE_VARIANCE, VariableAmount.class).get();
return Optional.of((VariableAmount.BaseAndVariance) VariableAmount.baseWithVariance(base, amount));
}
Aggregations