package net.mcft.copy.core.inventory.slot;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;

import net.mcft.copy.core.misc.Enumerator;
import net.mcft.copy.core.misc.IEnumerable;
import net.minecraft.inventory.IInventory;

public class SlotGroup implements IEnumerable<SlotBase> {
	
	public List<SlotBase> slots = new ArrayList<SlotBase>();
	
	public SlotGroup() {  }
	public SlotGroup(Class<? extends SlotBase> slotClass,
	                 IInventory inventory, int startIndex,
	                 int x, int y, int columns, int rows) {
		try {
			Constructor<? extends SlotBase> constructor =
					slotClass.getConstructor(IInventory.class, int.class, int.class, int.class);
			for (int i = 0; i < columns; i++)
				for (int j = 0; j < rows; j++) {
					int index = startIndex + i + j * columns;
					int xx = x + i * 16;
					int yy = y + j * 16;
					add(constructor.newInstance(inventory, index, xx, yy));
				}
		} catch (Exception e) { e.printStackTrace(); }
	}
	
	/** Adds a slot to this slot group. */
	public void add(SlotBase slot) {
		slots.add(slot);
	}
	
	// IEnumerable implementation
	
	@Override
	public Enumerator<SlotBase> iterator() { return Enumerator.of(slots); }
	
}

@@ -726,29 +726,26 @@
 int 
-i
+j
  = 0; 
-i %3C columns; i
+j %3C rows; j
 ++)%0A
@@ -757,34 +757,37 @@
 or (int 
-j
+i
  = 0; 
-j %3C rows; j
+i %3C columns; i
 ++) %7B%0A%09%09
@@ -850,25 +850,25 @@
  = x + i * 1
-6
+8
 ;%0A%09%09%09%09%09int y
@@ -884,9 +884,9 @@
  * 1
-6
+8
 ;%0A%09%09

Fix SlotGroup adding in wrong order and positions