Minecraft Random Item Name
The problem is that Minecraft provides next to no string manipulation. What it does instead of concatenation (adding two strings together character by character) is it uses something called JSON strings.
Difference between a string literal and a JSON string
String literals are things such as "minecraft:stone"
. They are frequently used for IDs and are not changeable.
JSON strings are things like
[\"\",{\"nbt\":\"nbtPath\",\"storage\":\"storagename\"}]
and are frequently surrounded by '
This JSON string is interpreted by Minecraft and indicates that instead of a hardcoded string, it should look at the NBT storage storagename
and from that get the value assigned to the NBT path nbtPath
.
Visual Strings
There is a third type of string, which I can only call a Visual String. It's format is as follows:
'{"extra":[{"text":"b"},{"text":"c"}],"text":"a"}'
This would, for anything compatible such as bossbars, entity names, item names, and many more, display as abc
Addressing your issue
In order to accomplish your goal of what essentially amounts to concatenating 3 phrases, all you need to do is tell minecraft to look at these 3 NBT values.
How to do this
Assuming your method for generating prefix/name/suffixes creates 3 different NBT storage values, then all you would have to do is generate the 3 values and store them in storagename.prefixPath
,storagename.namePath
, and storagename.suffixPath
respectively
Now, I'm not sure if it'll figure out that storagename.nbtPath
should be an array, so you might have to have an extra data modify
command to declare storagename.nbtPath
to be an empty array.
then what you should be able to do is
setblock <x> <y> <z> oak_sign{Text1:"[\"\",{\"nbt\":\"prefixPath\",\"storage\":\"storagename\"},{\"text\":\" \"},{\"nbt\":\"namePath\",\"storage\":\"storagename\"},{\"text\":\" \"},{\"nbt\":\"suffixPath\",\"storage\":\"storagename\"}]"}
This command will setblock a sign, which acts as a middleman to convert JSON strings to Visual strings, as Visual strings have hardcoded values.
Finally, all you have to do is
data modify <block|entity> pathToItemName set from block <x> <y> <z> Text1
Sorry about the two-stage answer. You should be good to go now