Class CommonLootModifiers

java.lang.Object
com.blamejared.crafttweaker.api.loot.modifier.CommonLootModifiers

@ZenRegister public final class CommonLootModifiers extends Object
Holds a set of implementations of ILootModifier of common usage.

These can be used freely instead of rewriting the same code more than once. They are also guaranteed to behave correctly.

  • Constructor Details

    • CommonLootModifiers

      public CommonLootModifiers()
  • Method Details

    • add

      public static ILootModifier add(IItemStack stack)
      Adds the given IItemStack to the drops.
      Parameters:
      stack - The stack to add
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      stack <item:minecraft:cobblestone>
    • addAll

      public static ILootModifier addAll(IItemStack... stacks)
      Adds all the given IItemStack to the drops.
      Parameters:
      stacks - The stacks to add
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      stacks <item:minecraft:iron_ingot>, <item:minecraft:iron_nugget> * 5
    • addWithChance

      public static ILootModifier addWithChance(Percentaged<IItemStack> stack)
      Adds the given Percentaged IItemStack to the drops, according to the specified chances.

      The chance will be computed on each modifier roll.

      Parameters:
      stack - The stack to add.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      stack <item:minecraft:gilded_blackstone> % 50
    • addAllWithChance

      @SafeVarargs public static ILootModifier addAllWithChance(Percentaged<IItemStack>... stacks)
      Adds the given Percentaged IItemStacks to the drops, according to the specified chances.

      The chance will be computed on each modifier roll, and independently for each of the given stacks.

      Parameters:
      stacks - The stacks to add.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      stacks <item:minecraft:honey_bottle> % 50, <item:minecraft:dried_kelp> % 13
    • addWithOreDropsBonus

      public static ILootModifier addWithOreDropsBonus(net.minecraft.world.item.enchantment.Enchantment enchantment, IItemStack stack)
      Adds the given IItemStack to the drops, modifying its count based on the level of the given Enchantment on the tool used, if available.

      In case no tool is used to obtain the stack, then this loot modifier behaves exactly like add(IItemStack).

      The formula used is based on the ore_drops formula used by vanilla, which multiplies the stack's original count by a random number between 1 and the tool's enchantment level + 1. This is the formula used by all vanilla ores to determine their drop count.

      Parameters:
      enchantment - The enchantment to check for.
      stack - The stack to add.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      enchantment <enchantment:minecraft:fortune>, stack <item:minecraft:coal>
    • addWithBinomialBonus

      public static ILootModifier addWithBinomialBonus(net.minecraft.world.item.enchantment.Enchantment enchantment, int extra, float p, IItemStack stack)
      Adds the given IItemStack to the drops, modifying its count based on the level of the given Enchantment on the tool used, if available.

      In case no tool is used to obtain the stack, then this loot modifier behaves exactly like add(IItemStack).

      The formula used is based on the binomial_with_bonus_count formula used by vanilla. In this case, the value of extra is added to the current tool's enchantment level; that determines the amount of times the randomness will roll. Every roll that is higher than p will add one element to the stack. This is the formula used by potatoes and carrots to determine their drop count.

      Parameters:
      enchantment - The enchantment to check for.
      extra - An extra value that will be added to the tool's enchantment level.
      p - The probability of the binomial distribution, between 0.0 and 1.0 (both exclusive).
      stack - The stack to add.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      enchantment <enchantment:minecraft:fortune>, extra 3, p 0.5714286, stack <item:minecraft:wheat_seeds>
    • addWithUniformBonus

      public static ILootModifier addWithUniformBonus(net.minecraft.world.item.enchantment.Enchantment enchantment, int multiplier, IItemStack stack)
      Adds the given IItemStack to the drops, modifying its count based on the level of the given Enchantment on the tool used, if available.

      In case no tool is used to obtain the stack, then this loot modifier behaves exactly like add(IItemStack).

      The formula used is based on the uniform_bonus_count formula used by vanilla. In this case, the enchantment level is multiplied by multiplier and a random number is extracted between 0 and the result. This number is then added to the original's stack count. This is the formula used by redstone ore and glowstone to determine their drop count.

      Parameters:
      enchantment - The enchantment to check for.
      multiplier - A multiplier that will be used in conjunction with the enchantment's level.
      stack - The stack to add.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      enchantment <enchantment:minecraft:fortune>, multiplier 1, stack <item:minecraft:glowstone_dust>
    • addAllWithOreDropsBonus

      public static ILootModifier addAllWithOreDropsBonus(net.minecraft.world.item.enchantment.Enchantment enchantment, IItemStack... stacks)
      Adds the given IItemStacks to the drops, modifying their count based on the level of the given Enchantment on the tool used, if available.

      In case no tool is used to obtain the stack, then this loot modifier behaves exactly like addAll(IItemStack...).

      The fortune modifier is applied separately for each IItemStack.

      The formula used is based on the ore_drops formula used by vanilla, which multiplies the stack's original count by a random number between 1 and the tool's enchantment level + 1. This is the formula used by all vanilla ores to determine their drop count.

      Parameters:
      enchantment - The enchantment to check for.
      stacks - The stacks to add.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      enchantment <enchantment:minecraft:fortune>, stacks <item:minecraft:coal>, <item:minecraft:diamond>
    • addAllWithBinomialBonus

      public static ILootModifier addAllWithBinomialBonus(net.minecraft.world.item.enchantment.Enchantment enchantment, int extra, float p, IItemStack... stacks)
      Adds the given IItemStacks to the drops, modifying their count based on the level of the given Enchantment on the tool used, if available.

      In case no tool is used to obtain the stack, then this loot modifier behaves exactly like addAll(IItemStack...).

      The fortune modifier is applied separately for each IItemStack.

      The formula used is based on the binomial_with_bonus_count formula used by vanilla. In this case, the value of extra is added to the current tool's enchantment level; that determines the amount of times the randomness will roll. Every roll that is higher than p will add one element to the stack. This is the formula used by potatoes and carrots to determine their drop count.

      Parameters:
      enchantment - The enchantment to check for.
      extra - An extra value that will be added to the tool's enchantment level.
      p - The probability of the binomial distribution, between 0.0 and 1.0 (both exclusive).
      stacks - The stacks to add.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      enchantment <enchantment:minecraft:fortune>, extra 3, p 0.5714286, stacks <item:minecraft:wheat_seeds>, <item:minecraft:carrot> * 9
    • addAllWithUniformBonus

      public static ILootModifier addAllWithUniformBonus(net.minecraft.world.item.enchantment.Enchantment enchantment, int multiplier, IItemStack... stacks)
      Adds the given IItemStacks to the drops, modifying their count based on the level of the given Enchantment on the tool used, if available.

      In case no tool is used to obtain the stack, then this loot modifier behaves exactly like addAll(IItemStack...).

      The fortune modifier is applied separately for each IItemStack.

      The formula used is based on the uniform_bonus_count formula used by vanilla. In this case, the enchantment level is multiplied by multiplier and a random number is extracted between 0 and the result. This number is then added to the original's stack count. This is the formula used by redstone ore and glowstone to determine their drop count.

      Parameters:
      enchantment - The enchantment to check for.
      multiplier - A multiplier that will be used in conjunction with the enchantment's level.
      stacks - The stacks to add.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      enchantment <enchantment:minecraft:fortune>, multiplier 1, stacks <item:minecraft:glowstone_dust>, <item:minecraft:prismarine_crystals>
    • addWithRandomAmount

      public static ILootModifier addWithRandomAmount(IItemStack stack, int min, int max)
      Adds the given IItemStack to the drops, with an amount chosen randomly between the given bounds.

      Any original stack size given to this method is ignored; if an addition behavior is desired (as in random chance on top of the original stack size), a combining loot modifier should be used instead.

      Parameters:
      stack - The stack to add.
      min - The minimum amount that this stack can be.
      max - The maximum amount that this stack can be.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      stack <item:minecraft:conduit>, min 2, max 9
    • replaceWith

      public static ILootModifier replaceWith(IIngredient target, IItemStack replacement)
      Replaces every instance of the targeted IIngredient with the replacement IItemStack. In this case, a simple matching procedure is used, where every stack that matches the given target is replaced by the replacement without considering stack size. If stack size is to be preserved, refer to replaceStackWith(IItemStack, IItemStack).
      Parameters:
      target - The target to replace.
      replacement - The replacement to use.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      target <tag:items:forge:ingots/iron>, replacement <item:minecraft:iron_ingot>
    • replaceAllWith

      public static ILootModifier replaceAllWith(Map<IIngredient,IItemStack> replacementMap)
      Replaces every instance of the targeted IIngredients with their corresponding replacement IItemStack. In this case, a simple matching procedure is used, where every stack that matches the key of the pair is replaced by the corresponding value, without considering stack size. If stack size is to be preserved, refer to replaceAllStacksWith(Map).
      Parameters:
      replacementMap - A map of key-value pairs dictating the target to replace along with their replacement.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      replacementMap { <tag:items:forge:gems/emerald> : <item:minecraft:emerald> }
    • replaceStackWith

      public static ILootModifier replaceStackWith(IItemStack target, IItemStack replacement)
      Replaces every instance of the targeted IItemStack with the replacement IItemStack, proportionally. As an example, if the loot drops 5 carrots and this loot modifier runs with 2 carrots as the target and 1 potato as the replacement, the loot will be modified to 2 potatoes and 1 carrot. This happens because every 2-carrot stack will be actively replaced by a 1-potato stack, without exceptions. This loot modifier acts differently than replaceWith(IIngredient, IItemStack), where a simpler approach is used.
      Parameters:
      target - The target to replace.
      replacement - The replacement to use.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      target <item:minecraft:carrots> * 2, replacement <item:minecraft:potatoes>
    • replaceAllStacksWith

      public static ILootModifier replaceAllStacksWith(Map<IItemStack,IItemStack> replacementMap)
      Replaces every instance of the targeted IItemStacks with the replacement IItemStacks, proportionally. As an example, if the loot drops 5 carrots and this loot modifier runs with 2 carrots as the key of a pair and 1 potato as the corresponding value, the loot will be modified to 2 potatoes and 1 carrot. This happens because every 2-carrot stack will be actively replaced by a 1-potato stack, without exceptions. This loot modifier acts differently than replaceAllWith(Map), where a simpler approach is used.
      Parameters:
      replacementMap - A map of key-value pairs dictating the target to replace along with their replacement.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      replacementMap { <item:minecraft:carrots> * 2 : <item:minecraft:potatoes> }
    • remove

      public static ILootModifier remove(IIngredient target)
      Removes every instance of the targeted IIngredient from the drops.
      Parameters:
      target - The IIngredient to remove.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      target <tag:items:minecraft:creeper_drop_music_discs>
    • removeAll

      public static ILootModifier removeAll(IIngredient... targets)
      Removes every instance of all the targeted IIngredients from the drops.
      Parameters:
      targets - The IIngredients to remove.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      targets <item:minecraft:bell>, <tag:items:minecraft:rails>
    • clearLoot

      public static ILootModifier clearLoot()
      Clears the entire drop list.
      Returns:
      An ILootModifier that carries out the operation.
    • chaining

      public static ILootModifier chaining(ILootModifier... modifiers)
      Chains the given list of ILootModifiers to be executed one after the other.
      Parameters:
      modifiers - The modifier list.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      modifiers CommonLootModifiers.clearLoot(), CommonLootModifiers.add(<item:minecraft:warped_hyphae>)
    • clearing

      public static ILootModifier clearing(ILootModifier... modifiers)
      Chains the given list of ILootModifiers together after having cleaned the original loot.
      Parameters:
      modifiers - The modifier list.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      modifiers CommonLootModifiers.add(<item:minecraft:warped_hyphae>)