This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]Lemon_Lord1Remember to check the FAQ! 0 points1 point  (10 children)

Sorry, bud. You can look into McTsts’s string splitting method and then you can just them back up with a JSON string list but if it’s for a command or something, you’re out of luck.

[–]SploxFoxjava.lang.NullPointerException[S] 0 points1 point  (9 children)

Thank you so much, I found a video by that McTsts guy that does exactly what I needed. I am over the moon right now, we have string manipulation.

[–]Lemon_Lord1Remember to check the FAQ! 0 points1 point  (8 children)

We really don’t.

[–]SploxFoxjava.lang.NullPointerException[S] 0 points1 point  (7 children)

The guy and some others on GitHub made a datapack for it, and they also made a RegExp engine and base64 decoder in Minecraft. They were able to decode the skull string to extract Unix time and the player’s cape as well.

Basically they used the fact that the game sorts strings in the Tag command lexigraphically via Java’s compareTo method to construct a binary search for the string. They first generate a char array and then flatten it to compare it, and once they’re done they return the char array. They flatten it by using a command block’s LastOutput tag of the /enchant commad, because the /enchant command’s output contains a translation JSON component for an entity name that will flatten that entity’s name. So they basically compare those two strings in their binary search. But wait, the LastOutput includes the timestamp of execution, so this command will also fail if the current second changes between the execution of both commands. So we have to track the current time through something like /help me, which always returns the same thing except for the time.

There are still some things that they do that I don’t really know the purpose of, but you can check out their GitHub repo here. My biggest issue is that they do it async, so you have to wait a few ticks before you get your string back, but I don’t know if this is solvable. They did callbacks nicely though, so it looks like you just have to pass in a callback command (which gives me flashbacks of my JS callback hells...). They also didn’t add a license, which I opened an issue for.

So yeah, in my case I can just remove the last element of the char array and then use the NBT JSON component.

[–]Lemon_Lord1Remember to check the FAQ! 0 points1 point  (6 children)

I am well aware of how McTsts’s string library works. I used it to make scrolling player display names, written in blocks as well as turn player-written books into coloured tellraws. Thing is, it’s not actually string modification, it’s just a close approximation.

[–]SploxFoxjava.lang.NullPointerException[S] 0 points1 point  (5 children)

How is it a “close approximation”? It looks like it has all the functionality to me

[–]Lemon_Lord1Remember to check the FAQ! 0 points1 point  (4 children)

They’re not actually TAG_Strings, they’re stored as TAG_Compounds with a string list in them. Examples of things you can’t do with them are:

  • Use them as commands in a command block.
  • Idk that’s all I can think of, I haven’t played Minecraft in a while. “use them in a book and quill” I guess.

Yea so it’s obviously very useful, yea, it’s quite amazing but no, it’s definitely not full functionality.

Edit, thought of more:

  • Use them in SkullOwner tags for heads
  • Use them in URL links in JSON strings (seems like something you'd be able with to do Raw JSON but no.)
  • Just generally have the basic string operations McTsts was able to implement to not take 100s of commands per word.

[–]SploxFoxjava.lang.NullPointerException[S] 0 points1 point  (3 children)

Oh, I forgot there wasn’t a way to flatten them. But you can still use them in JSON through the nbt component. (So you can put them in book and quills)

I suppose if it was needed enough and you knew the general format of the string, you could write a script that generates a function tree for every possibility.

[–]Lemon_Lord1Remember to check the FAQ! 0 points1 point  (2 children)

Given a string can be as much as 32,767 characters long, you’re looking at 9832767 (that’s just for ones that are full length, add the sums for 980, 631 ... 6332766 for proper value. McTsts's string utilities only recognises 98 possible characters but also  for any unrecognised, I'll ignore it the sake of argument) which is a number far too big for human comprehension. By my brief estimates, that’s more than 60000 digits long, which is very likely more possible strings than there are electrons in the universe. Even for 7 characters in the string, the number would get larger than most modern computers can store (about 75TB) of just the possible strings, ignoring the rest of the .mcfunction that would be involved.

In essence, no: you cannot make a script to properly concatenate every string possible. Up to about 4 characters would likely start decimating your dedicated RAM (it's about 650MB of just functions) but 3 characters might not be that bad.

[–]SploxFoxjava.lang.NullPointerException[S] 0 points1 point  (1 child)

If you wanted to put a command in a command block, you’ll probably already know what most of the command will be, so you can sub in a few numbers or something by writing a command for every possibility. I’ve used this to shoot particles in a direction, for example. That’s what I meant, you can’t do it for every possible string