55 * are made available under the terms of the GNU Lesser Public License v2.1
66 * which accompanies this distribution, and is available at
77 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
8- *
8+ *
99 * Contributors:
1010 * cpw - implementation
1111 */
2222import java .util .concurrent .CountDownLatch ;
2323import java .util .logging .Level ;
2424
25+ import net .minecraft .block .Block ;
26+ import net .minecraft .block .BlockSand ;
2527import net .minecraft .item .Item ;
2628import net .minecraft .nbt .NBTTagCompound ;
2729import net .minecraft .nbt .NBTTagList ;
2830
2931import com .google .common .base .Function ;
3032import com .google .common .base .Throwables ;
3133import com .google .common .collect .ImmutableMap ;
34+ import com .google .common .collect .ImmutableTable ;
35+ import com .google .common .collect .ImmutableTable .Builder ;
3236import com .google .common .collect .MapDifference ;
37+ import com .google .common .collect .Tables ;
3338import com .google .common .collect .MapDifference .ValueDifference ;
3439import com .google .common .collect .Maps ;
3540import com .google .common .collect .Sets ;
41+ import com .google .common .collect .Table ;
42+ import com .google .common .collect .Table .Cell ;
3643
3744import cpw .mods .fml .common .FMLLog ;
3845import cpw .mods .fml .common .Loader ;
@@ -46,6 +53,7 @@ public class GameData {
4653 private static MapDifference <Integer , ItemData > difference ;
4754 private static boolean shouldContinue = true ;
4855 private static boolean isSaveValid = true ;
56+ private static ImmutableTable <String , String , Integer > modObjectTable ;
4957 private static Map <String ,String > ignoredMods ;
5058
5159 private static boolean isModIgnoredForIdValidation (String modId )
@@ -238,4 +246,50 @@ static void setName(Item item, String name, String modId)
238246 ItemData itemData = idMap .get (id );
239247 itemData .setName (name ,modId );
240248 }
249+
250+ public static void buildModObjectTable ()
251+ {
252+ if (modObjectTable != null )
253+ {
254+ throw new IllegalStateException ("Illegal call to buildModObjectTable!" );
255+ }
256+
257+ Map <Integer , Cell <String , String , Integer >> map = Maps .transformValues (idMap , new Function <ItemData ,Cell <String ,String ,Integer >>() {
258+ public Cell <String ,String ,Integer > apply (ItemData data )
259+ {
260+ return Tables .immutableCell (data .getModId (), data .getItemType (), data .getItemId ());
261+ }
262+ });
263+
264+ Builder <String , String , Integer > tBuilder = ImmutableTable .builder ();
265+ for (Cell <String , String , Integer > c : map .values ())
266+ {
267+ tBuilder .put (c );
268+ }
269+ modObjectTable = tBuilder .build ();
270+ }
271+ static Item findItem (String modId , String name )
272+ {
273+ if (modObjectTable == null )
274+ {
275+ return null ;
276+ }
277+
278+ return Item .field_77698_e [modObjectTable .get (modId , name )];
279+ }
280+
281+ static Block findBlock (String modId , String name )
282+ {
283+ if (modObjectTable == null )
284+ {
285+ return null ;
286+ }
287+
288+ Integer blockId = modObjectTable .get (modId , name );
289+ if (blockId >= Block .field_71973_m .length )
290+ {
291+ return null ;
292+ }
293+ return Block .field_71973_m [blockId ];
294+ }
241295}
0 commit comments