๐๏ธ tryashtar ยท 3 points ยท Posted at 23:03:17 on June 16, 2016 ยท (Permalink)*
Alright, friends, I've got a problem here that may be a little bit difficult to explain, but I'll try my best.
We have an armor stand in a block. Naturally, there are also blocks directly north, south, east, and west of it. Each block in each direction is either a command block or another block (air, stone, nether brick--it's irrelevant).
Our armor stand needs to secure two pieces of information:
The location of the "output block"
The orientation of the "output block"
So the question is, what is an output block? An output block is a command block that is bordering the armor stand but NOT pointing into it. We need exactly one of these--if there are multiple, the armor stand should die.
A command block can be any type:
Impulse
Chain
Repeating
It can also be conditional or unconditional. Therefore there are SIX distinct block types for each direction--north, south, east, west.
Given this scenario, we need to store the location and orientation of the output block inside two scores in the armor stand.
It doesn't matter what values are used--you could have north represented as 52, south as -352, or whatever--we just need to obtain this information.
Of course, I could just do an ugly all-combinations brute-force, but let me tell you, it expands quite a bit and gets scary. I need an elegant way--or at least a somewhat efficient one.
Thanks!
EDIT: Simplified the problem due to new information.
IceMetalPunk ยท 1 points ยท Posted at 00:13:30 on June 17, 2016 ยท (Permalink)
My first thought was the brute-force method, but yeah, it's not pretty. No matter what, you'll always need at least 12 commands for this, since there's no way to get the data value or block ID into any kind of variable (as far as I know), so those all have to be tested for manually. But rather than testing these 12 blocks in each of the 4 directions manually, I'd suggest summoning 4 armor stands, one on each side of the main armor stand, and then just executing on all of those at once to test for the blocks. That should reduce your command block number by about a factor of 4. It'd still require 16 blocks (4 to summon, and then 12 to check blocks under each, so 4+12=16), but that's much better than 4*12 = 48 commands.
๐๏ธ tryashtar ยท 1 points ยท Posted at 03:33:01 on June 17, 2016 ยท (Permalink)
Seems like a good idea. Here's a rough draft of what that would look like.
/execute @e[type=ArmorStand,name=Center] ~ ~ ~ summon ArmorStand ~1 ~ ~ {CustomName:PlusX,Tags:["blockchecker"]}/execute @e[type=ArmorStand,name=Center] ~ ~ ~ summon ArmorStand ~-1 ~ ~ {CustomName:MinusX,Tags:["blockchecker"]}/execute @e[type=ArmorStand,name=Center] ~ ~ ~ summon ArmorStand ~ ~ ~1 {CustomName:PlusZ,Tags:["blockchecker"]}/execute @e[type=ArmorStand,name=Center] ~ ~ ~ summon ArmorStand ~ ~ ~-1 {CustomName:MinusZ,Tags:["blockchecker"]}/execute @e[type=ArmorStand,tag=blockchecker] ~ ~ ~ detect ~ ~ ~ command_block 0 scoreboard players set @e[type=ArmorStand,c=1] blockcheck 1/execute @e[type=ArmorStand,tag=blockchecker] ~ ~ ~ detect ~ ~ ~ command_block 8 scoreboard players set @e[type=ArmorStand,c=1] blockcheck 1/execute @e[type=ArmorStand,tag=blockchecker] ~ ~ ~ detect ~ ~ ~ chain_command_block 0 scoreboard players set @e[type=ArmorStand,c=1] blockcheck 1/execute @e[type=ArmorStand,tag=blockchecker] ~ ~ ~ detect ~ ~ ~ chain_command_block 8 scoreboard players set @e[type=ArmorStand,c=1] blockcheck 1/execute @e[type=ArmorStand,tag=blockchecker] ~ ~ ~ detect ~ ~ ~ repeating_command_block 0 scoreboard players set @e[type=ArmorStand,c=1] blockcheck 1/execute @e[type=ArmorStand,tag=blockchecker] ~ ~ ~ detect ~ ~ ~ repeating_command_block 8 scoreboard players set @e[type=ArmorStand,c=1] blockcheck 1(Repeat that above one three more times, one for each direction)
(From here, we'll assume 1=+X, 2=-X, 3=+Z, 4=-Z)
/execute @e[type=ArmorStand,name=PlusX,score_blockcheck_min=2,score_blockcheck=2] ~ ~ ~ scoreboard players set @e[type=ArmorStand,name=Center,r=2,c=1] inputdir 2/execute @e[type=ArmorStand,name=MinusX,score_blockcheck_min=1,score_blockcheck=1] ~ ~ ~ scoreboard players set @e[type=ArmorStand,name=Center,r=2,c=1] inputdir 1/execute @e[type=ArmorStand,name=PlusZ,score_blockcheck_min=4,score_blockcheck=4] ~ ~ ~ scoreboard players set @e[type=ArmorStand,name=Center,r=2,c=1] inputdir 4/execute @e[type=ArmorStand,name=MinusZ,score_blockcheck_min=3,score_blockcheck=3] ~ ~ ~ scoreboard players set @e[type=ArmorStand,name=Center,r=2,c=1] inputdir 3Issue here is that we don't know if there are multiple input blocks found, because if there are we need to kill the armor stand.
A possible solution is to use 11, 12, 13, and 14 instead of 1, 2, 3, 4 and use
/scoreboard players addinstead ofset. That way, ifinputdirexceeds 20, we know there were multiple.Anyway, from here we've already used 26 commands, and that's just to find the input orientation. Finding the output orientation and position would take several more, and I don't really feel like using the brainpower to write all those right now.
Am I missing a way to condense all this down? It seems terribly inefficient, even with this modification.
Plagiatus ยท 1 points ยท Posted at 06:01:15 on June 17, 2016 ยท (Permalink)
Well, you could always just add 1, that way you won't know where the block is, but if you have a score of 2+, you know it's too much?
But yeah, pretty big and surprisingly complicated thing you're trying to achieve there.
Just so I am sure I get this right: you need to know where your CommandBlocks are pointing? Or is it just important whether it is pointing at the center or not (I assume it's the first, because you want to redirect something in that direction?)?
๐๏ธ tryashtar ยท 1 points ยท Posted at 06:22:21 on June 17, 2016 ยท (Permalink)
Basically, the end goal is to, essentially, connect two severed command block chains.
> โข ^As an example, say the dot is our armor stand. We see the input block is to the left, facing right (the input block will always face the opposite direction it is relative to our armor stand) and the output block is to the right, facing up.
If I wanted to connect these two chains, I would need to place a RIGHT-facing command block at the armor stand.
Of course, you would think, "oh, in that case, just find the output and point to it," but it isn't that simple, because in the final product, I'm using structure blocks to copy the output block and paste it at the armor stand, pointing to its old self with rotation.
Therefore, we need to know the output's position and orientation.
Hmm... after explaining this, I'm realizing the input block is actually irrelevant. May have to do some edits.
Plagiatus ยท 1 points ยท Posted at 10:12:26 on June 17, 2016 ยท (Permalink)
It's always good to explain something to someone not involved. You more often than not realise a better/other way to do it. ๐
IceMetalPunk ยท 1 points ยท Posted at 18:17:11 on June 17, 2016 ยท (Permalink)
I'm confused about something in your code. You're only ever setting blockcheck to 1, but you're later looking for armor stands with blockcheck = 1, 2, 3, and 4. Three of those conditions will never occur, making those three checks useless. I think instead you could start the armor stands with scores of 0, 6, 12, and 18, then add the data value of the block you're checking (minus 8 for the conditionals) to the score. Once that's done, all you have to do to determine inputs/outputs is check for the 8 possible results, since each direction-tag-and-score combination will be enough to tell whether a stand is an input, an output, or neither; so tag those appropriately as input or output. Lastly, just have the central armor stand keep a score of InputNumber and OutputNumber, which you can count by /executing on the previously tagged check stands to increment it by 1.
๐๏ธ tryashtar ยท 1 points ยท Posted at 18:25:30 on June 17, 2016 ยท (Permalink)
In that stuff that I typed out as an example, I only ever set blockcheck to 1 because I didn't want to copy-paste that large block and make the comment even longer--in the real thing, they would be there.
As for your idea, it does seem pretty good except for the conversion from data values -> scores would be a very long laundry list that may or may not be necessary.