Class ItemStackBuilderPopulators

java.lang.Object
org.spongepowered.api.item.inventory.ItemStackBuilderPopulators

public final class ItemStackBuilderPopulators extends Object
A factory for generating BiConsumers to apply to an ItemStack.Builder, usually through an ItemStackGenerator.

Note that the BiConsumers are expected to utilize the passed in Random and use the builder as necessary.

  • Method Details

    • itemStack

      public static BiConsumer<ItemStack.Builder,Random> itemStack(ItemStackSnapshot snapshot)
      Creates a new BiConsumer to set the ItemStack.Builder to use the provided ItemStackSnapshot as a "default". Note that the normal behavior of the builder is to reset according to the snapshot.
      Parameters:
      snapshot - The snapshot to set the builder to use
      Returns:
      The new biconsumer to apply to an itemstack builder
    • itemStacks

      public static BiConsumer<ItemStack.Builder,Random> itemStacks(ItemStackSnapshot snapshot, ItemStackSnapshot... snapshots)
      Creates a new BiConsumer that uses a randomized selection of the provided ItemStackSnapshots. The builder, when called will only use one at random selection to default to.
      Parameters:
      snapshot - The first snapshot
      snapshots - The additional snapshots
      Returns:
      The new biconsumer to apply to an itemstack builder
    • item

      public static BiConsumer<ItemStack.Builder,Random> item(ItemType itemType)
      Creates a new BiConsumer that defines the provided ItemType.
      Parameters:
      itemType - The given item type
      Returns:
      The new biconsumer to apply to an itemstack builder
    • item

      public static BiConsumer<ItemStack.Builder,Random> item(Supplier<? extends ItemType> supplier)
      Creates a new BiConsumer that defines the provided ItemType, provided that the Supplier does not return null.

      Note that the Supplier is not queried for an ItemType until the generated BiConsumer is called.

      Parameters:
      supplier - The supplier of the item type
      Returns:
      The new biconsumer to apply to an itemstack builder
    • items

      public static BiConsumer<ItemStack.Builder,Random> items(ItemType itemType, ItemType... itemTypes)
      Creates a new BiConsumer that provides a random ItemType of the provided item types.

      Note that the desired ItemType given to the builder is only defined at the time of calling BiConsumer.accept(Object, Object).

      Parameters:
      itemType - The first item type
      itemTypes - The additional item types
      Returns:
      The new biconsumer to apply to an item stack builder
    • items

      public static BiConsumer<ItemStack.Builder,Random> items(Collection<ItemType> itemTypes)
      Creates a new BiConsumer that provides a random ItemType from the provided collection of item types.
      Parameters:
      itemTypes - The item types to use
      Returns:
      The new biconsumer to apply to an itemstack builder
    • quantity

      public static BiConsumer<ItemStack.Builder,Random> quantity(VariableAmount amount)
      Creates a new BiConsumer that sets the desired quantity for creating an ItemStack.

      Note that the default behavior of the item stack builder is still expected to take place. Negative values are not allowed.

      Parameters:
      amount - The variable amount
      Returns:
      The new biconsumer to apply to an itemstack builder
    • quantity

      public static BiConsumer<ItemStack.Builder,Random> quantity(Supplier<VariableAmount> supplier)
      Creates a new BiConsumer that sets the desired quantity for creating an ItemStack. The supplier is not queried for a VariableAmount until the generated bi consumer is called on.

      Note that the default behavior of an item stack builder is still expected to take place. Negative values are not allowed.

      Parameters:
      supplier - The supplier of the variable amount
      Returns:
      The new biconsumer to apply to an itemstack builder
    • keyValue

      public static <E> BiConsumer<ItemStack.Builder,Random> keyValue(Key<? extends Value<E>> key, E value)
      Creates a new BiConsumer that sets the provided Key'ed object where the value is possibly ignored or not supported. No checks on whether the key or object is supported until called upon.

      Note that custom data is not supported through this method, use values(Iterable) or any variant thereof for applying custom data.

      Type Parameters:
      E - The type of value
      Parameters:
      key - The key to use
      value - The value to use
      Returns:
      The new biconsumer to apply to an itemstack builder
    • keyValues

      public static <E> BiConsumer<ItemStack.Builder,Random> keyValues(Key<? extends Value<E>> key, Iterable<E> values)
      Creates a new BiConsumer that sets a single provided value with the provided Key. Only a single value is chosen to provide to the itemstack builder.

      Note that custom data is not supported through this method, use values(Iterable) or any variant thereof for applying custom data.

      Type Parameters:
      E - The type of value
      Parameters:
      key - The key to use
      values - The pool of possible values
      Returns:
      The new biconsumer to apply to an itemstack builder
    • listValues

      public static <E> BiConsumer<ItemStack.Builder,Random> listValues(Key<? extends ListValue.Mutable<E>> key, List<E> elementPool, VariableAmount amount)
      Creates a new BiConsumer where the Key is responsible for a List based Value.Mutable. Given that the provided elements are chosen with a Random, it's not clear that the elements will be added in bundles or in the same iteration order.

      Note that custom data is not supported through this method, use values(Iterable) or any variant thereof for applying custom data.

      Type Parameters:
      E - The type of elements
      Parameters:
      key - The key to use
      elementPool - The pool of possible values
      amount - The variable amount of elements to add
      Returns:
      The new biconsumer to apply to an itemstack builder
    • listValues

      public static <E> BiConsumer<ItemStack.Builder,Random> listValues(Key<? extends ListValue.Mutable<E>> key, List<E> elementPool)
      Creates a new BiConsumer where the Key is responsible for a List based Value.Mutable. Given that the provided elements are chosen with a Random, it's not clear that the elements will be added in bundles or in the same iteration order. The default variance is provided as VariableAmount.baseWithRandomAddition(double, double) where at the least, a single element is chosen, and at most the entire collection is chosen.

      Note that custom data is not supported through this method, use values(Iterable) or any variant thereof for applying custom data.

      Type Parameters:
      E - The type of elements
      Parameters:
      key - The key to use
      elementPool - The pool of possible values
      Returns:
      The new biconsumer to apply to an itemstack builder
    • listValues

      public static <E> BiConsumer<ItemStack.Builder,Random> listValues(Key<? extends ListValue.Mutable<E>> key, WeightedTable<E> weightedTable)
      Creates a new BiConsumer where the Key is responsible for a List based Value.Mutable. Given the WeightedTable is already generated, the values requested are only retrieved when the generated biconsumer is called upon.

      Note that custom data is not supported through this method, use values(Iterable) or any variant thereof for applying custom data.

      Type Parameters:
      E - The type of elements
      Parameters:
      key - The key to use
      weightedTable - The weighted table
      Returns:
      The new biconsumer to apply to an itemstack builder
    • listValueSuppliers

      public static <E> BiConsumer<ItemStack.Builder,Random> listValueSuppliers(Key<? extends ListValue<E>> key, WeightedTable<Function<Random,E>> weightedTable)
      Creates a new BiConsumer where the Key is responsible for a List based Value.Mutable. Given the WeightedTable is exclusively used with Functions, the Functions themselves are queried with a Random and expected to present a singular element of the defined type. It's expected that there are multiple functions to provide additional elements for a particular key'ed ListValue.Mutable.

      An example usage of this can be for generating a randomized list of Enchantments with varying enchantment levels.

      Note that custom data is not supported through this method, use values(Iterable) or any variant thereof for applying custom data.

      Type Parameters:
      E - The type of element
      Parameters:
      key - The key to use
      weightedTable - The weighted table containing all the desired functions producing the randomized elements
      Returns:
      The new biconsumer to apply to an itemstack builder
    • listValueSuppliers

      public static <E> BiConsumer<ItemStack.Builder,Random> listValueSuppliers(Supplier<? extends Key<? extends ListValue<E>>> key, WeightedTable<Function<Random,E>> weightedTable)
    • setValues

      public static <E> BiConsumer<ItemStack.Builder,Random> setValues(Key<? extends SetValue.Mutable<E>> key, Set<E> elementPool)
      Creates a new BiConsumer where the Key is responsible for a Set based Value.Mutable. Given the Set of element to act as a pool, the consumer will pull a random amount of the given pool and apply it as a new Set.

      Note that custom data is not supported through this method, use values(Iterable) or any variant thereof for applying custom data.

      Type Parameters:
      E - The type of element
      Parameters:
      key - The key to use
      elementPool - The set of elements to use as a pool
      Returns:
      The new biconsumer to apply to an itemstack builder
    • setValues

      public static <E> BiConsumer<ItemStack.Builder,Random> setValues(Key<? extends SetValue.Mutable<E>> key, Set<E> elementPool, VariableAmount amount)
      Creates a new BiConsumer where the Key is responsible for a Set based Value.Mutable. Given the Set of elements to act as a pool, the consumer will pull a variable amount based on the provided VariableAmount, and apply it as a new Set.
      Type Parameters:
      E - The type of element
      Parameters:
      key - The key to use
      elementPool - The set of elements to use as a pool
      amount - The variable amount of elements to get
      Returns:
      The new biconsumer to apply to an itemstack builder
    • setValues

      public static <E> BiConsumer<ItemStack.Builder,Random> setValues(Key<? extends SetValue.Mutable<E>> key, WeightedTable<E> weightedTable)
      Creates a new BiConsumer where the Key is responsible for a Set based Value.Mutable. Given the provided WeightedTable, the consumer will retrieve a List of values and add them as a new Set.
      Type Parameters:
      E - The type of element
      Parameters:
      key - The key to use
      weightedTable - The weighted table acting as an element pool
      Returns:
      The new biconsumer to apply to an itemstack builder
    • value

      public static <E, V extends Value<E>> BiConsumer<ItemStack.Builder,Random> value(V value)
      Creates a new BiConsumer that applies the provided Value.Mutable to the generated ItemStack.
      Type Parameters:
      E - The type of element
      V - The type of value
      Parameters:
      value - The value to use
      Returns:
      The new biconsumer to apply to an itemstack builder
    • values

      public static <E, V extends Value<E>> BiConsumer<ItemStack.Builder,Random> values(Iterable<V> values)
      Creates a new BiConsumer that applies a random selection of the provided Values.
      Type Parameters:
      E - The type of element
      V - The type of value
      Parameters:
      values - The iterable collection of values to choose from
      Returns:
      The new biconsumer to apply to an itemstack builder
    • values

      public static BiConsumer<ItemStack.Builder,Random> values(Collection<Value.Immutable<?>> manipulators, VariableAmount rolls)
      Creates a new BiConsumer that provides a VariableAmount of Values from the provided pool. Note that no validation can be performed, however the builder will ignore unsupported data.
      Parameters:
      manipulators - The manipulator pool to use
      rolls - The variable amount of manipulators to apply
      Returns:
      The new biconsumer to apply to an itemstack builder
    • values

      public static BiConsumer<ItemStack.Builder,Random> values(WeightedTable<Value.Immutable<?>> weightedTable)
      Creates a new BiConsumer that provides a variable amount of Values from the provided WeightedTable. Note that no validation can be performed, however the builder will ignore unsupported data.
      Parameters:
      weightedTable - The weighted table containing manipulators
      Returns:
      The new biconsumer to apply to an itemstack builder
    • enchantment

      public static BiConsumer<ItemStack.Builder,Random> enchantment(EnchantmentType enchantmentType)
      Creates a new BiConsumer that takes the provided EnchantmentType and applies it to the generated ItemStack. The enchantmentType level is varied based on vanilla mechanics.
      Parameters:
      enchantmentType - The singular enchantmentType to add
      Returns:
      The new biconsumer to apply to an itemstack builder
    • enchantment

      public static BiConsumer<ItemStack.Builder,Random> enchantment(VariableAmount level, EnchantmentType enchantmentType)
      Creates a new BiConsumer that takes the provided EnchantmentType and applies it to the generated ItemStack. The enchantmentType level is defined by the variable amount provided.
      Parameters:
      level - The variance in enchantmentType level
      enchantmentType - The enchantmentType to add
      Returns:
      The new biconsumer to apply to an itemstack builder
    • enchantmentsWithVanillaLevelVariance

      public static BiConsumer<ItemStack.Builder,Random> enchantmentsWithVanillaLevelVariance(Collection<EnchantmentType> enchantmentTypes)
      Creates a new BiConsumer that takes the provided Collection of EnchantmentTypes and applies a singular EnchantmentType with varying levels to the generated ItemStack.
      Parameters:
      enchantmentTypes - The enchantment pool to choose from
      Returns:
      The new biconsumer to apply to an itemstack builder
    • enchantmentsWithVanillaLevelVariance

      public static BiConsumer<ItemStack.Builder,Random> enchantmentsWithVanillaLevelVariance(VariableAmount amount, EnchantmentType enchantmentType, EnchantmentType... enchantmentTypes)
      Creates a new BiConsumer that takes the provided EnchantmentTypes and applies a variable amount of enchantmentTypes with varying levels to the generated ItemStack.
      Parameters:
      amount - The variable amount of enchantmentTypes to use
      enchantmentType - The first enchantmentType to add
      enchantmentTypes - The additional enchantmentTypes to use
      Returns:
      The new biconsumer to apply to an itemstack builder
    • enchantmentsWithVanillaLevelVariance

      public static BiConsumer<ItemStack.Builder,Random> enchantmentsWithVanillaLevelVariance(VariableAmount amount, Collection<EnchantmentType> itemEnchantmentTypes)
      Creates a new BiConsumer that takes the provided Collection of EnchantmentTypes and applies a varying amount of generated enchantments to the generated ItemStack.
      Parameters:
      amount - The varying amount of enchantments to use
      itemEnchantmentTypes - The enchantment pool to use
      Returns:
      The new biconsumer to apply to an itemstack builder
    • enchantments

      public static BiConsumer<ItemStack.Builder,Random> enchantments(VariableAmount amount, Collection<Tuple<EnchantmentType,VariableAmount>> enchantments)
      Creates a new BiConsumer that takes the provided Collection of coupled EnchantmentType and VariableAmount to apply varying enchantments of varying amounts to the generated ItemStack.
      Parameters:
      amount - The varying amount of enchantments
      enchantments - The collection of enchantment tuples combining the enchantment and the variable amount of level to apply
      Returns:
      The new biconsumer to apply to an itemstack builder