Home Commands Examples Getting Started With Scripts Global Keywords
BracketDumpers BracketHandlers BracketValidators ResourceLocationBracketHandler

CommonLootModifiers

Importing the class

If you need to reference this type directly, like when casting an Array, or as a parameter, you will need to import it. Simply add the import at the top of the file.

script.zs
import crafttweaker.api.loot.modifier.CommonLootModifiers;

Description

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.

Members

static add(stack as IItemStack) as ILootModifier
Adds the given IItemStack to the drops.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.add(stack as IItemStack) as ILootModifier;
CommonLootModifiers.add(<item:minecraft:cobblestone>);

Parameters:

stack Type: IItemStack - The stack to add

Return Type: ILootModifier

static addAll(stacks as IItemStack[]) as ILootModifier
Adds all the given IItemStack to the drops.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.addAll(stacks as IItemStack[]) as ILootModifier;
CommonLootModifiers.addAll(<item:minecraft:iron_ingot>, <item:minecraft:iron_nugget> * 5);

Parameters:

stacks Type: IItemStack[] - The stacks to add

Return Type: ILootModifier

static addAllWithBinomialBonus(enchantment as Enchantment, extra as int, p as float, stacks as IItemStack[]) as ILootModifier
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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.addAllWithBinomialBonus(enchantment as Enchantment, extra as int, p as float, stacks as IItemStack[]) as ILootModifier;
CommonLootModifiers.addAllWithBinomialBonus(<enchantment:minecraft:fortune>, 3, 0.5714286, <item:minecraft:wheat_seeds>, <item:minecraft:carrot> * 9);

Parameters:

enchantment Type: Enchantment - The enchantment to check for.
extra Type: int - An extra value that will be added to the tool's enchantment level.
p Type: float - The probability of the binomial distribution, between 0.0 and 1.0 (both exclusive).
stacks Type: IItemStack[] - The stacks to add.

Return Type: ILootModifier

static addAllWithChance(stacks as Percentaged<IItemStack>[]) as ILootModifier
Adds the given Percentaged s 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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.addAllWithChance(stacks as Percentaged<IItemStack>[]) as ILootModifier;
CommonLootModifiers.addAllWithChance(<item:minecraft:honey_bottle> % 50, <item:minecraft:dried_kelp> % 13);

Parameters:

stacks Type: Percentaged<IItemStack>[] - The stacks to add.

Return Type: ILootModifier

static addAllWithOreDropsBonus(enchantment as Enchantment, stacks as IItemStack[]) as ILootModifier
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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.addAllWithOreDropsBonus(enchantment as Enchantment, stacks as IItemStack[]) as ILootModifier;
CommonLootModifiers.addAllWithOreDropsBonus(<enchantment:minecraft:fortune>, <item:minecraft:coal>, <item:minecraft:diamond>);

Parameters:

enchantment Type: Enchantment - The enchantment to check for.
stacks Type: IItemStack[] - The stacks to add.

Return Type: ILootModifier

static addAllWithUniformBonus(enchantment as Enchantment, multiplier as int, stacks as IItemStack[]) as ILootModifier
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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.addAllWithUniformBonus(enchantment as Enchantment, multiplier as int, stacks as IItemStack[]) as ILootModifier;
CommonLootModifiers.addAllWithUniformBonus(<enchantment:minecraft:fortune>, 1, <item:minecraft:glowstone_dust>, <item:minecraft:prismarine_crystals>);

Parameters:

enchantment Type: Enchantment - The enchantment to check for.
multiplier Type: int - A multiplier that will be used in conjunction with the enchantment's level.
stacks Type: IItemStack[] - The stacks to add.

Return Type: ILootModifier

static addWithBinomialBonus(enchantment as Enchantment, extra as int, p as float, stack as IItemStack) as ILootModifier
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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.addWithBinomialBonus(enchantment as Enchantment, extra as int, p as float, stack as IItemStack) as ILootModifier;
CommonLootModifiers.addWithBinomialBonus(<enchantment:minecraft:fortune>, 3, 0.5714286, <item:minecraft:wheat_seeds>);

Parameters:

enchantment Type: Enchantment - The enchantment to check for.
extra Type: int - An extra value that will be added to the tool's enchantment level.
p Type: float - The probability of the binomial distribution, between 0.0 and 1.0 (both exclusive).
stack Type: IItemStack - The stack to add.

Return Type: ILootModifier

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

The chance will be computed on each modifier roll.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.addWithChance(stack as Percentaged<IItemStack>) as ILootModifier;
CommonLootModifiers.addWithChance(<item:minecraft:gilded_blackstone> % 50);

Parameters:

stack Type: Percentaged<IItemStack> - The stack to add.

Return Type: ILootModifier

static addWithOreDropsBonus(enchantment as Enchantment, stack as IItemStack) as ILootModifier
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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.addWithOreDropsBonus(enchantment as Enchantment, stack as IItemStack) as ILootModifier;
CommonLootModifiers.addWithOreDropsBonus(<enchantment:minecraft:fortune>, <item:minecraft:coal>);

Parameters:

enchantment Type: Enchantment - The enchantment to check for.
stack Type: IItemStack - The stack to add.

Return Type: ILootModifier

static addWithRandomAmount(stack as IItemStack, min as int, max as int) as ILootModifier
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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.addWithRandomAmount(stack as IItemStack, min as int, max as int) as ILootModifier;
CommonLootModifiers.addWithRandomAmount(<item:minecraft:conduit>, 2, 9);

Parameters:

stack Type: IItemStack - The stack to add.
min Type: int - The minimum amount that this stack can be.
max Type: int - The maximum amount that this stack can be.

Return Type: ILootModifier

static addWithUniformBonus(enchantment as Enchantment, multiplier as int, stack as IItemStack) as ILootModifier
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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.addWithUniformBonus(enchantment as Enchantment, multiplier as int, stack as IItemStack) as ILootModifier;
CommonLootModifiers.addWithUniformBonus(<enchantment:minecraft:fortune>, 1, <item:minecraft:glowstone_dust>);

Parameters:

enchantment Type: Enchantment - The enchantment to check for.
multiplier Type: int - A multiplier that will be used in conjunction with the enchantment's level.
stack Type: IItemStack - The stack to add.

Return Type: ILootModifier

static chaining(modifiers as ILootModifier[]) as ILootModifier
Chains the given list of ILootModifiers to be executed one after the other.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.chaining(modifiers as ILootModifier[]) as ILootModifier;
CommonLootModifiers.chaining(CommonLootModifiers.clearLoot(), CommonLootModifiers.add(<item:minecraft:warped_hyphae>));

Parameters:

modifiers Type: ILootModifier[] - The modifier list.

Return Type: ILootModifier

static clearing(modifiers as ILootModifier[]) as ILootModifier
Chains the given list of ILootModifiers together after having cleaned the original loot.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.clearing(modifiers as ILootModifier[]) as ILootModifier;
CommonLootModifiers.clearing(CommonLootModifiers.add(<item:minecraft:warped_hyphae>));

Parameters:

modifiers Type: ILootModifier[] - The modifier list.

Return Type: ILootModifier

static clearLoot() as ILootModifier
Clears the entire drop list.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.clearLoot() as ILootModifier;
CommonLootModifiers.clearLoot();

Return Type: ILootModifier

static remove(target as IIngredient) as ILootModifier
Removes every instance of the targeted IIngredient from the drops.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.remove(target as IIngredient) as ILootModifier;
CommonLootModifiers.remove(<tag:items:minecraft:creeper_drop_music_discs>);

Parameters:

target Type: IIngredient - The IIngredient to remove.

Return Type: ILootModifier

static removeAll(targets as IIngredient[]) as ILootModifier
Removes every instance of all the targeted IIngredients from the drops.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.removeAll(targets as IIngredient[]) as ILootModifier;
CommonLootModifiers.removeAll(<item:minecraft:bell>, <tag:items:minecraft:rails>);

Parameters:

targets Type: IIngredient[] - The IIngredients to remove.

Return Type: ILootModifier

static removeExactly(target as IIngredientWithAmount) as ILootModifier
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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.removeExactly(target as IIngredientWithAmount) as ILootModifier;
CommonLootModifiers.removeExactly(<tag:items:minecraft:wooden_planks> * 2);

Parameters:

target Type: IIngredientWithAmount - The IIngredient to remove along with its quantity.

Return Type: ILootModifier

static removeExactlyAll(targets as IIngredientWithAmount[]) as ILootModifier
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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.removeExactlyAll(targets as IIngredientWithAmount[]) as ILootModifier;
CommonLootModifiers.removeExactlyAll(myIIngredientWithAmount[]);

Parameters:

targets Type: IIngredientWithAmount[] - The IIngredients to remove along with their quantity.

Return Type: ILootModifier

static replaceAllStacksWith(replacementMap as IItemStack[IIngredientWithAmount]) as ILootModifier
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.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.replaceAllStacksWith(replacementMap as IItemStack[IIngredientWithAmount]) as ILootModifier;
CommonLootModifiers.replaceAllStacksWith({ <item:minecraft:carrots> * 2 : <item:minecraft:potatoes> });

Parameters:

replacementMap Type: IItemStack[IIngredientWithAmount] - A map of key-value pairs dictating the target to replace along with their replacement.

Return Type: ILootModifier

static replaceAllWith(replacementMap as IItemStack[IIngredient]) as ILootModifier
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).

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.replaceAllWith(replacementMap as IItemStack[IIngredient]) as ILootModifier;
CommonLootModifiers.replaceAllWith({ <tag:items:forge:gems/emerald> : <item:minecraft:emerald> });

Parameters:

replacementMap Type: IItemStack[IIngredient] - A map of key-value pairs dictating the target to replace along with their replacement.

Return Type: ILootModifier

static replaceStackWith(target as IIngredientWithAmount, replacement as IItemStack) as ILootModifier
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 IItemStack), where a simpler approach is used.

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.replaceStackWith(target as IIngredientWithAmount, replacement as IItemStack) as ILootModifier;
CommonLootModifiers.replaceStackWith(<item:minecraft:carrots> * 2, <item:minecraft:potatoes>);

Parameters:

target Type: IIngredientWithAmount - The target to replace.
replacement Type: IItemStack - The replacement to use.

Return Type: ILootModifier

static replaceWith(target as IIngredient, replacement as IItemStack) as ILootModifier
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 IItemStack).

Returns: An ILootModifier that carries out the operation.

script.zs
// CommonLootModifiers.replaceWith(target as IIngredient, replacement as IItemStack) as ILootModifier;
CommonLootModifiers.replaceWith(<tag:items:forge:ingots/iron>, <item:minecraft:iron_ingot>);

Parameters:

target Type: IIngredient - The target to replace.
replacement Type: IItemStack - The replacement to use.

Return Type: ILootModifier