GnaspGames / Smelt

A CLI tool for Minecraft map makers
http://smelt.gnasp.com
MIT License
19 stars 4 forks source link

Consider whether the new "Advancements" & "Functions" feature can be used to import commands #99

Open GnaspGames opened 7 years ago

GnaspGames commented 7 years ago

The advancements feature can be used to trigger commands from a JSON file.

See: http://minecraft.gamepedia.com/Commands#advancement And: http://minecraft.gamepedia.com/Advancements

GnaspGames commented 7 years ago

Notes

The advancement JSON file needs to go into the world directory, under /data/advancements/FOLDER/FILE.json. We would use the folder name of smelt, and a filename matching the module filename for each module. The trigger impossible can be used on module advancement files so that they can only be granted via commands.

The advancement trigger location can be used without criteria to automatically get granted to all players who haven't had it before. So long as the filename has not be used before, this will then automatically get triggered when joining the world or when resource packs are refreshed using F3 + T.

This approach could be used to generate randomly names advancement files that then grant & revoke access to the module advancements.

The issue we have with the location trigger is that if multiple players are in the world, it will grant to ALL of them and run the associated commands on ALL of them. This leads to the module advancement commands being run multiple times.

E.g.

RANDOM_FILE_NAME.json

{
    "criteria": {
        "findme": {
            "trigger": "minecraft:location"
        }
    },
    "rewards": {
        "commands": [
            "/say SMELT RANDOM: @s going to grant to Gnasp",
            "/execute @s ~ ~ ~  /advancement grant @p[name=Gnasp] only smelt:test",
            "/say SMELT RANDOM: @s granted to Gnasp",
            "/execute @s 0 10 0 /advancement revoke @p[name=Gnasp] only smelt:test",
            "/say SMELT RANDOM: @s revoked to Gnasp"
        ]
    }
}

test.json

{
    "criteria": {
        "findme": {
            "trigger": "minecraft:impossible"
        }
    },
    "rewards": {
        "commands": [
            "/say TEST: This is the test advancement 2!",
            "/say TEST: I'm @s !"
        ]
    }
}

Produces this:

Smelt/Advancement test

This feature would only work in Single Player worlds anyway, so maybe it doesn't matter that commands are executed once for each player (if there are multiple on LAN).

If we do go ahead, maybe we could use a certain trigger to target one player.

If it does @mrjvs suggests that we could use the minecraft:inventory_changed trigger.

GnaspGames commented 7 years ago

Mojang have released a 1.12 pre-release that removed Advancements 'commands' and replaces it with 'functions'. See https://minecraft.net/en-us/article/minecraft-112-pre-release-1

This would change now this feature, if it get's built, would work.