2

Can you make variables in Minecraft Java? I want to make an armor stand tp to where I am looking, but I want to make the local Z coordinate editable with scoreboard. My command would be:

/execute at [username] run tp [armorstand UUID] ^ ^ ^#

"#" is a scoreboard objective.

Is that possible?

1 Answer 1

3

Scoreboard objectives in Minecraft are for all entities, meaning that all entities have all the objectives you have created. In other words you cannot create objectives for specific mobs

Back to the question, your method seems to be over-complicated. There is a method called raycasting, and it is basically a recursive function which repeatedly execute itself through the Minecraft world. It is especially useful for making laser weapons but this case, you can utilize it to detect which block the player is facing.

Here is a template of the raycast inside a function called raycast.mcfunction

execute unless block ~ ~ ~ air run tp @e[type=armor_stand] ~ ~ ~
execute if block ~ ~ ~ air positioned ^ ^ ^1 run function namespace:raycast

In your tick function

execute as @a at @s run function namespace:raycast

I have tested it out myself and it works.

Unfortunately you might have to do it with datapacks since you cannot make functions in game.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.