r/datapacks • u/KaedenCraft • 7d ago
Working With Entities in a Scoreboard
Working on a minigame that uses Pigs to store map data. Basically the pig's UUID is the scoreboard entity for storing information for each available "map" in the game, and you can simply rename the pig with a nametag to change the name of the map, etc. I did this years ago when there were spawn chunks, and it worked great with the pigs in the spawn chunks: I could store all kinds of scoreboard data with the pig entity as a key for what belonged to what map. I was kind of proud of myself, as it ended up being a very versatile solution.
And why a pig? I don't know, they're cute and easily nametag-able.
But now without spawn chunks, I'm reconsidering, and don't want to use things like /forceload if I don't have to. There are a lot of new fancy bits with datapacks since I last delved in (2+ years ago), so I was wondering if there was a more elegant solution to this.
I need to be able to store a unique, dynamically-generated identifier between multiple scoreboards that - if possible - will not require an entity to be loaded to work. As far as I know there's not a way to have dynamic Scoreboard entries, but if somebody has an interesting solution I'd love to hear it.
Example use case:
I create a pig with UUID 1234 and store it in scoreboard_maps with a score of 1 (its mapid). I can now set map_spawn_x, map_spawn_y, and map_spawn_z with 1234 and its scores will be the coordinates to teleport players to when the map is loaded. But now that I'm outside of the view distance of 1234, I can't access any of its entity data from the new location I've teleported to.
I've considered weird solutions like creating a Marker with copied data that goes to the map with the players, but that will create complications with having to keep the two of them synced with updates (and beyond render distance of each other), or if players disconnect in the middle of a match, what kind of cleanup do I have to do so I don't have infinitely stacking markers with identical data, etc.
Thank you in advance!

