Implementing Minecraft Banner Text Parsing

This is a complex question, so I apologize in advance. Believe it or not, this is for an assignment in a college-level class.

I am trying to implement a lexer in Minecraft that interprets different types of number-looking banners. The functionality I am looking to achieve is very similar to SethBling's Scrabble Spell Checker. Essentially, when a number of various banners are placed, some series of command blocks are triggered.

So let's say I want to interpret these banners and set a scoreboard objective to be 149:

Number banners

Here's my understanding of how this functionality works:

  1. There is a dummy scoreboard object configured to act a counter
  2. A command block would spawn in an armour stand to the far right of the banners and it could step the armour stand to the left 1 block after every iteration using relative coordinates
  3. At each "step", the armour stand would have to issue a testfor command and then, depending on the result, would have to add that respective value to the scoreboard

Step 3. is the heart of my question. In SethBling's example he uses this command:

/execute @e[type=ArmorStand,name=Lexer] ~ ~ ~ /testforblock ~ ~ ~ wall_banner -1 {Patterns:[{Pattern:"ls",Color:0},{Pattern:"bs",Color:0},{Pattern:"bo",Color:15}]}

Where it's clear the banner type is being identified. But I'm not sure how it is possible to do anything with this result.

Am I on the right track with this logic? How can I use the result from the testfor command issued by the armour stand?

Once I figure out the value of the banner, how can I add this result to the relative total (ie. 9 + 40 + 100), since I can't perform mathematical operations inside the command block?

I know this question involves a lot of complex command block logic. Thanks so much for your help!


Solution 1:

You can use the /stats or check the CommandStats datatag of the ArmorStand. I highly recommend use of the /stats command.

Extract the result:

Run these commands once
Note: Anything suffixed with a "_v" can be whatever you want, as long as they're consistent.

/scoreboard objectives add SuccessCount_v dummy
/stats entity @e[type=ArmorStand,name=Lexer] set SuccessCount @e[type=ArmorStand,name=Lexer] SuccessCount_v

This will store the SuccessCount (in case of this command, 0 or 1) in the scoreboard as @e[type=ArmorStand,name=Lexer] SuccessCount_v, which you can then test and use as you would any other scoreboard value.

Add results together:

I'm not going to go into detail here, since I am unsure exactly you want to add together. I will, however link you to a wiki page where you can find the format of /scoreboard players operation <selector> <objective> <operator> <selector2> <objective2>, the only method for doing math in command blocks. (Yes, there is a command dedicated to it. It is not impossible.)

Hope this helps and wish you luck!

Solution 2:

The new syntax for /execute in 1.13 makes chaining commands like this very easy:

/execute positioned as @e[type=armor_stand,name=Lexer] if block ~ ~ ~ minecraft:wall_banner{Patterns:[{Pattern:"ls",Color:0},{Pattern:"bs",Color:0},{Pattern:"bo",Color:15}]} run <command>

Where <command> can be replaced with any command, without the leading slash that is usually present.