lib_lore is a mcfunction library that allows other datapacks to easily search, remove, insert, and replace lines of lore on items.
There are 4 operations that can be applied. Each operation uses data storage and scoreboards as inputs and outputs.
There are three data storage inputs, along with two scoreboard inputs. Below are their terminologies (will be used further in this document), as well as their uses and the command to set them.
Source: This is a list of the lore that will be modified, typically this would be extracted directly from the item being modified, but can be set manually to a desired set of lore.
data modify storage gm4_lore:temp Source set from <...>Target: This is a single json item (i.e. a single 'line' of lore) that will be found during the operations. This sets the line of lore to be searched, removed, inserted after, or replaced.
data modify storage gm4_lore:temp Target set from <...>Input: This is list of the lore that will be inserted or replaced. This should not be set when simply searching or removing and will be ignored if set while using the search of remove operation.
data modify storage gm4_lore:temp Input set from <...>start: This is an integer that determines where the operation will start. It is essentially the offset for the operations. More specific use cases can be found under each specific operation description.
scoreboard players set $start gm4_lore <value>extra: This is an integer that determines the extra lines to be removed after the initial line. This is only used during the remove operation and will be ignored otherwise. More specific use cases can be found under the remove operation description.
scoreboard players set $extra gm4_lore <value>There are three outputs to work to work with after running an operation. Each operation uses the three outputs differently, which can be found under the specific operation description. Below are their terminologies (will be used further in this document), as well as their general uses and the command to get them.
Source: This is the modified version of the input Source.
data get storage gm4_lore:temp SourceDump: This is extra info about the operation that was used, usually the line of lore that was modified.
data get storage gm4_lore:temp Dumpindex: This is the index of the lore where the operation took place.
scoreboard players get $index gm4_loreBelow are the four operations and how to utilize them. Note that every operation requires Source and Target to be set.
Removes a specified line of lore
startdetermines where the removal will start when it finds theTargetline; this can be negative to start removing before the line or positive to start removing after the line. Defaults to 0.extradetermines how many more lines to remove after the first target line is removed. Must be positive. Defaults to 0. If set to -1, every line after the first target line will be removed.
function #gm4_lore:removeSourceis the updatedSourcewithout theTargetline.Dumpis the removed line of lore.indexis the location of first line that was removed.
Finds the index of a specified line of lore
startdetermines where the search will start; must be a positive number. Defaults to 0.
function #gm4_lore:searchSourceremains unchanged.Dumpis the found line of lore (Target).indexis the location of first line that was found.
Inserts lines of lore after a specified line of lore
Inputdetermines the lines of lore to add after theTargetlinestartdetermines where the insertion will start when it finds theTargetline; this can be negative to insert before the line or positive to insert after the line. Defaults to 0.
function #gm4_lore:insertSourceis the updatedSourcewith the added lore.Dumpis the added lines of lore (Input).indexis the location of first line that was added.
Replaces a specified line of lore with one or more new lines of lore
Inputdetermines the lines of lore to replace theTargetlinestartdetermines where the search for theTargetline will start; must be a positive number. Defaults to 0.
function #gm4_lore:replaceSourceis the updatedSourcewith the replaced loreDumpis the replaced line of lore (Target)indexis the location of first line that was replaced.
Please note that the example_pack must be started by calling #load:load, as a proper load implementation is not included.
- Technically the item isn't modified directly, this means the
Sourceand be added to the lore of the item using the defaultdata modifyoperations. - These operations are technically not limited to lore, but can also be used for any type of list.