Is there any way to numerically retrieve and store the block ID of a block in the scoreboard using command blocks?

The goal here is to implement memory by using block.

I want to give command blocks index-able memory. I figured using blocks would be the most logical thing to do since they're... everywhere. I see they each have block ID's as shown here:

https://minecraft.fandom.com/wiki/Data_values/Block_IDs

I know the scoreboard can do some kinds of arithmetic operations. Possibly enough to serve as a naive "processor" to go hand in hand with the "memory". Naturally then I need to somehow get the block id of some block at an arbitrary position into the scoreboard. I know that theoretically one could just use this function (https://minecraft.fandom.com/wiki/Commands/testforblock) and just use that. However, the only problem with that is that checking 256 blocks is bridging from being inefficient to downright absurd. There has to be a better way. Is there a command to look up a block ID at some position and then move it to the scoreboard?


Solution 1:

There is no better way.

Commands are very limited when it comes to dynamically reading and writing data to and from scoreboard - or anything else for that matter.

Without knowing your specific requirements, all I can say is that you're going to have to hardcode each individual block. If you can add some details to the OP we might be able to come up with a work-around that isn't so absurd.


Allow me to elaborate in an attempt to assert my credibility on the subject.

The scoreboard command is relatively large but its functionality is still quite limited. It can write only to the scores of entities and so-called "fake players" (static names on the scoreboard). It can read values from the same places, naturally, however it is also possible to read in values from various other sources using the stats command. Even so, there is no such stat or query that can extract the id of a block and place it into a score.

I should also note that selectors and scores can be used in several other places (such as with the tellraw command, signs, books, and text components in general), though not in any way that will allow for dynamic manipulation of data.

Solution 2:

Sadly you will have to test for every single possible block.

Blocks have IDs, but they are only used for the save files. In the game, they are only referred to with their ID name ("minecraft:stone", "minecraft:dirt", "minecraft:beacon" and so on).

Also, as Arcensoth said, there is no way to get data into and out of scoreboards dynamically (except /stats, but that's also limited). But that doesn't mean that your relative coordinates based on scoreboards are impossible, it just means that you will have to e.g. move an armor stand one block per scoreboard count etc.

For this project, I recommend you to use functions instead of command blocks. You can edit them in a text editor, you can easily copy commands (whenever you need 256 of a kind) and you can use recursion for the armor stand teleportation so that it can happen in one tick.