Hi, what I need help with is when a player looks at a block (gold block) the command would execute then open a door. So then the door would open and then close when the player goes through it. The door is 3x3 but I can animate the door to close and open I just need help with the command executing if a player is looking at the gold block.
I will give you an answer using function, because it's more complex with command block. If you don't know how to use function, I recommand you to check that, cause all is more simple.
So there is not an easy method with just one command to do it... Nop we'll need more than 2 command!
And by more than 2, I mean 3.
You create a function called randomly, like look_at_gold.mcfunction
And within you write
execute if block ~ ~ ~ air if entity @s[distance=..5] positioned ^ ^ ^1 run function datapack:look_at_gold
execute if block ~ ~ ~ gold_block run [what you need to open your door]
What this does? It check at the position we give to it if there's a block, if not he move forward in the direction the player look and check again, until the distance with the player equal 5 (change this value if you want more or less) or until he found a block. And if one of this condition is true, he check if there's a gold_block where it stand and if yes, he run a command.
So the last thing we have to do is to tell it where it start to check (on the player). We just have to go on a function that run every tick (I leat search you how to do it) and within we write one little command :
execute as @a at @s anchored eyes run function datapack:look_at_gold
This command tell the function to run as all the player, on their eyes position.
And it's done, you have your function who check whether a player look at a gold block. But beware, if you want the player to look at a special gold block and not whatever gold block that stood in your world, you will have to create a area effect cloud with a tag, and tell the function to run if the player is near it!
Hi, what I need help with is when a player looks at a block (gold block) the command would execute then open a door. So then the door would open and then close when the player goes through it. The door is 3x3 but I can animate the door to close and open I just need help with the command executing if a player is looking at the gold block.
Thanks!
Hello!
I will give you an answer using function, because it's more complex with command block. If you don't know how to use function, I recommand you to check that, cause all is more simple.
So there is not an easy method with just one command to do it... Nop we'll need more than 2 command!
And by more than 2, I mean 3.
You create a function called randomly, like look_at_gold.mcfunction
And within you write
What this does? It check at the position we give to it if there's a block, if not he move forward in the direction the player look and check again, until the distance with the player equal 5 (change this value if you want more or less) or until he found a block. And if one of this condition is true, he check if there's a gold_block where it stand and if yes, he run a command.
So the last thing we have to do is to tell it where it start to check (on the player). We just have to go on a function that run every tick (I leat search you how to do it) and within we write one little command :
This command tell the function to run as all the player, on their eyes position.
And it's done, you have your function who check whether a player look at a gold block. But beware, if you want the player to look at a special gold block and not whatever gold block that stood in your world, you will have to create a area effect cloud with a tag, and tell the function to run if the player is near it!
I like trains... OF CHAIN COMMAND BLOCKS !
Thank you so much!