Command is running weirdly from load.json (datapack)



  • Could someone help me? I am thoroughly confused. I have a command in my datapack that is executed from load.json function:

    execute unless entity @e  
    [type=armor_stand,name=team_lives,scores={first_time_setup=1}]  
    run summon armor_stand 0 255 0 {Tags:["armor_stand_life"],  
    Invisible:4b,Invulnerable:4b,PersistenceRequired:4b,NoBasePlate:4b,NoGravity:4b,  
    CustomName:'{"text":"team_lives"}',DisabledSlots:4444959} 
    

    Basically, what this will do is unless first_time_setup (the score) = 1 then it will summon a new armor stand. first_time_setup is automatically set to 1 with another function, and I checked there is an armor stand in the world that has first_time_setup=1 which means that is should not summon a new one.
    When I run it via a command block nothing happens like it should. But for some reason, when it's in the datapack (despite me having ran it via command block and it working as intended) it summons a new armor stand (but it shouldn't).

    I'm doing this in single player, and I've noticed that it only happens when I leave/re-join a world, so it has to be coming from the load.json function, since when I disable/re-enable the datapack nothing breaks. This leads me to believe that here may be a time between load.json loading and running the command then the the world fully loading (with the armor stand in it). So it might be that the armor stand isn't loaded at the time it checks.

    Either way any ideas?



  • I ended up posting on another forum and got an answer. Check the first comment in this post from planet minecraft if you still want an answer:

    https://www.planetminecraft.com/forums/minecraft/datapacks/help-load-json-causing-problems-652896/

    You could also just put the command in a different function and schedule it. For Example:

    load.mcfunction:

    schedule function :load_delayed 40t append
    

    load_delayed.mcfunction

    execute unless entity @e[type=armor_stand,name=team_lives,scores={first_time_setup=1}] run summon armor_stand 0 255 0 {Tags:["armor_stand_life"],Invisible:4b,Invulnerable:4b,PersistenceRequired:4b,NoBasePlate:4b,NoGravity:4b,CustomName:'{"text":"team_lives"}',DisabledSlots:4444959}
    

    That would execute load_delayed.mcfunction (your previous load.mcfuntion) 40t (=2s) after the world has loaded, when the armorstand already should have loaded. This for sure is not the best method to do it, because a slow computer might need a longer delay and a fast computer would be okay with a shorter delay, but it is the easiest solution I could think of. Also as toothgenie already said, you should use markers instead of armorstands in 1.17+.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2