gnembon / fabric-carpet

Fabric Carpet
MIT License
1.72k stars 275 forks source link

Attempting to run(...) commands from __on_tick() context always fails. #474

Closed James103 closed 4 years ago

James103 commented 4 years ago

As of Carpet Mod 1.4.11 for Minecraft 1.16.3, any attempt to execute a run('...') function will output A player is required to run this command here to stderr and return the following: [null, [], A player is required to run this command here]. The same is true regardless of which command is put into the run function.

Why is it that attempting to run commands from the __on_tick() function in any given app always fails and outputs A player is required to run this command here to stderr, even though the same commands outside that event context runs normally? It all still worked normally when I was on Minecraft 1.16.1 with Carpet mod 1.4.0.

There are a couple of workarounds:

  1. Use the __on_statistic event to run the commands (such as bossbar updates).
  2. Create a datapack to update the bossbars every tick.

My testing steps:

  1. Run /bossbar add test:a from chat.
  2. Create an app named a.sc with the following, and put it in the scripts folder of the world you are reproducing this on.
    __on_tick() -> (
    if(tick_time() % 20 != 0, return());
    if(rand(1)>0.5,
        x = run('bossbar set test:a players @a');
        print(1); print(x);,
        x = run('bossbar set test:a players');
        print(2); print(x);
    );
    )
  3. Run /script load a global from chat.
  4. Notice the output.
  5. Run /script run __on_player_jumps(p) -> (x = run('give @p stone'); print(x)) from chat.
  6. Jump repeatedly.
  7. Notice the output.
  8. Reload the world, then repeat from step 3. The output looks identical.
  9. Create an app named b.sc with the following, and put it in the scripts folder of the world you are reproducing this on.
    __on_player_takes_damage(p,a,b,c) -> (
    if(rand(1)>0.5,
        x = run('give @p stone');
        print(1); print(x);,
        x = run('give @p dirt');
        print(2); print(x);
    );
    )
  10. Run /script load b from chat (without the global).
  11. Step on a cactus or repeatedly run /tp @p ~ ~4 ~ from chat.
  12. Notice the output.
  13. Reload the world, and then run /script load b global from chat.
  14. Step on a cactus or repeatedly run /tp @p ~ ~4 ~ from chat.
  15. Notice the output. It looks identical to the output from step 12.
Output from reproduction steps The output from step 4 looks like this: ``` [16:31:42] [Server thread/INFO]: 1 [16:31:42] [Server thread/INFO]: [null, [], A player is required to run this command here] [16:31:42] [main/INFO]: [CHAT] [Server: 1] [16:31:42] [main/INFO]: [CHAT] [Server: [null, [], A player is required to run this command here]] [16:31:43] [Server thread/INFO]: 1 [16:31:43] [Server thread/INFO]: [null, [], A player is required to run this command here] [16:31:43] [main/INFO]: [CHAT] [Server: 1] [16:31:43] [main/INFO]: [CHAT] [Server: [null, [], A player is required to run this command here]] [16:31:44] [Server thread/INFO]: 2 [16:31:44] [Server thread/INFO]: [null, [], A player is required to run this command here] [16:31:44] [main/INFO]: [CHAT] [Server: 2] [16:31:44] [main/INFO]: [CHAT] [Server: [null, [], A player is required to run this command here]] [16:31:45] [Server thread/INFO]: 1 [16:31:45] [Server thread/INFO]: [null, [], A player is required to run this command here] [16:31:45] [main/INFO]: [CHAT] [Server: 1] [16:31:45] [main/INFO]: [CHAT] [Server: [null, [], A player is required to run this command here]] [16:31:46] [Server thread/INFO]: 1 [16:31:46] [Server thread/INFO]: [null, [], A player is required to run this command here] [16:31:46] [main/INFO]: [CHAT] [Server: 1] [16:31:46] [main/INFO]: [CHAT] [Server: [null, [], A player is required to run this command here]] ``` The output from step 7 looks like this: ``` [16:31:58] [main/INFO]: [CHAT] [1, [Gave 1 [Stone] to Player], null] [16:31:58] [main/INFO]: [CHAT] [1, [Gave 1 [Stone] to Player], null] [16:31:59] [main/INFO]: [CHAT] [1, [Gave 1 [Stone] to Player], null] [16:32:00] [main/INFO]: [CHAT] [1, [Gave 1 [Stone] to Player], null] ``` The output from step 12 looks like this: ``` [16:39:16] [main/INFO]: [CHAT] Teleported James3221 to -167.32679981930409, 67.0, 218.30087855250957 [16:39:17] [main/INFO]: [CHAT] 2 [16:39:17] [main/INFO]: [CHAT] [1, [Gave 1 [Dirt] to James3221], null] [16:39:17] [Server thread/INFO]: [James3221: Teleported James3221 to -167.32679981930409, 67.0, 218.30087855250957] [16:39:17] [main/INFO]: [CHAT] Teleported James3221 to -167.32679981930409, 67.0, 218.30087855250957 [16:39:17] [main/INFO]: [CHAT] 1 [16:39:17] [main/INFO]: [CHAT] [1, [Gave 1 [Stone] to James3221], null] [16:39:17] [Server thread/INFO]: [James3221: Teleported James3221 to -167.32679981930409, 67.0, 218.30087855250957] [16:39:17] [main/INFO]: [CHAT] Teleported James3221 to -167.32679981930409, 67.0, 218.30087855250957 [16:39:18] [main/INFO]: [CHAT] 2 [16:39:18] [main/INFO]: [CHAT] [1, [Gave 1 [Dirt] to James3221], null] [16:39:18] [Server thread/INFO]: [James3221: Teleported James3221 to -167.32679981930409, 67.0, 218.30087855250957] [16:39:18] [main/INFO]: [CHAT] Teleported James3221 to -167.32679981930409, 67.0, 218.30087855250957 [16:39:19] [main/INFO]: [CHAT] 1 [16:39:19] [main/INFO]: [CHAT] [1, [Gave 1 [Stone] to James3221], null] [16:39:19] [Server thread/INFO]: [James3221: Teleported James3221 to -167.32679981930409, 67.0, 218.30087855250957] [16:39:19] [main/INFO]: [CHAT] Teleported James3221 to -167.32679981930409, 67.0, 218.30087855250957 [16:39:19] [main/INFO]: [CHAT] 2 [16:39:19] [main/INFO]: [CHAT] [1, [Gave 1 [Dirt] to James3221], null] ``` Full modlist: * carpet-extra-1.16.3-1.4.11 * clientcommands-2.4.7 * fabric-api-0.21.0+build.407-1.16 * fabric-carpet-1.16.3-1.4.11+v200910 * litematica-fabric-1.16.3-0.0.0-dev.20200913.215807 * lithium-fabric-mc1.16.3-0.5.5 * malilib-fabric-1.16.3-0.10.0-dev.21+arne.1 * NoFog-1.16.2b1-Fabric
gnembon commented 4 years ago

That probably spoiled the fun of the new run command output for you. Should be easy to fix.

James103 commented 4 years ago

@gnembon Just out of my curiosity: Why are most (if not all) of your commits have their commit date set to 3 hours later than when you actually pushed the commit? I presume it's because you are using the wrong time zone on your local machine / Git client.