When appending list entries in another list, the entries get appended in reverse order
The bug
When using /data modify to append the entries of a list into another list, they get appended in reverse order.
How to reproduce
/setblock ~ ~ ~ minecraft:chest{Items:[{id:"minecraft:stone",Count:1b,tag:{list1:[1,2,3],list2:[1,2,3]}}]}
/data modify block ~ ~ ~ Items[0].tag.list1 append from block ~ ~ ~ Items[0].tag.list2[]
/data get block ~ ~ ~ Items[0].tag
This results in the list [1,2,3,3,2,1] rather than the expected list [1,2,3,1,2,3]
Created Issue:
When appending list entries in another list, the entries get appended in reverse order
The bug
When using /data modify to append the entries of a list into another list, they get appended in reverse order.
How to reproduce
/setblock ~ ~ ~ minecraft:chest{Items:[{id:"minecraft:stone",Count:1b,tag:{list1:[1,2,3],list2:[1,2,3]}}]} /data modify block ~ ~ ~ Items[0].tag.list1 append from block ~ ~ ~ Items[0].tag.list2[] /data get block ~ ~ ~ Items[0].tagThis results in the list [1,2,3,3,2,1] rather than the expected list [1,2,3,1,2,3]
Can I add to this that the iteration-order of the list to copy from may be inconsistent?
If you have this storage-data setup:
data modify storage main Foo set value [I;] data modify storage main Bar set value [I; 1, 2]And do the following:
data modify storage main Foo append from storage main Bar[]Results in "Foo" to now be "[I; 1, 2]" as expected.
data modify storage main Foo prepend from storage main Bar[]Results in the same as above, although expected "Foo" to now be "[I; 2, 1]". The iteration-order of "Bar" seems to be flipped (top to bottom).
So the iteration-order seems to depend on wether you "append" or "prepend". Same happens when inserting to an index. I guess "append/prepend" just borrows behavior from "insert", so "append" is "insert -1" and "prepend" is "insert 0".
Or I guess it's WAI. Maybe all entries get processed first and then later on inserted as a batch which is of a fixed order, so appending/prepending only determines wether you want to insert that batch at the back or front.
As a side effect, "insert after" and "insert before" are merged into "insert". When inserting, index 0 means "before first element", while -1 means "after last element".