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

LootModifierManager

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.LootModifierManager;

Description

Manager for loot modifiers.

An instance of this manager can be obtained via the com.blamejared.crafttweaker.api.loot.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.

Members

getAll() as List<ILootModifier>
Gets a list containing all currently registered loot modifiers.

Returns: A list containing all currently registered loot modifiers.

script.zs
// LootModifierManager.getAll() as List<ILootModifier>;
myLootModifierManager.getAll();

Return Type: List<ILootModifier>

getAllNames() as List<ResourceLocation>
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.

script.zs
// LootModifierManager.getAllNames() as List<ResourceLocation>;
myLootModifierManager.getAllNames();

Return Type: List<ResourceLocation>

getByName(name as string) as ILootModifier
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.

script.zs
// LootModifierManager.getByName(name as string) as ILootModifier;
myLootModifierManager.getByName(myString);

Parameters:

name Type: string - The name of the loot modifier.

Return Type: ILootModifier

register(name as string, conditions as LootConditions, modifier as ILootModifier)
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);
myLootModifierManager.register(myString, myLootConditions, myILootModifier);

Parameters:

name Type: string - The unique identifier for the loot modifier. It must be all lowercase and devoid of both spaces and
colons.
conditions Type: LootConditions - A set of conditions that restrict the context in which the loot modifier applies.
modifier Type: ILootModifier - The loot modifier itself. It may be created via CommonLootModifiers.
removeAll()
Removes all loot modifiers that have been registered up to this point.
script.zs
// LootModifierManager.removeAll();
myLootModifierManager.removeAll();
removeByModId(modId as string)
Removes all loot modifiers that have been registered by the mod with the given ID.
script.zs
// LootModifierManager.removeByModId(modId as string);
myLootModifierManager.removeByModId(myString);

Parameters:

modId Type: string - The mod ID.
removeByName(name as string)
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);
myLootModifierManager.removeByName(myString);

Parameters:

name Type: string - The name of the loot modifier to remove.
removeByRegex(regex as string)
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);
myLootModifierManager.removeByRegex(myString);

Parameters:

regex Type: string - The regular expression to match.