Search in sources :

Example 1 with VariableAmount

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));
}
Also used : VariableAmount(org.spongepowered.api.util.weighted.VariableAmount)

Example 2 with VariableAmount

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));
}
Also used : VariableAmount(org.spongepowered.api.util.weighted.VariableAmount)

Example 3 with VariableAmount

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));
}
Also used : VariableAmount(org.spongepowered.api.util.weighted.VariableAmount)

Aggregations

VariableAmount (org.spongepowered.api.util.weighted.VariableAmount)3