How to rotate an item frame with a command?
Solution 1:
The wiki was actually wrong about /replaceitem
not working for item frames, it's even mentioned in the history, but wasn't changed in the main article so far. I changed that now.
But that still doesn't help you, because you can't rotate the item with that, because the rotation is not a property of the item, but of the frame. It's documented here: https://minecraft.gamepedia.com/Item_Frame#Entity_data (archive)
To reset the rotation of an item, you can just use this command:
/data merge entity @e[type=item_frame,sort=nearest,limit=1] {ItemRotation:0}
To set it to 45°: {ItemRotation:1}
This goes up to 7
, which is 45° rotated to the left from the default.
To rotate an item frame item relative to the current rotation, you first need to store the rotation in a scoreboard, then change that scoreboard and then put the value back into the item frame rotation NBT:
/scoreboard objectives add rotation dummy
/execute as @e[type=item_frame] store result score @s rotation run data get entity @s ItemRotation
/scoreboard players add @e[type=item_frame] rotation 1
/execute as @e[type=item_frame] store result entity @s ItemRotation byte run scoreboard players get @s rotation
This rotates the item in every item frame by 45°. I'm pretty sure it wraps around from 8 to 0, but I didn't test it.