Help with raycasting commands - Minecraft 1.13
I'm making a little chess game in Minecraft with commands and need a cursor for the player to select one of their own pieces by looking at it. I thought I had figured a way to do it with area_effect_clouds that will be teleported a small distance (0.08 blocks) each tick from anyone who has the tag "PlayingChess" (with I have ensured with other commands that they always have as they are playing chess). The problem is that the area effect clouds don't seem to be teleporting at all and here are the commands (in the same order as they are placed in a chain):
/execute at @a[tag=PlayingChess,scores={ChessSneak=1..}] positioned ~ ~1.2 ~ run summon minecraft:area_effect_cloud ^ ^ ^0.08 {Duration:12,Tags:["Undirected"],CustomName:"{\"text\":\"ChessTargeting\"}"}
/execute as @e[type=minecraft:area_effect_cloud,name=ChessTargeting] at @s run teleport @s ~ ~ ~ facing entity @a[tag=PlayingChess,sort=nearest,limit=1] eyes
/tag @e remove Undirected
/execute as @e[type=minecraft:area_effect_cloud,name=ChessTargeting] at @s run teleport @s ^ ^ ^-0.08
/execute at @e[type=minecraft:area_effect_cloud,name=ChessTargeting] if block ~ ~ ~ minecraft:quartz_pillar at @e[name=WhitePiece,distance=..0.1,sort=nearest,limit=1] run summon minecraft:area_effect_cloud ~ ~ ~ {Duration:20,CustomName:"{\"text\":\"ChessSelect\"}"}
/execute as @e[type=minecraft:area_effect_cloud,name=ChessTargeting] at @s if block ~ ~ ~ minecraft:quartz_pillar run kill @s
When the cursor area effect cloud hits a quarts pillar block (the chess table) it should spawn a new area effect cloud at the nearest white chess piece (area effect cloud with name "WhitePiece") and then die.
I have this to display to the player which piece is selected:
/execute at @e[type=minecraft:area_effect_cloud,name=ChessSelect] run summon minecraft:falling_block ~ ~0.02 ~ {BlockState:{Name:"minecraft:lime_stained_glass_pane"},NoGravity:1b,Time:0,DropItem:0b}
I have done a lot of testing and it seems the problem is with teleporting the area effect cloud forward using:
/execute as @e[type=minecraft:area_effect_cloud,name=ChessTargeting] at @s run teleport @s ^ ^ ^-0.08
or making it face the player from the beginning with:
/execute as @e[type=minecraft:area_effect_cloud,name=ChessTargeting] at @s run teleport @s ~ ~ ~ facing entity @a[tag=PlayingChess,sort=nearest,limit=1] eyes
Thankful for all replies!! :)
Is it possible to use a datapack? It's very simple to set up, and you won't need to use area_effect_clouds at all, which will reduce lag greatly, and should be quicker to respond than the clouds.
Assuming you can use a datapack, you will need to create a recursive function (meaning it calls itself) which every iteration runs itself .02 blocks ahead of where it was the last iteration. First, run the function initially like this:
execute as @a[tag=PlayingChess,scores={ChessSneak=1..}] at @s anchored eyes run function namespace:raycasting_function
The function should look something like this, where namespace:raycasting_function
refers to the function itself:
#execute if block ~ ~ ~ #namespace:raycastable positioned ^ ^ ^0.02 run function namespace:raycasting_function
execute if block ~ ~ ~ minecraft:quartz_pillar run function namespace:found_piece
The #namespace:raycastable
in the commented out line (starts with a #
) would be a tag that you would implement. Alternatively, that line could be replaced by these three
execute if block ~ ~ ~ minecraft:air positioned ^ ^ ^0.02 run function namespace:raycasting_function
execute if block ~ ~ ~ minecraft:cave_air positioned ^ ^ ^0.02 run function namespace:raycasting_function
execute if block ~ ~ ~ minecraft:void_air positioned ^ ^ ^0.02 run function namespace:raycasting_function
if you don't use the tag. To make the tag, go to your namespace folder and make a folder called 'tags'. Inside that, make a folder called 'blocks'. Inside that, make a JSON file (it ends with .json) called 'raycastable', with the text:
{
"replace": false,
"values": [
"minecraft:air",
"minecraft:cave_air",
"minecraft:void_air"
]
}
inside.
The function namespace:found_piece
would contain all of the commands you needed to run at the quartz block. From your question, I think this would be:
execute at @e[name=WhitePiece,distance=..0.1,sort=nearest,limit=1] run summon minecraft:area_effect_cloud ~ ~ ~ {Duration:20,CustomName:"{\"text\":\"ChessSelect\"}"}
The command for summoning the falling block can just go in a tick function or a repeat command block.