Skip to content

Instantly share code, notes, and snippets.

@intsuc
Last active August 22, 2019 15:25
Show Gist options
  • Save intsuc/5bbf8398f82a898796330d00ea8513b3 to your computer and use it in GitHub Desktop.
Save intsuc/5bbf8398f82a898796330d00ea8513b3 to your computer and use it in GitHub Desktop.
usercache map (non-username string -> UUID string)
  • Any entities that extend TameableEntity or AbstractHorseEntity works.

  • To jump to the else branch that performs the lookup:

    • HandItems[0].tag.OwnerUUID must not be TAG_String.
    • HandItems[0].tag.OwnerUUID and HandItems[0].tag.Owner must be assigned to the entity together.
String uuid;
if (tag.containsKey("OwnerUUID", TAG_String) /* This method returns false if an actual tag type is different from the specified type */) {
    uuid = tag.getString("OwnerUUID");
} else {
    String owner = tag.getString("Owner");
    uuid = ConfigHandler.getPlayerUuid(getServer(), owner); // The lookup is performed here using `Owner`.
}
data modify entity 0-0-0-0-0 HandItems[0].tag.Owner set ...
data modify entity 0-0-0-0-0 Tags append from entity 0-0-0-0-0 HandItems[0].tag.Owner
execute store result score #tags_size usercache_map run data get entity 0-0-0-0-0 Tags
data modify entity 0-0-0-0-0 {} merge from entity 0-0-0-0-0 HandItems[0].tag
# execute if score #tags_size usercache_map = #size usercache_map run tellraw @s ["some ", {"entity": "0-0-0-0-0", "nbt": "OwnerUUID"}]
# execute unless score #tags_size usercache_map = #size usercache_map run tellraw @s "none"
summon minecraft:parrot 0 0 0 {HandItems: [{id: "minecraft:tnt", Count: 1b, tag: {Tags: ["#a", "#b"], OwnerUUID: false}}], UUIDMost: 0L, UUIDLeast: 0L, Invulnerable: true, Silent: true, NoAI: true}
data modify entity 0-0-0-0-0 Tags set from entity 0-0-0-0-0 HandItems[0].tag.Tags
scoreboard objectives add usercache_map dummy
execute store result score #size usercache_map run data get entity 0-0-0-0-0 HandItems[0].tag.Tags
[
{
"name": "#a",
"uuid": "0-0-0-0-a"
},
{
"name": "#b",
"uuid": "0-0-0-0-b"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment