-
Notifications
You must be signed in to change notification settings - Fork 1
Loot Tables
This page serves as documentation for the loot table manipulation system available in tweakers. It will be added to as further loot table manipulation tools are added. All sample code is in JavaScript for the time being. It is recommended you know how a vanilla loot table is set up before using a LibCD tweaker.
The loot tweaker is accessible with var LootTweaker = libcd.import("libcd.loot.LootTweaker");
. It serves as the core manager for editing loot tables. The loot tweaker has a single method that's important for scripts, which is LootTweaker.getTable(id)
. id
is a string which matches the ID of the table you want to modify. If the table is already defined in JSON, you'll get a copy of that table, and otherwise you'll get a new, empty table. You'll want to save the return value of getTable
to a variable.
LootTweaker.getTable
will return a wrapped form of a loot table that can be mutated and changed from JavaScript code. A loot table is fundamentally comprised of two things: an array of loot pools, and an array of loot functions. There are a few methods to manipulate each of these:
-
getPool(index)
- Passed an integer number, this will return the loot pool at that spot in the array as a mutable loot pool (see below). -
addPool(rolls)
- Passed an integer number, this will add a new pool which is rolledrolls
number of times for drops. Returns the newly-added pool as a mutable loot pool (see below). -
addPool(minRolls, maxRolls)
- Passed two integer numbers, this will add a new pool which is rolled betweenminRolls
andmaxRolls
times. Returns the newly-added pool as a mutable loot pool (see below). -
addPool(minRolls, maxRolls, minBonusRolls, maxBonusRolls)
- passed four integer numbers, this will add a new pool which is rolled betweenminRolls
andmaxRolls
times, and then rolled betweenminBonusRolls
andmaxBonusRolls
additional times per point of the player's Luck attribute (boosted in vanilla through the Luck status effect or the Luck of the Sea enchantment on a fishing rod). Returns the newly-added pool as a mutable loot pool (see below). -
removePool(int index)
- Removes the pool at the given index in the table's pool array. Returns the table itself. -
addFunctions(...functions)
- Adds the passed functions into the loot table's function array. Can be passed any number of functions separated by commas. Returns the table itself. See below for function construction. -
removeFunction(int index)
- Removes the function at the given index in the table's function array. Returns the table itself.
table.getPool
and all of the table.addPool
functions will return a mutable form of a loot pool. Loot pools also comprised of two arrays: an array of entries and an array of conditions. The following functions can be used on pools:
-
rolls(rolls)
- Passed an integer number, sets the exact number of rolls this pool should perform. Returns the pool itself. -
rolls(minRolls, maxRolls)
- Passed two integer numbers, sets the range of rolls this pool should perform. Returns the pool itself. -
bonusRolls(rolls)
- Passed an integer number, sets the exact number of additional rolls this pool should perform per int of luck. Returns the pool itself. -
bonusRolls(minRolls, maxRolls)
- Passed two integer numbers, sets the range of additional rolls this pool should perform per int of luck. Returns the pool itself. -
removeEntry(type, name)
- Passed two strings, removes any entry matching the type and name passed. The name is typically an item ID, tag ID, or loot table ID. Returns the pool itself. -
removeEntry(index)
- Passed one integer number, removes the entry at that index in the pool's entry array. Returns the pool itself. -
getEntry(type, name)
- Returns the first entry in the table which matches the type and name passed as a mutable loot entry (see below). -
getEntry(index)
- Passed one integer number, returns the entry at that index in the pool's entry array as a mutable loot entry (see below). -
addEntries(...entries)
- Adds the passed entries into the loot pool's entry array. Can be passed any number of entries separated by commas. Returns the pool itself. See below for entry construction. -
addConditions(...conditions)
- Adds the passed conditions into the loot pool's condition array. Can be passed any number of conditions separated by commas. Returns the pool itself. See below for condition construction. -
removeCondition(index)
- Passed one integer number, removes the condition at that index in the pool's condition array. Returns the pool itself.
LibCD can both modify existing loot entries and add new ones. Loot entries are created with the support of the Entries helper, which can be accessed with var Entries = libcd.require("libcd.loot.Entries")
. Entries can be constructed with the following functions:
-
item(name)
- Passed the string ID of an item, creates a new entry that drops a specific item. Returns a mutable loot entry (see below). -
tag(name)
- Passed the string ID of a tag, creates a new entry that drops a random item in a specific tag. Returns a mutable loot entry (see below). -
table(name)
- Passed the string ID of another loot table, creates a new entry that drops the contents of another loot table. Returns a mutable loot entry (see below). -
dynamic(name)
passed the string ID of a dynamic loot dropper, creates a new entry that drops the results of the dynamic dropper. The only dynamic dropper in vanilla is for shulker box contents, but mods may add other dynamic droppers. Returns a mutable loot entry (see below). -
combined(type, ...children)
- Passed a string ID of a combination type and any amount of mutable loot entries as children, creates an entry which combines the passed entries with logic defined by the type. The types included in vanilla are"alternative"
,"group"
, and"sequence"
. Returns a mutable loot entry (see below).
Mutable loot entries can be modified with the following functions:
-
type(type)
- Passed a string ID of a loot entry type, changes the type of drop for the entry. Returns the entry itself. -
name(name)
- Passed a string ID, changes the name of the entry. What this does depends on the type; anitem
type's name is the ID of the item to drop, atag
type's name is the ID of the tag to drop from, and aloot_table
type's name is the ID of the loot table to drop. Returns the entry itself. -
weight(weight)
- Passed an integer number, changes the weight of the entry. In a table with five entries with 1 weight and one entry with 3 weight, the entry with 3 weight will be dropped 3/8 of the time. Returns the entry itself. -
quality(quality)
- Passed an integer number, changes the quality of the entry. Entries with higher quality are more likely to drop with higher luck, and entries with lower quality are more likely to drop with lower luck. Returns the entry itself. -
addConditions(...conditions)
- Adds the passed conditions into the loot entry's condition array. Can be passed any number of conditions separated by commas. Returns the entry itself. See below for condition construction. -
addFunctions(...functions)
- Adds the passed functions into the loot entry's function array. Can be passed any number of functions separated by commas. Returns the entry itself. See below for function construction. -
property(name, value)
- Passed a string name and any primitive value, adds the value into the entry JSON at that name key. Generally used for loot entry types from other mods, which may require more information. -
element(name, value)
- Passed a string name and a stringified JSON value, adds the JSON into the entry JSON at that name key. Generally used for loot entry types from other mods, which may require more information.
Conditions can be added to both pools and entries, and determine whether the pool or entry is allowed to drop anything. LibCD provides a helper to build conditions, which can be added as var Conditions = libcd.import("libcd.loot.Conditions");
. The condition helper provides the following functions:
-
parse(json)
- Passed stringified JSON, constructs the JSON into a loot condition. Provided because some conditions are too complex to construct via code. Returns the constructed condition if the JSON is valid, or null otherwise. -
or(...conditions)
- Constructs a condition which returns true if any of the passed conditions is true. Can be passed any number of conditions separated by commas. Returns the constructed condition. -
not(condition)
- Passed a single condition, constructs a condition which returns true if the passed condition is false. Passes the constructed condition. -
killedByPlayer()
- Constructs a condition which returns true if the entity dropping this loot table was killed by a player. Returns the constructed condition. -
chance(chance)
- Passed a floating-point number between 0 and 1, constructs a condition which returns true randomly based on the percentage chance passed. A chance of 1 will always return true, and a chance of 0 will never return true. Returns the constructed condition. -
chanceWithLooting(chance, multiplier)
- Passed two floating-point numbers between 0 and 1, constructs a condition which returns true randomly based on the percentage chance passed, with a multiplier for looting. The chance is boosted by the level of looting times the multiplier value. Returns the constructed condition. -
survivesExplosion()
- Constructs a condition which returns true if the block dropping this loot table should have its block dropped when destroyed by an explosion. Returns the constructed condition. -
matchTool(item, nbt)
- Passed two strings, constructs a condition which only returns true if the block dropping this loot table was mined using an item matching the ID and stringified NBT passed.nbt
can be left as""
to ignore NBT testing. Returns the constructed condition. -
enchantBonus(enchantment, chances)
- Passed a string enchantment ID and an array of floating-point numbers, constructs a condition which has different chances of successful drop based on the value of the passed enchantment. Each successive element in the array defines a chance for a greater enchantment value. Returns the constructed condition. -
weather(raining, thundering)
- Passed two nullable booleans, constructs a condition which will return true based on the weather in the world when the loot table is rolled. Use null to ignore either check. Returns the constructed condition. -
predicate(id)
- Passed the string ID of a predicate JSON, constructs a condition which will return true if the predicate JSON returns true.
Functions can be added to both loot tables and entries, and add modifications to the items dropped. LibCD provides a helper to build functions, which can be added as var Functions = libcd.import("Functions");
. The function helper provides the following functions:
-
parse(json)
- Passed stringified JSON, constructs the JSON into a loot function. Provided because some functions are too complex to construct via code. Returns the constructed function if the JSON is valid, or null otherwise. -
countExact(amount)
- Passed an integer number, constructs a function which sets the count of the dropped stack to the value passed. Returns the constructed function. -
countRange(min, max)
- Passed two integer numbers, constructs a function which sets the count of the dropped stack to a value betweenmin
andmax
inclusive. Each value is equally likely. Returns the constructed function. -
countBinomial(n, p)
- Passed an integer numbern
and a floating-point numberp
between 0 and 1, constructs a function which sets the count of the dropped stack to a value based on a bell curve with maximum amountn
and midpointp
as a percentage ofn
. Returns the constructed function. -
fillPlayerHead(from, ...conditions)
- Passed a string value from and any amount of conditions, constructs a function which sets the NBT value on a player head drop to get the proper display based on thefrom
value.from
can be"this"
,"killer"
,"direct_killer"
, or"killer_player"
. Returns the constructed function. -
setNbt(nbt)
- Passed a wrapped compound tag (wiki article coming soon), constructs a function which sets the NBT tag on the dropped stack to the specified tag. Returns the constructed function.