Class LootModifierManager

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

@ZenRegister public class LootModifierManager extends Object
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.

DocParam:
this loot.modifiers
  • Field Details

  • Method Details

    • register

      public void register(String name, LootConditions conditions, ILootModifier 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.

      Parameters:
      name - The unique identifier for the loot modifier. It must be all lowercase and devoid of both spaces and colons.
      conditions - A set of conditions that restrict the context in which the loot modifier applies.
      modifier - The loot modifier itself. It may be created via CommonLootModifiers.
    • getByName

      public ILootModifier getByName(String name)
      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.

      Parameters:
      name - The name of the loot modifier.
      Returns:
      The ILootModifier with the given name, or a default one if no such instance exists.
    • getAllNames

      public List<net.minecraft.resources.ResourceLocation> getAllNames()
      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.
    • getAll

      public List<ILootModifier> getAll()
      Gets a list containing all currently registered loot modifiers.
      Returns:
      A list containing all currently registered loot modifiers.
    • removeByName

      public void removeByName(String name)
      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.

      Parameters:
      name - The name of the loot modifier to remove.
    • removeByModId

      public void removeByModId(String modId)
      Removes all loot modifiers that have been registered by the mod with the given ID.
      Parameters:
      modId - The mod ID.
    • removeByRegex

      public void removeByRegex(String regex)
      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.

      Parameters:
      regex - The regular expression to match.
    • removeAll

      public void removeAll()
      Removes all loot modifiers that have been registered up to this point.