• 510 views, 2 today
    • 17 downloads, 0 today
    • 3
    • 1
    olinolivia
    Level 15 : Journeyman Cat
    2
    Simple datapack that enables looping through NBT lists, byte arrays, integer arrays and float arrays with ease.

    Usage


    Example statement



    This statement reads the NBT data of a chest one block below the entity that runs it, and for each item in it, prints the item ID to chat using an external print function

    function nbt_for:api/for {source: "block", target: "~ ~-1 ~", list_path: "Items", item_path: "id", function: "datapack:print"}

    Arguments

    source: The type of NBT source to draw from. Can be either block, entity, or storage.
    target: The target to draw the NBT data from.If source is set to block, it is the coordinates to the block entity to draw from. If it is set to entity, it is the target selector for the entity to draw from. If it is set to storage, it is the storage ID for the storage to draw from.
    list_path: The NBT path to the list to iterate through.
    item_path (optional): The NBT path to navigate for each item before running the function. If not needed, set this to an empty string.
    function: The function to run for each item

    Accessing the items' contents

    In order to access the contents of the items you are iterating through in the function to loop, use a macro with the keyword $(item). If item_path is set, the macro will be set to the output of navigating that path, starting from the item.
    CompatibilityMinecraft 1.21
    Tags

    Create an account or sign in to comment.

    Welcome