Skip to content

Limiting origins in the base origin layer

eggohito edited this page Mar 18, 2022 · 3 revisions

In the following steps, we'll be using this datapack as our template.


1.) Create a .json file in the data/origins-limiter/advancements/can_pick folder of your datapack. For consistency, I advise that you name the .json file after the identifier of the origin, and place it inside a folder that is named after the namespace of the origin.

Example (click me!)

In this example, we'll be naming the .json file as origin.json and place it inside a folder named example:

data/origins-limiter/advancements/can_pick/example/origin.json

{
    "criteria": {
        "dummy": {
            "trigger": "minecraft:impossible"
        }
    }
}

2.) Create an .mcfunction file (a .txt file with the .mcfunction file extension) in the data/origins-limiter/functions/can_pick folder of your datapack. This function will be the one counting how many players currently have the origin that we want to limit. For consistency, I advise that you name the .mcfunction file after the identifier of the origin, and place it inside a folder that is named after the namespace of the origin.

Example (click me!)

In this example, we'll be naming the .mcfunction file as origin.mcfunction and place it inside a folder named example.

data/origins-limiter/functions/can_pick/example/origin.mcfunction

#
#   Set the max count for this origin once (can then be changed in-game afterwards)
#
#   - `example:origin` = being the namespace and ID of the origin that you wish to limit 
#
execute unless score example:origin o-l.max = example:origin o-l.max run scoreboard players set example:origin o-l.max 1


#
#   Store the count of the players that currently have this origin
#
#   - `example:origin` = being the namespace and ID of the origin that you wish to limit
#
execute store result score example:origin o-l.cur if entity @a[tag = !origins-limiter.ignore, nbt = {cardinal_components: {"origins:origin": {OriginLayers: [{Origin: "example:origin"}]}}}]


#
#   Grant the player an advancement to indicate that the player can choose the origin. Revoke the advancement otherwise
#
#   - `example:origin` = being the namespace and ID of the origin that you wish to limit
#   - `origins-limiter:can_pick/example/origin` = being the advancement you made for the origin
#
execute if score example:origin o-l.cur < example:origin o-l.max run advancement grant @a only origins-limiter:can_pick/example/origin

execute if score example:origin o-l.cur >= example:origin o-l.max run advancement revoke @a only origins-limiter:can_pick/example/origin

3.) Create a .json file named as tick.json in the data/origins-limiter/tags/functions folder of your datapack. Afterwards, reference the namespace, path and ID of the function that you've created from Step 2 in the values string array field of the file.

Example (click me!)

In this example, we'll be referencing the origins-limiter:can_pick/example/origin function, which is the .mcfunction file that we made in Step 2.

data/origins-limiter/tags/functions/tick.json

{
    "values": [
        "origins-limiter:can_pick/example/origin"
    ]
}

4.) Create a .json file named as origin.json in the data/origins-limiter/origin_layers/confirm/origins folder of your datapack. In the origins string array field of the file, you'll need to use Conditioned Origins to check whether if the player has the origin that we want to limit and the advancement that we made in Step 1 or not.

Example (click me!)

In this example, we'll be checking if the player has the example:origin origin and the origins-limiter:can_pick/example/origin advancement that we made in Step 1. We'll also check if the player has the example:origin but not the origins-limiter:can_pick/example/origin advancement that we made in Step 1 to restrict them.

data/origins-limiter/origin_layers/confirm/origins/origin.json

{
    "order": 1,
    "name": "confirmed Origin",
    "missing_name": "None",
    "missing_description": " ",
    "origins": [
        {
            "condition": {
                "type": "origins:constant",
                "value": false
            },
            "origins": [
                "origins-limiter:empty",
                "origins-limiter:pass"
            ]
        },
        {
            "condition": {
                "type": "origins:and",
                "conditions": [
                    {
                        "type": "origins:origin",
                        "origin": "example:origin"
                    },
                    {
                        "type": "origins:advancement",
                        "advancement": "origins-limiter:status/ignore",
                        "inverted": true
                    },
                    {
                        "type": "origins:advancement",
                        "advancement": "origins-limiter:can_pick/example/origin"
                    }
                ]
            },
            "origins": [
                "example:origin"
            ]
        },
        {
            "condition": {
                "type": "origins:and",
                "conditions": [
                    {
                        "type": "origins:origin",
                        "origin": "example:origin"
                    },
                    {
                        "type": "origins:advancement",
                        "advancement": "origins-limiter:status/ignore",
                        "inverted": true
                    },
                    {
                        "type": "origins:advancement",
                        "advancement": "origins-limiter:can_pick/example/origin",
                        "inverted": true
                    }
                ]
            },
            "origins": [
                "origins-limiter:status/restrict"
            ]
        }
    ],
    "auto_choose": true,
    "hidden": false
}

Clone this wiki locally