@@ -58,7 +58,7 @@ public default void set(int col, int row, ClickableItem item) {
5858 throw new IllegalArgumentException ("col must be between 1 and 9" );
5959 if (row < 1 || row > 6 )
6060 throw new IllegalArgumentException ("row must be between 1 and the maximum number of rows" );
61- set ((row - 1 ) * 9 + ( col - 1 ), item );
61+ set (locToPos (row , col ), item );
6262 }
6363
6464 /**
@@ -104,7 +104,7 @@ public default void rectangle(int row, int col, int width, int height, Clickable
104104 throw new IllegalArgumentException ("The width must be between 1 and " + (10 - col ));
105105 if (height < 1 || height > 7 - col )
106106 throw new IllegalArgumentException ("The height must be between 1 and " + (7 - col ));
107- rectangle ((row - 1 ) * 9 + ( col - 1 ), width , height , item );
107+ rectangle (locToPos (row , col ), width , height , item );
108108 }
109109
110110 /**
@@ -114,9 +114,10 @@ public default void rectangle(int row, int col, int width, int height, Clickable
114114 * The position of the item. Must be between 0 and the maximum number
115115 * of case (9 * number of rows - 1)
116116 * @param width
117- * The width. Must be between 1 and 9
117+ * The width. Must be between 1 and 9 and stay inside the inventory
118118 * @param height
119- * The height. Must be between 1 and the maximum number of rows
119+ * The height. Must be between 1 and the maximum number of rows and
120+ * stay inside the inventory
120121 * @param item
121122 * The item
122123 */
@@ -141,4 +142,28 @@ public default void rectangle(int row, int col, int width, int height, Clickable
141142 * exist, null is returned
142143 */
143144 public Object get (String key );
145+
146+ /**
147+ * Transform a single position to two location
148+ *
149+ * @param pos
150+ * The position
151+ * @return an array of two integer: The row and the column
152+ */
153+ public default int [] posToLoc (int pos ) {
154+ return new int [] { (pos / 9 ) + 1 , (pos % 9 ) + 1 };
155+ }
156+
157+ /**
158+ * Transform two location to a single position
159+ *
160+ * @param row
161+ * The row
162+ * @param col
163+ * The col
164+ * @return The position
165+ */
166+ public default int locToPos (int row , int col ) {
167+ return (row - 1 ) * 9 + (col - 1 );
168+ }
144169}
0 commit comments