Background:
The center of the block a golem is standing is what is used in the function BlockPos.distToCenterSqr
in the TransportItemsBetweenContainers.getTargetBlockPosition to compare against (blockPos.getX(), blockPos.getY(), blockPos.getZ()), however (blockPos.getX(), blockPos.getY() and blockPos.getZ()) is not the center of the block but rather the edge. This leads to unexpected, directional behaviour of copper golems. The correct snippet would be:
.min(Comparator.comparing(transportItemTarget -> transportItemTarget.pos.distToCenterSqr(blockPos.getX() + 0.5, blockPos.getY() + 0.5, blockPos.getZ() + 0.5)));
Reproduce:
spawn a golem into the structure block file that I shared here. Then, rotate the structure by 180 degree and repeat.
What happens:
The golem doesn’t pick the chest right below it, but rather the one after.
Expected result:
the golem picks the closest chest
I forget to mention what happens after the rotation: everything works as expected, namely the copper golem chooses to open the closest chest.