LootPool ======== .. zenscript:type:: loottweaker.vanilla.loot.LootPool Each instance of this type represents a specific pool of a loot table. .. _json-format-maps: Condition and function formatting --------------------------------- Conditions and functions should be supplied to methods as JSON format maps_/ or :doc:`conditions`/:doc:`functions`. Do not supply the conditions/functions as part of a parent tag. When using a `map`_ to supply conditions or functions, it is recommended that you surround the keys with double quotes("), as otherwise any keys which are ZenScript keywords(e.g function) will cause issues. Recommended .. code-block:: json [ { "count": { "min": 0.0, "max": 2.0 }, "function": "minecraft:set_count" } ] Not Recommended .. code-block:: none [ { count: { min: 0.0, max: 2.0 }, function: "minecraft:set_count" } ] .. _autoconverted: Converting JSON format maps to LootCondition/LootFunction --------------------------------------------------------- As of 0.3.0 JSON format maps are automatically converted to :doc:`conditions`/:doc:`functions` as needed, so any LootFunction/LootCondition parameter will accept a JSON format map. Methods ------- See :doc:`here ` for an explanation of the method documentation format used on this page. .. zenscript:function:: addConditions(LootCondition[] conditions) Adds conditions to the pool. :parameters: * conditions - an array of instances of :doc:`LootCondition ` to add. JSON format maps are :ref:`automatically converted `. .. code-block:: java import loottweaker.vanilla.loot.Conditions; // somePool is a LootPool created elsewhere somePool.addConditions([ {"condition": "killed_by_player"}, Conditions.randomChance(0.5) ]); .. zenscript:function:: removeEntry(String entryName) Removes the entry with a matching ``entryName`` tag from the pool :parameters: * entryName - the :doc:`unique name ` of the target entry :errors: if no entry with the specified name exists in the pool .. code-block:: java // somePool is a LootPool created elsewhere somePool.removeEntry("someEntryName"); .. zenscript:function:: addItemEntry(IItemStack iStack, int weight, int quality, LootFunction[] functions, LootCondition[] conditions, @Optional String name) Adds a new ``item`` type entry to the pool. :parameters: * iStack - the item stack the entry should produce. LootTweaker will autogenerate *set_nbt*, *set_damage*/*set_data* and *set_count* functions based on this stack, unless ``functions`` contains a function of the same type. * weight - the main component that determines the generation chance. Higher weights make entries generate more often. * quality - determines how much the Luck attribute affects the generation chance. Higher qualities make the luck attribute affect the generation chance more. * functions - :doc:`functions ` that affect the stack(s) generated by the entry. JSON format maps are :ref:`automatically converted `. * conditions - :doc:`conditions ` for the generation of the entry. JSON format maps are :ref:`automatically converted `. * name - (Optional) a name for the entry. Must be unique within the pool. :errors: if the pool already contains an entry with the same name. .. code-block:: java import loottweaker.vanilla.loot.Conditions; // somePool is a LootPool created elsewhere somePool.addItemEntry( , 1, // weight 1, i.e. low generation chance. Actual chance depends on total pool weight. 0, // Default quality [], // No functions [ Conditions.killedByPlayer() ], "someEntry" // Optional entry name ); .. zenscript:function:: addItemEntry(IItemStack stack, int weightIn, int qualityIn, @Optional String name) Adds a new ``item`` type entry to the pool, with no conditions or functions. :parameters: * iStack - the item stack the entry should produce. LootTweaker will autogenerate *set_nbt*, *set_damage*/*set_data* and *set_count* functions based on this stack, unless ``functions`` contains a function of the same type. * weight - the main component that determines the generation chance. Higher weights make entries generate more often. * name - (Optional) a name for the entry. Must be unique within the pool. :errors: if the pool already contains an entry with the same name. .. zenscript:function:: addItemEntry(IItemStack stack, int weightIn, @Optional String name) Adds a new ``item`` type entry to the pool, with no conditions or functions, and a quality of 0. :parameters: * iStack - the item stack the entry should produce. LootTweaker will autogenerate *set_nbt*, *set_damage*/*set_data* and *set_count* functions based on this stack, unless ``functions`` contains a function of the same type. * weight - the main component that determines the generation chance. Higher weights make entries generate more often. * name - (Optional) a name for the entry. Must be unique within the pool. :errors: if the pool already contains an entry with the same name. .. zenscript:function:: addLootTableEntry(String tableName, int weightIn, int qualityIn, LootCondition[] conditions, @Optional String name) Adds a new ``loot_table`` type entry to the pool. :parameters: * tableName - the identifier for the table the entry should generate loot from. * weight - the main component that determines the generation chance. Higher weights make entries generate more often. * quality- determines how much the Luck attribute affects the generation chance. Higher qualities make the luck attribute affect the generation chance more. * conditions - :doc:`conditions ` for the generation of the entry. JSON format maps are :ref:`automatically converted `. * name - (Optional) a name for the entry. Must be unique within the pool. :errors: if the pool already contains an entry with the same name. .. code-block:: java import loottweaker.vanilla.loot.Conditions; // somePool is a LootPool created elsewhere somePool.addLootTableEntry( "someMod:someTable", 1, // weight 1, i.e. low generation chance. Actual chance depends on total pool weight. 0, // Default quality [ Conditions.killedByPlayer() ], "someEntry" // Optional entry name ); .. zenscript:function:: addLootTableEntry(String tableName, int weightIn, int qualityIn, @Optional String name) Adds a new ``loot_table`` type entry to the pool with no conditions. :parameters: * tableName - the identifier for the table the entry should generate loot from. * weight - the main component that determines the generation chance. Higher weights make entries generate more often. * quality - determines how much the Luck attribute affects the generation chance. Higher qualities make the luck attribute affect the generation chance more. * conditions - conditions for the generation of the entry. * name - (Optional) a name for the entry. Must be unique within the pool. :errors: if the pool already contains an entry with the same name. .. zenscript:function:: addLootTableEntry(String tableName, int weightIn, @Optional String name) Adds a new ``loot_table`` type entry to the pool with no conditions, and a quality of 0. :parameters: * tableName - the identifier for the table the entry should generate loot from. * weight - the main component that determines the generation chance. Higher weights make entries generate more often. * quality - determines how much the Luck attribute affects the generation chance. Higher qualities make the luck attribute affect the generation chance more. * conditions - conditions for the generation of the entry. * name - (Optional) a name for the entry. Must be unique within the pool. :errors: if the pool already contains an entry with the same name. .. zenscript:function:: addEmptyEntry(int weight, int quality, LootCondition[] conditions, @Optional String name) Adds a new ``empty`` type entry to the pool. :parameters: * weight - the main component that determines the generation chance. Higher weights make entries generate more often. * quality - determines how much the Luck attribute affects the generation chance. Higher qualities make the luck attribute affect the generation chance more. * conditions - :doc:`conditions ` for the generation of the entry. JSON format maps are :ref:`automatically converted `. * name - (Optional) a name for the entry. Must be unique within the pool. :errors: if the pool already contains an entry with the same name. .. code-block:: java import loottweaker.vanilla.loot.Conditions; // somePool is a LootPool created elsewhere somePool.addLootTableEntry( 1, // weight 1, i.e. low generation chance. Actual chance depends on total pool weight. 0, // Default quality [ Conditions.killedByPlayer() ], "someEntry" // Optional entry name ); .. zenscript:function:: addEmptyEntry(int weight, int quality, @Optional String name) Adds a new ``empty`` type entry to the pool with no conditions. :parameters: * weight - the main component that determines the generation chance. Higher weights make entries generate more often. * quality - determines how much the Luck attribute affects the generation chance. Higher qualities make the luck attribute affect the generation chance more. * name - (Optional) a name for the entry. Must be unique within the pool. :errors: if the pool already contains an entry with the same name. .. zenscript:function:: addEmptyEntry(int weight, @Optional String name) Adds a new ``empty`` type entry to the pool with no conditions, and a quality of 0. :parameters: * weight - the main component that determines the generation chance. Higher weights make entries generate more often. * quality - determines how much the Luck attribute affects the generation chance. Higher qualities make the luck attribute affect the generation chance more. * name - (Optional) a name for the entry. Must be unique within the pool. :errors: if the pool already contains an entry with the same name. .. zenscript:function:: setRolls(float min, float max) Sets the minimum and maximum rolls of the pool to the specified values. :parameters: * min - the new minimum rolls value * max - the new maximum rolls value .. code-block:: java // somePool is a LootPool created elsewhere somePool.setRolls(0, 1); .. zenscript:function:: setBonusRolls(float min, float max) Sets the minimum and maximum bonus rolls of the pool to the specified values. :parameters: * min - the new minimum bonus rolls value. * max - the new maximum bonus rolls value. .. code-block:: java // somePool is a LootPool created elsewhere somePool.setBonusRolls(0, 1); .. zenscript:function:: clearConditions() Removes all loot conditions attached to this loot pool. Loot conditions and loot functions attached to child entries are unaffected. .. code-block:: java // somePool is a LootPool created elsewhere somePool.clearConditions(); .. zenscript:function:: clearEntries() Removes all entries from this loot pool. .. code-block:: java // somePool is a LootPool created elsewhere somePool.clearEntries(); .. _map: https://docs.blamejared.com/1.12/en/AdvancedFunctions/Associative_Arrays/ .. _maps: https://docs.blamejared.com/1.12/en/AdvancedFunctions/Associative_Arrays/