LootModifierManager

Manager for loot modifiers.

An instance of this manager can be obtained via the LootManager.

The main usage of this manager is for registering “global loot modifiers”, also known as “loot modifiers” for short. A global loot modifier runs on the loot drop of every loot table (unless otherwise specified by conditions) and is as such able to modify it according either to predetermined parameters (e.g. replacing items) or via completely customized code that leverages the dropping context.

For more information, refer to ILootModifier.

Importing the class

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.

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

Enum Constants

LootModifierManager is an enum. It has 1 enum constants. They are accessible using the code below.

script.zs
LootModifierManager.INSTANCE

Methods

Gets a list containing all currently registered loot modifiers.

Returns: A list containing all currently registered loot modifiers.
Return Type: stdlib.List<ILootModifier>

script.zs
// LootModifierManager.getAll() as stdlib.List<ILootModifier>
loot.modifiers.getAll();

Gets a list of all the names of the currently registered loot modifiers.

Returns: A list with all the names of the currently registered loot modifiers.
Return Type: stdlib.List<ResourceLocation>

script.zs
// LootModifierManager.getAllNames() as stdlib.List<ResourceLocation>
loot.modifiers.getAllNames();

Gets the loot modifier with the given name, if it exists.

If no loot modifier with that name exists, a default no-op instance is returned.

Returns: The ILootModifier with the given name, or a default one if no such instance exists.
Return Type: ILootModifier

script.zs
LootModifierManager.getByName(name as string) as ILootModifier
ParameterTypeDescription
Parameter
name
Type
string
Description
The name of the loot modifier.

Registers a new global loot modifier with the given name.

The loot modifier will be run only when the given set of conditions is satisfied.

script.zs
LootModifierManager.register(name as string, conditions as LootConditions, modifier as ILootModifier)
ParameterTypeDescription
Parameter
name
Type
string
Description
The unique identifier for the loot modifier. It must be all lowercase and devoid of both spaces and
colons.
Parameter
conditions
Type
LootConditions
Description
A set of conditions that restrict the context in which the loot modifier applies.
Parameter
modifier
Type
ILootModifier
Description
The loot modifier itself. It may be created via CommonLootModifiers.

Removes all loot modifiers that have been registered up to this point.

script.zs
// LootModifierManager.removeAll()
loot.modifiers.removeAll();

Removes all loot modifiers that have been registered by the mod with the given ID.

script.zs
LootModifierManager.removeByModId(modId as string)
ParameterTypeDescription
Parameter
modId
Type
string
Description
The mod ID.

Removes the loot modifier with the given name.

The name may either contain a colon or not. If no colon is present, it is assumed that the loot modifier name is one of the modifiers that have been already registered in a script.

script.zs
LootModifierManager.removeByName(name as string)
ParameterTypeDescription
Parameter
name
Type
string
Description
The name of the loot modifier to remove.

Removes all loot modifiers whose name matches the given regular expression.

The entire name is taken into consideration for the match, effectively matching the format of a ResourceLocation.

script.zs
LootModifierManager.removeByRegex(regex as string)
ParameterTypeDescription
Parameter
regex
Type
string
Description
The regular expression to match.