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 invalid input: '<'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 invalid input: '<'item:minecraft:iron_ingot>, invalid input: '<'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 invalid input: '<'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 invalid input: '<'item:minecraft:honey_bottle> % 50, invalid input: '<'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 invalid input: '<'enchantment:minecraft:fortune>, stack invalid input: '<'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 invalid input: '<'enchantment:minecraft:fortune>, extra 3, p 0.5714286, stack invalid input: '<'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 invalid input: '<'enchantment:minecraft:fortune>, multiplier 1, stack invalid input: '<'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 invalid input: '<'enchantment:minecraft:fortune>, stacks invalid input: '<'item:minecraft:coal>, invalid input: '<'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 invalid input: '<'enchantment:minecraft:fortune>, extra 3, p 0.5714286, stacks invalid input: '<'item:minecraft:wheat_seeds>, invalid input: '<'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 invalid input: '<'enchantment:minecraft:fortune>, multiplier 1, stacks invalid input: '<'item:minecraft:glowstone_dust>, invalid input: '<'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 invalid input: '<'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(IIngredientWithAmount, IItemStack).
      Parameters:
      target - The target to replace.
      replacement - The replacement to use.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      target invalid input: '<'tag:item:forge:ingots/iron>, replacement invalid input: '<'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 { invalid input: '<'tag:item:forge:gems/emerald> : invalid input: '<'item:minecraft:emerald> }
    • replaceStackWith

      public static ILootModifier replaceStackWith(IIngredientWithAmount target, IItemStack replacement)
      Replaces every instance of the targeted IIngredientWithAmount 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 invalid input: '<'item:minecraft:carrots> * 2, replacement invalid input: '<'item:minecraft:potatoes>
    • replaceAllStacksWith

      public static ILootModifier replaceAllStacksWith(Map<IIngredientWithAmount,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 { invalid input: '<'item:minecraft:carrots> * 2 : invalid input: '<'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 invalid input: '<'tag:item:minecraft:creeper_drop_music_discs>
    • removeExactly

      public static ILootModifier removeExactly(IIngredientWithAmount target)
      Removes every instance of the targeted IIngredient from the drops, until the maximum amount of removals is reached.

      For example, assume the loot drops 2 carrots, 3 potatoes, and 1 iron ingot and that this loot modifier has been asked to remove 4 edible items. The result of applying the loot modifier will be to remove the 2 carrots and 2 out of the 3 potatoes, resulting in a final drop list of 1 iron ingot and 1 potato.

      Parameters:
      target - The IIngredient to remove along with its quantity.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      target invalid input: '<'tag:item:minecraft:wooden_planks> * 2
    • 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 invalid input: '<'item:minecraft:bell>, invalid input: '<'tag:item:minecraft:rails>
    • removeExactlyAll

      public static ILootModifier removeExactlyAll(IIngredientWithAmount... targets)
      Removes every instance of the targeted IIngredients from the drops, until the maximum amount of removals is reached.

      For example, assume the loot drops 2 carrots, 3 potatoes, and 1 iron ingot and that this loot modifier has been asked to remove 4 edible items. The result of applying the loot modifier will be to remove the 2 carrots and 2 out of the 3 potatoes, resulting in a final drop list of 1 iron ingot and 1 potato.

      Parameters:
      targets - The IIngredients to remove along with their quantity.
      Returns:
      An ILootModifier that carries out the operation.
      DocParam:
      target invalid input: '<'tag:item:minecraft:wooden_planks> * 2, invalid input: '<'item:minecraft:dried_kelp>
    • 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(invalid input: '<'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(invalid input: '<'item:minecraft:warped_hyphae>)