1.0.0 • Published 4 years ago

prismarine-loottable v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

prismarine-loottable

NPM version Build Status Discord Gitter Irc Try it on gitpod

A utility package for parsing Minecraft loot table files.

Based on Loot Table format: https://minecraft.gamepedia.com/Loot_table

Usage

const getPotentialDrops = require("prismarine-loottable").getPotentialDrops;
const lootTable = require('./path/to/table.json')

const drops = getPotentialDrops(lootTable)

const itemType = drops[0].itemType
const silkTouch = drops[0].requiresSilkTouch()

API

Global Functions

getPotentialDrops(lootTable: MinecaftLootTable): LootItemDrop[]

This function can be used to directly parse a raw Minecraft loot table to pull out all potential drops as well as conditions required for that item to drop and functions that applied to the item (or user) in order. It returns a list of potential item drops.

Classes

LootItemDrop

This object is the main object returned from the getPotentialDrops function. It contains information about the details involved in getting this item to drop from the table.

  • lootItemDrop.itemType: string Gets the name of the item type which is dropped. This is a namespaced value.

  • lootItemDrop.minCount: number The smallest number of this item type which can be dropped, assuming all conditions are met. This does not take functions into consideration, which may change this value.

  • lootItemDrop.maxCount: number The maximum number of this item type which can be dropped assuming all conditions are met. This does not take functions into consideration, which may change this value.

  • lootItemDrop.functions: LootFunction[] The list of all functions that should be applied to this item drop, in order. Some functions may contain additional conditions required for them to occur.

  • lootItemDrop.conditions: LootCondition[] The list of all conditions which are required for this item drop to occur. This list contain conditions from both the item drop entry as well as the pool the item drop is in. These conditions do not have to be applied in any other but all conditions must be true.

  • lootItemDrop.weight: number The randomness weight of this item drop within the pool, relative to other entries in the pool. Items with a higher weight are more likely to be dropped than items with a lower weight compared to other entries in the same pool.

  • lootItemDrop.quality: number The bonus weight to add for each point of luck being used. The new weight value is calculated via the formula: floor(weight + (quality * generic.luck)) More information can be found on the Minecraft wiki page.

  • lootItemDrop.poolIndex: number The index of the loot table pool this item drop is located in.

  • lootItemDrop.entryType: string This value contains the entry type of the parent entry this item drop occurs from. For item drops not being nested, this is equal to minecraft:item. For item drops which are nested inside another entry, this value contains the parent entry's group type. group, alternatives, or sequence. This can be used to calculate more information about how item drops are calculated compared to the siblings

  • lootItemDrop.sibling: LootItemDrop[] A list of all other item drops that come from the same pool as this item drop. The list also contains this item.

  • lootItemDrop.requiresSilkTouch(): boolean Checks if any of the drop conditions is a silk touch requirement.

  • lootItemDrop.requiresNoSilkTouch(): boolean Checks if the item drop requires the tool to not have silk touch.

  • lootItemDrop.requiresPlayerKill(): boolean Checks if the item drop requires the entity to be killed by a player directly.

  • lootItemDrop.estimateDropChance(looting?: number, luck?: number): number Estimates the drop chance of the item with the given luck potion effect, looting enchantment level and all relevant functions and conditions applied to the item drop. If the looting parameter is not defined, it is defaulted to 0. If the luck parameter is not defined, it is defaulted to 0.

  • lootItemDrop.getRequiredBlockAge(): number Gets the required age of the block (for plant based blocks) in order for this item drop to occur.

  • lootItemDrop.getStackSizeRange(fortune?: number, looting?: number): [number, number] Gets the range of potential stack sizes for this item drop. This value may exceed the actual size of a Minecraft stack. If looting or fortune enchantments are used, the level can be specified to produce a more accurate range.

LootFunction

Contains information about a function to be applied to an item drop. The properties within this class match the properties of the given type as defined within the Minecraft Loot Table format.

  • lootFunction.type: string The namespaced type of function that is being applied.

  • lootFunction.onPool: boolean True if this function is applied to the entire pool. False if this function is only applied to the item.

LootCondition

Contains information about a condition required for an item drop to occur. The properties within this class match the properties of the given type as defined within the Minecraft Loot Table format.

  • lootCondition.type: string The namespaced type of condition that is being applied.

  • lootCondition.onPool: boolean True if this condition is applied to the entire pool. False if this condition is only applied to the item.

  • lootCondition.isSilkTouch(): boolean Checks if the condition is a silk touch check.