While using "for(Iterator i: Iterable<BlockPos>)", it is the same as "for(Iterator i = Iterable.Iterator();Iterable.hasNext();Iterable.next())".
There is a mistake in "betweenClosed(final int n, final int n2, final int n3, int n4, int n5, int n6)" ---- change values of the same reference.
Each time the code arrives in "computeNext()" in the Iterable, this.curser.set() changes the x,y,z values of the same MutableBlockPos(reference type, extends BlockPos) and then makes "blockpos4" refers to it. When an eligible endstone was found, the blockpos3 refers to blockpos4, which is in fact the reference of the only object of MutableBlockPos.
From now on, each time computeNext() changes the coordinates of the only object of MutableBlockPos, the blockpos3 changes with it, because all BlockPos (including blockpos3), pointing to the same object, or it can be said the same memory area in the heap.
So according to the indexing order, the final result is: If there is an eligible endstone, the method will return the max x,y,z (actually n4, n5 and n6 in method betweenClosed) in the indexing area. This is the southeast and highest block in the area. If there is no eligible endstone, return null.
There is another way to solve this:
Change blockpos3 to 3 double values representing x, y and z. Change "blockpos3 = blockpos 4" to "assign x, y, z with blockpos4" and finally "return new BlockPos(x, y, z)". This way reduces creating more BlockPos objects, just one. And three Integer which hardly affect performance.
While using "for(Iterator i: Iterable<BlockPos>)", it is the same as "for(Iterator i = Iterable.Iterator();Iterable.hasNext();Iterable.next())".
There is a mistake in "betweenClosed(final int n, final int n2, final int n3, int n4, int n5, int n6)" ---- change values of the same reference.
Each time the code arrives in "computeNext()" in the Iterable, this.curser.set() changes the x,y,z values of the same MutableBlockPos(reference type, extends BlockPos) and then makes "blockpos4" refers to it. When an eligible endstone was found, the blockpos3 refers to blockpos4, which is in fact the reference of the only object of MutableBlockPos.
From now on, each time computeNext() changes the coordinates of the only object of MutableBlockPos, the blockpos3 changes with it, because all BlockPos (including blockpos3), pointing to the same object, or it can be said the same memory area in the heap.
So according to the indexing order, the final result is: If there is an eligible endstone, the method will return the max x,y,z (actually n4, n5 and n6 in method betweenClosed) in the indexing area. This is the southeast and highest block in the area. If there is no eligible endstone, return null.
There is another way to solve this:
Change blockpos3 to 3 double values representing x, y and z. Change "blockpos3 = blockpos 4" to "assign x, y, z with blockpos4" and finally "return new BlockPos(x, y, z)". This way reduces creating more BlockPos objects, just one. And three Integer which hardly affect performance.