String comparison issue with Get display name of provided entity

Started by Lix_DansSonLabo on

Topic category: Help with MCreator software

Last seen on 08:01, 14. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
String comparison issue with Get display name of provided entity
Mon, 06/01/2020 - 12:48 (edited)

Hello !

I'm quite new with MCreator and I'm working on a tabletop plugin for roleplay game.

I'm using 2020-2 because I'm stuck with 1.12.2 mods that are not yet migrated to 1.15...

 

I'm having an issue with the block "Get display name of provided entity" which has a very strange behaviours.

It seems there is un issue with the value returned by this block.

 

Case 1 :

For instance, I'm "Player123" which is 9 char. Making a print shows of the lenght of "Get display name of provided entity" show 11 char long.

Case 2 :

I created a command to set a global string var et set it a Player name in it.

When I compare this string to the one of Case 1, it's different. As long as it's not the same lenght, i understand, even if i don't know why Case 1 returned 11 char long string.

When I substring Case1 returned value to get "Player123", it gives me "Player123" with 9 char string, but comparing whit the global string variable I set with my manual command, comparison return false.

Case 3 :

I created an item to allow user to set himself this global variable using the block "Get display name of provided entity" and it works fine.

But it's not the way I want to do this as long as, as a Game Master, I want to be able to be the only one to set the player name in this variable.

 

 

As I'm a C# dev and I'm not used to Java, I'm not very used to how all of this works. (reason I'm using your awesome tool).

Btw, please don't ask me to update 2020-3 because I'm can't upgrade to MC 1.14 or 1.15 right now.

 

Picture of String comparison : https://ibb.co/brkcvRq

Setting the global string var :https://ibb.co/XkVwPsw

 

Thks in advance for your kind help

Lix

Edited by Lix_DansSonLabo on Mon, 06/01/2020 - 12:48
I suggest using print block…
Wed, 06/03/2020 - 10:09

I suggest using print block to print strings to console to see actual contents of the strings you are comparing.

Last seen on 08:01, 14. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It's what I did to test…
Wed, 06/03/2020 - 10:20

It's what I did to test string lenght and string value.

Assuming player name is Player123 (9 char long) :

- A build string surrounding the [Get display name of provided entity retrun] with brackets returns : [Player123]

- A print of [Get display name of provided entity retrun] returns : Player123

- A print of [lenght of] => [Get display name of provided entity retrun] returns : 11

Last seen on 08:01, 14. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
After many hours, a lot of…
Thu, 06/04/2020 - 09:20

After many hours, a lot of search into MCreator code and some try with plugins, I think finally found a way...

 

I searched the java.ftl code of entity_name which is : (entity.getDisplayName().getFormattedText())

Then I search in Mc and Forge documentation about entity.getDisplayName() and found an getUnformattedText() which I setup in a MCreator plugin.

 

GetPlayerName.json :

{
  "message0": "Get raw display name of provided entity",
  "output": "String",
  "colour": "%{BKY_TEXTS_HUE}",
  "mcreator": {
    "toolbox_id": "lix",
    "dependencies": [
      {
        "name": "entity",
        "type": "entity"
      }
    ]
  }
}

GetPlayerName.java.ftl :

(entity.getDisplayName().getUnformattedText())

And withi this new block, it returns a string that has the good lenght and compare correctly to manual username input

 

So, i dono if it's okay or not in 2020-3 and -4 but you might actually want to check and maybe update this...

 

Nice find, probably…
Thu, 06/04/2020 - 10:26

Nice find, probably formatted string adds some invisible formatting characters. Thank you very much for your work.

I will fix the procedure to return the unformatted text in 2020.4 ;)

Last seen on 08:01, 14. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I klnow you do not support…
Thu, 06/04/2020 - 10:35

I klnow you do not support anymore 2020-2 but my but you could considere creating a plugin to add later fixes OR add a section or something in the forum to list what must be done for those who required 2020-2 (1.12.2 only) long terme support ?

I open-sourced 1.12.2…
Thu, 06/04/2020 - 13:43

I open-sourced 1.12.2 generator for this reason. You can find it on https://github.com/Pylo/MCreatorGenerator-Forge-1.12.2.

Feel free to open a pull request or even make own plugin for 1.12.2 out of it.

Users interested can also port generator to 2020.3, but I personally can't as I am busy working on 1.14.4 and 1.15.2 and can't maintain another version.

Last seen on 08:01, 14. Jun 2020
Joined May 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay. thanks a lot. I did…
Thu, 06/04/2020 - 13:44

Okay. thanks a lot. I did not notice this information.

I understand your issue with 1.12.2 maintenance.