PageRenderTime 749ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/modLoader/debug/sources/net/minecraft/src/ModLoader.java

https://code.google.com/p/minecraft-smp-mocreatures/
Java | 1300 lines | 1236 code | 64 blank | 0 comment | 222 complexity | aa8f929072a86da530627fd1c5ad4b89 MD5 | raw file
  1. package net.minecraft.src;
  2. import net.minecraft.src.BaseMod;
  3. import java.awt.image.BufferedImage;
  4. import java.io.BufferedInputStream;
  5. import java.io.File;
  6. import java.io.FileInputStream;
  7. import java.io.FileNotFoundException;
  8. import java.io.FileOutputStream;
  9. import java.io.IOException;
  10. import java.io.InputStream;
  11. import java.io.OutputStream;
  12. import java.io.PrintStream;
  13. import java.lang.reflect.Constructor;
  14. import java.lang.reflect.Field;
  15. import java.lang.reflect.InvocationTargetException;
  16. import java.lang.reflect.Method;
  17. import java.net.URI;
  18. import java.net.URL;
  19. import java.net.URLClassLoader;
  20. import java.security.CodeSource;
  21. import java.security.ProtectionDomain;
  22. import java.util.ArrayList;
  23. import java.util.Arrays;
  24. import java.util.Collection;
  25. import java.util.Collections;
  26. import java.util.HashMap;
  27. import java.util.HashSet;
  28. import java.util.Iterator;
  29. import java.util.LinkedList;
  30. import java.util.List;
  31. import java.util.Map;
  32. import java.util.Properties;
  33. import java.util.Set;
  34. import java.util.logging.FileHandler;
  35. import java.util.logging.Level;
  36. import java.util.logging.Logger;
  37. import java.util.logging.SimpleFormatter;
  38. import java.util.zip.ZipEntry;
  39. import java.util.zip.ZipInputStream;
  40. import javax.imageio.ImageIO;
  41. import net.minecraft.client.Minecraft;
  42. import org.lwjgl.input.Keyboard;
  43. public final class ModLoader
  44. {
  45. private static final List<TextureFX> animList = new LinkedList<TextureFX>();
  46. private static final Map<Integer, BaseMod> blockModels = new HashMap<Integer, BaseMod>();
  47. private static final Map<Integer, Boolean> blockSpecialInv = new HashMap<Integer, Boolean>();
  48. private static final File cfgdir = new File(Minecraft.getMinecraftDir(), "/config/");
  49. private static final File cfgfile = new File(cfgdir, "ModLoader.cfg");
  50. public static Level cfgLoggingLevel = Level.FINER;
  51. private static Map<String, Class<? extends Entity>> classMap = null;
  52. private static long clock = 0L;
  53. public static final boolean DEBUG = false;
  54. private static Field field_animList = null;
  55. private static Field field_armorList = null;
  56. private static Field field_blockList = null;
  57. private static Field field_modifiers = null;
  58. private static Field field_TileEntityRenderers = null;
  59. private static boolean hasInit = false;
  60. private static int highestEntityId = 3000;
  61. private static final Map<BaseMod, Boolean> inGameHooks = new HashMap<BaseMod, Boolean>();
  62. private static final Map<BaseMod, Boolean> inGUIHooks = new HashMap<BaseMod, Boolean>();
  63. private static Minecraft instance = null;
  64. private static int itemSpriteIndex = 0;
  65. private static int itemSpritesLeft = 0;
  66. private static final Map<BaseMod, Map<KeyBinding, boolean[]>> keyList = new HashMap<BaseMod, Map<KeyBinding, boolean[]>>();
  67. private static final File logfile = new File(Minecraft.getMinecraftDir(), "ModLoader.txt");
  68. private static final File modDir = new File(Minecraft.getMinecraftDir(), "/mods/");
  69. private static final Logger logger = Logger.getLogger("ModLoader");
  70. private static FileHandler logHandler = null;
  71. private static Method method_RegisterEntityID = null;
  72. private static Method method_RegisterTileEntity = null;
  73. private static final Map<String, BaseMod> modList = new HashMap<String, BaseMod>();
  74. private static int nextBlockModelID = 1000;
  75. private static final Map<Integer, Map<String, Integer>> overrides = new HashMap<Integer, Map<String, Integer>>();
  76. public static final Properties props = new Properties();
  77. private static BiomeGenBase[] standardBiomes;
  78. private static int terrainSpriteIndex = 0;
  79. private static int terrainSpritesLeft = 0;
  80. private static String texPack = null;
  81. private static boolean texturesAdded = false;
  82. private static final boolean[] usedItemSprites = new boolean[256];
  83. private static final boolean[] usedTerrainSprites = new boolean[256];
  84. public static final String VERSION = "ModLoader Beta 1.6.6";
  85. public ModLoader()
  86. {
  87. }
  88. public static void AddAchievementDesc(Achievement achievement, String name, String description)
  89. {
  90. try
  91. {
  92. if(achievement.statName.contains("."))
  93. {
  94. String key = achievement.statName.split("\\.")[1];
  95. AddLocalization("achievement." + key, name);
  96. AddLocalization((new StringBuilder("achievement.")).append(key).append(".desc").toString(), description);
  97. setPrivateValue(StatBase.class, achievement, 1, StatCollector.translateToLocal("achievement." + key));
  98. setPrivateValue(Achievement.class, achievement, 3, StatCollector.translateToLocal((new StringBuilder("achievement.")).append(key).append(".desc").toString()));
  99. } else
  100. {
  101. setPrivateValue(StatBase.class, achievement, 1, name);
  102. setPrivateValue(Achievement.class, achievement, 3, description);
  103. }
  104. }
  105. catch(IllegalArgumentException e)
  106. {
  107. logger.throwing("ModLoader", "AddAchievementDesc", e);
  108. ThrowException(e);
  109. }
  110. catch(SecurityException e)
  111. {
  112. logger.throwing("ModLoader", "AddAchievementDesc", e);
  113. ThrowException(e);
  114. }
  115. catch(NoSuchFieldException e)
  116. {
  117. logger.throwing("ModLoader", "AddAchievementDesc", e);
  118. ThrowException(e);
  119. }
  120. }
  121. public static int AddAllFuel(int id)
  122. {
  123. logger.finest("Finding fuel for " + id);
  124. int result = 0;
  125. for (BaseMod mod : modList.values())
  126. {
  127. if ((result = mod.AddFuel(id)) == 0)
  128. {
  129. logger.finest("Returned " + result);
  130. break;
  131. }
  132. }
  133. return result;
  134. }
  135. public static void AddAllRenderers(Map<Class<? extends Entity>, Render> o)
  136. {
  137. if(!hasInit)
  138. {
  139. init();
  140. logger.fine("Initialized");
  141. }
  142. for (BaseMod mod : modList.values())
  143. mod.AddRenderer(o);
  144. }
  145. public static void addAnimation(TextureFX anim)
  146. {
  147. logger.finest("Adding animation " + anim.toString());
  148. for (TextureFX oldAnim : animList)
  149. {
  150. if (oldAnim.iconIndex == anim.iconIndex)
  151. {
  152. animList.remove(anim);
  153. break;
  154. }
  155. }
  156. animList.add(anim);
  157. }
  158. public static int AddArmor(String armor)
  159. {
  160. try
  161. {
  162. String[] existingArmor = (String[])field_armorList.get(null);
  163. List<String> existingArmorList = Arrays.asList(existingArmor);
  164. List<String> combinedList = new ArrayList<String>();
  165. combinedList.addAll(existingArmorList);
  166. if (!combinedList.contains(armor))
  167. combinedList.add(armor);
  168. int index = combinedList.indexOf(armor);
  169. field_armorList.set(null, combinedList.toArray(new String[0]));
  170. return index;
  171. } catch (IllegalArgumentException e) {
  172. logger.throwing("ModLoader", "AddArmor", e);
  173. ThrowException("An impossible error has occured!", e);
  174. } catch (IllegalAccessException e) {
  175. logger.throwing("ModLoader", "AddArmor", e);
  176. ThrowException("An impossible error has occured!", e);
  177. }
  178. return -1;
  179. }
  180. public static void AddLocalization(String key, String value)
  181. {
  182. Properties props = null;
  183. try {
  184. props = (Properties)getPrivateValue(StringTranslate.class, StringTranslate.getInstance(), 1);
  185. } catch (SecurityException e) {
  186. logger.throwing("ModLoader", "AddLocalization", e);
  187. ThrowException(e);
  188. } catch (NoSuchFieldException e) {
  189. logger.throwing("ModLoader", "AddLocalization", e);
  190. ThrowException(e);
  191. }
  192. if (props != null)
  193. props.put(key, value);
  194. }
  195. private static void addMod(ClassLoader classLoader, String className, String classFullName)
  196. {
  197. try
  198. {
  199. classFullName = classFullName.substring(0, classFullName.lastIndexOf('.'));
  200. if(!classFullName.contains("$") && (!props.containsKey(className) || (!props.getProperty(className).equalsIgnoreCase("no") && !props.getProperty(className).equalsIgnoreCase("off"))))
  201. {
  202. Class modClass = classLoader.loadClass(classFullName);
  203. if(BaseMod.class.isAssignableFrom(modClass))
  204. {
  205. setupProperties(modClass);
  206. BaseMod mod = (BaseMod)modClass.newInstance();
  207. String modName = mod.toString();
  208. if(mod != null && !modList.containsKey(modName))
  209. {
  210. modList.put(modName, mod);
  211. logger.fine((new StringBuilder("Mod Loaded: \"")).append(modName).append("\" from ").append(className).toString());
  212. System.out.println("Mod Loaded: " + modName);
  213. }
  214. }
  215. }
  216. }
  217. catch(Throwable e)
  218. {
  219. logger.fine((new StringBuilder("Failed to load mod from \"")).append(className).append("\"").toString());
  220. System.out.println((new StringBuilder("Failed to load mod from \"")).append(className).append("\"").toString());
  221. logger.throwing("ModLoader", "addMod", e);
  222. ThrowException(e);
  223. }
  224. }
  225. private static void setupProperties(Class<? extends BaseMod> mod) throws IllegalArgumentException, IllegalAccessException, IOException, SecurityException, NoSuchFieldException
  226. {
  227. Properties modprops = new Properties();
  228. File modcfgfile = new File(cfgdir, mod.getName() + ".cfg");
  229. if ((modcfgfile.exists()) && (modcfgfile.canRead())) {
  230. modprops.load(new FileInputStream(modcfgfile));
  231. }
  232. StringBuilder helptext = new StringBuilder();
  233. for (Field field : mod.getFields()) {
  234. if (((field.getModifiers() & 0x8) != 0) && (field.isAnnotationPresent(MLProp.class))) {
  235. Class type = field.getType();
  236. MLProp annotation = field.getAnnotation(MLProp.class);
  237. String key = annotation.name().length() == 0 ? field.getName() : annotation.name();
  238. Object currentvalue = field.get(null);
  239. StringBuilder range = new StringBuilder();
  240. if (annotation.min() != (-1.0D / 0.0D))
  241. range.append(String.format(",>=%.1f", new Object[] { Double.valueOf(annotation.min()) }));
  242. if (annotation.max() != (1.0D / 0.0D)) {
  243. range.append(String.format(",<=%.1f", new Object[] { Double.valueOf(annotation.max()) }));
  244. }
  245. StringBuilder info = new StringBuilder();
  246. if (annotation.info().length() > 0) {
  247. info.append(" -- ");
  248. info.append(annotation.info());
  249. }
  250. helptext.append(String.format("%s (%s:%s%s)%s\n", new Object[] { key, type.getName(), currentvalue, range, info }));
  251. if (modprops.containsKey(key)) {
  252. String strvalue = modprops.getProperty(key);
  253. Object value = null;
  254. if (type.isAssignableFrom(String.class)) value = strvalue;
  255. else if (type.isAssignableFrom(Integer.TYPE)) value = Integer.valueOf(Integer.parseInt(strvalue));
  256. else if (type.isAssignableFrom(Short.TYPE)) value = Short.valueOf(Short.parseShort(strvalue));
  257. else if (type.isAssignableFrom(Byte.TYPE)) value = Byte.valueOf(Byte.parseByte(strvalue));
  258. else if (type.isAssignableFrom(Boolean.TYPE)) value = Boolean.valueOf(Boolean.parseBoolean(strvalue));
  259. else if (type.isAssignableFrom(Float.TYPE)) value = Float.valueOf(Float.parseFloat(strvalue));
  260. else if (type.isAssignableFrom(Double.TYPE)) {
  261. value = Double.valueOf(Double.parseDouble(strvalue));
  262. }
  263. if (value != null) {
  264. if ((value instanceof Number)) {
  265. double num = ((Number)value).doubleValue();
  266. if ((annotation.min() != (-1.0D / 0.0D)) && (num < annotation.min()))
  267. continue;
  268. if ((annotation.max() != (1.0D / 0.0D)) && (num > annotation.max())) {
  269. continue;
  270. }
  271. }
  272. logger.finer(key + " set to " + value);
  273. if (!value.equals(currentvalue))
  274. field.set(null, value);
  275. }
  276. } else {
  277. logger.finer(key + " not in config, using default: " + currentvalue);
  278. modprops.setProperty(key, currentvalue.toString());
  279. }
  280. }
  281. }
  282. if ((!modprops.isEmpty()) && ((modcfgfile.exists()) || (modcfgfile.createNewFile())) && (modcfgfile.canWrite()))
  283. modprops.store(new FileOutputStream(modcfgfile), helptext.toString());
  284. }
  285. public static void AddName(Object instance, String name)
  286. {
  287. String tag = null;
  288. if ((instance instanceof Item)) {
  289. Item item = (Item)instance;
  290. if (item.getItemName() != null)
  291. tag = item.getItemName() + ".name";
  292. } else if ((instance instanceof Block)) {
  293. Block block = (Block)instance;
  294. if (block.getBlockName() != null)
  295. tag = block.getBlockName() + ".name";
  296. } else if ((instance instanceof ItemStack)) {
  297. ItemStack stack = (ItemStack)instance;
  298. if (stack.getItemName() != null)
  299. tag = stack.getItemName() + ".name";
  300. } else {
  301. Exception e = new Exception(instance.getClass().getName() + " cannot have name attached to it!");
  302. logger.throwing("ModLoader", "AddName", e);
  303. ThrowException(e);
  304. }
  305. if (tag != null) {
  306. AddLocalization(tag, name);
  307. } else {
  308. Exception e = new Exception(instance + " is missing name tag!");
  309. logger.throwing("ModLoader", "AddName", e);
  310. ThrowException(e);
  311. }
  312. }
  313. public static int addOverride(String fileToOverride, String fileToAdd)
  314. {
  315. try
  316. {
  317. int i = getUniqueSpriteIndex(fileToOverride);
  318. addOverride(fileToOverride, fileToAdd, i);
  319. return i;
  320. } catch (Throwable e) {
  321. logger.throwing("ModLoader", "addOverride", e);
  322. ThrowException(e);
  323. throw new RuntimeException(e);
  324. }
  325. }
  326. public static void addOverride(String path, String overlayPath, int index)
  327. {
  328. int dst = -1;
  329. int left = 0;
  330. if (path.equals("/terrain.png")) {
  331. dst = 0;
  332. left = terrainSpritesLeft;
  333. } else if (path.equals("/gui/items.png")) {
  334. dst = 1;
  335. left = itemSpritesLeft; } else {
  336. return;
  337. }System.out.println("Overriding " + path + " with " + overlayPath + " @ " + index + ". " + left + " left.");
  338. logger.finer("addOverride(" + path + "," + overlayPath + "," + index + "). " + left + " left.");
  339. Map<String, Integer> overlays = overrides.get(Integer.valueOf(dst));
  340. if (overlays == null) {
  341. overlays = new HashMap<String, Integer>();
  342. overrides.put(Integer.valueOf(dst), overlays);
  343. }
  344. overlays.put(overlayPath, Integer.valueOf(index));
  345. }
  346. public static void AddRecipe(ItemStack output, Object[] params)
  347. {
  348. CraftingManager.getInstance().addRecipe(output, params);
  349. }
  350. public static void AddShapelessRecipe(ItemStack output, Object[] params)
  351. {
  352. CraftingManager.getInstance().addShapelessRecipe(output, params);
  353. }
  354. public static void AddSmelting(int input, ItemStack output)
  355. {
  356. FurnaceRecipes.smelting().addSmelting(input, output);
  357. }
  358. public static void AddSpawn(Class<? extends EntityLiving> entityClass, int weightedProb, EnumCreatureType spawnList)
  359. {
  360. AddSpawn(entityClass, weightedProb, spawnList, null);
  361. }
  362. public static void AddSpawn(Class<? extends EntityLiving> entityClass, int weightedProb, EnumCreatureType spawnList, BiomeGenBase[] biomes)
  363. {
  364. if(entityClass == null)
  365. {
  366. throw new IllegalArgumentException("entityClass cannot be null");
  367. }
  368. if(spawnList == null)
  369. {
  370. throw new IllegalArgumentException("spawnList cannot be null");
  371. }
  372. if(biomes == null)
  373. {
  374. biomes = standardBiomes;
  375. }
  376. for(int j = 0; j < biomes.length; j++)
  377. {
  378. List<SpawnListEntry> list = biomes[j].getSpawnableList(spawnList);
  379. if (list != null) {
  380. boolean exists = false;
  381. for (SpawnListEntry entry : list) {
  382. if (entry.entityClass == entityClass) {
  383. entry.spawnRarityRate = weightedProb;
  384. exists = true;
  385. break;
  386. }
  387. }
  388. if (!exists)
  389. list.add(new SpawnListEntry(entityClass, weightedProb));
  390. }
  391. }
  392. }
  393. public static void AddSpawn(String entityName, int weightedProb, EnumCreatureType spawnList)
  394. {
  395. AddSpawn(entityName, weightedProb, spawnList, null);
  396. }
  397. public static void AddSpawn(String entityName, int weightedProb, EnumCreatureType spawnList, BiomeGenBase[] biomes)
  398. {
  399. Class class1 = (Class)classMap.get(entityName);
  400. if(class1 != null && (EntityLiving.class).isAssignableFrom(class1))
  401. {
  402. AddSpawn(class1, weightedProb, spawnList, biomes);
  403. }
  404. }
  405. public static boolean DispenseEntity(World world, double x, double y, double z, int xVel, int zVel, ItemStack item)
  406. {
  407. for (BaseMod mod : modList.values())
  408. if (mod.DispenseEntity(world, x, y, z, xVel, zVel, item))
  409. return true;
  410. return false;
  411. }
  412. public static List<BaseMod> getLoadedMods()
  413. {
  414. return Collections.unmodifiableList(new LinkedList<BaseMod>(modList.values()));
  415. }
  416. public static Logger getLogger()
  417. {
  418. return logger;
  419. }
  420. public static Minecraft getMinecraftInstance()
  421. {
  422. if (instance == null) {
  423. try {
  424. ThreadGroup group = Thread.currentThread().getThreadGroup();
  425. int count = group.activeCount();
  426. Thread[] threads = new Thread[count];
  427. group.enumerate(threads);
  428. for (Thread thread : threads)
  429. if (thread.getName().equals("Minecraft main thread")) {
  430. instance = (Minecraft)getPrivateValue(Thread.class, thread, "target");
  431. break;
  432. }
  433. }
  434. catch (SecurityException e) {
  435. logger.throwing("ModLoader", "getMinecraftInstance", e);
  436. throw new RuntimeException(e);
  437. } catch (NoSuchFieldException e) {
  438. logger.throwing("ModLoader", "getMinecraftInstance", e);
  439. throw new RuntimeException(e);
  440. }
  441. }
  442. return instance;
  443. }
  444. public static <T, E> T getPrivateValue(Class<? super E> instanceclass, E instance, int fieldindex)
  445. throws IllegalArgumentException, SecurityException, NoSuchFieldException
  446. {
  447. try
  448. {
  449. Field f = instanceclass.getDeclaredFields()[fieldindex];
  450. f.setAccessible(true);
  451. return (T)f.get(instance);
  452. } catch (IllegalAccessException e) {
  453. logger.throwing("ModLoader", "getPrivateValue", e);
  454. ThrowException("An impossible error has occured!", e);
  455. }
  456. return null;
  457. }
  458. public static <T, E> T getPrivateValue(Class<? super E> instanceclass, E instance, String field)
  459. throws IllegalArgumentException, SecurityException, NoSuchFieldException
  460. {
  461. try
  462. {
  463. Field f = instanceclass.getDeclaredField(field);
  464. f.setAccessible(true);
  465. return (T)f.get(instance);
  466. } catch (IllegalAccessException e) {
  467. logger.throwing("ModLoader", "getPrivateValue", e);
  468. ThrowException("An impossible error has occured!", e);
  469. }
  470. return null;
  471. }
  472. public static int getUniqueBlockModelID(BaseMod basemod, boolean flag)
  473. {
  474. int i = nextBlockModelID++;
  475. blockModels.put(Integer.valueOf(i), basemod);
  476. blockSpecialInv.put(Integer.valueOf(i), Boolean.valueOf(flag));
  477. return i;
  478. }
  479. public static int getUniqueEntityId()
  480. {
  481. return highestEntityId++;
  482. }
  483. private static int getUniqueItemSpriteIndex()
  484. {
  485. for(; itemSpriteIndex < usedItemSprites.length; itemSpriteIndex++)
  486. {
  487. if(!usedItemSprites[itemSpriteIndex])
  488. {
  489. usedItemSprites[itemSpriteIndex] = true;
  490. itemSpritesLeft--;
  491. return itemSpriteIndex++;
  492. }
  493. }
  494. Exception exception = new Exception("No more empty item sprite indices left!");
  495. logger.throwing("ModLoader", "getUniqueItemSpriteIndex", exception);
  496. ThrowException(exception);
  497. return 0;
  498. }
  499. public static int getUniqueSpriteIndex(String s)
  500. {
  501. if(s.equals("/gui/items.png"))
  502. {
  503. return getUniqueItemSpriteIndex();
  504. }
  505. if(s.equals("/terrain.png"))
  506. {
  507. return getUniqueTerrainSpriteIndex();
  508. } else
  509. {
  510. Exception exception = new Exception("No registry for this texture: " + s);
  511. logger.throwing("ModLoader", "getUniqueItemSpriteIndex", exception);
  512. ThrowException(exception);
  513. return 0;
  514. }
  515. }
  516. private static int getUniqueTerrainSpriteIndex()
  517. {
  518. for(; terrainSpriteIndex < usedTerrainSprites.length; terrainSpriteIndex++)
  519. {
  520. if(!usedTerrainSprites[terrainSpriteIndex])
  521. {
  522. usedTerrainSprites[terrainSpriteIndex] = true;
  523. terrainSpritesLeft--;
  524. return terrainSpriteIndex++;
  525. }
  526. }
  527. Exception exception = new Exception("No more empty terrain sprite indices left!");
  528. logger.throwing("ModLoader", "getUniqueItemSpriteIndex", exception);
  529. ThrowException(exception);
  530. return 0;
  531. }
  532. private static void init()
  533. {
  534. hasInit = true;
  535. String usedItemSpritesString = "1111111111111111111111111111111111111101111111011111111111111001111111111111111111111111111010111111100110000011111110000000001111111001100000110000000100000011000000010000001100000000000000110000000000000000000000000000000000000000000000001100000000000000";
  536. String usedTerrainSpritesString = "1111111111111111111111111111110111111111111111111111110111111111111111111111000111111011111111111111001111000000111111111111100011111111000010001111011110000000111111000000000011111100000000001111000000000111111000000000001101000000000001111111111111000011";
  537. for(int i = 0; i < 256; i++)
  538. {
  539. usedItemSprites[i] = usedItemSpritesString.charAt(i) == '1';
  540. if(!usedItemSprites[i])
  541. {
  542. itemSpritesLeft++;
  543. }
  544. usedTerrainSprites[i] = usedTerrainSpritesString.charAt(i) == '1';
  545. if(!usedTerrainSprites[i])
  546. {
  547. terrainSpritesLeft++;
  548. }
  549. }
  550. try
  551. {
  552. instance = (Minecraft)getPrivateValue(Minecraft.class, null, 1);
  553. instance.entityRenderer = new EntityRendererProxy(instance);
  554. classMap = (Map<String, Class<? extends Entity>>)getPrivateValue(EntityList.class, null, 0);
  555. field_modifiers = (Field.class).getDeclaredField("modifiers");
  556. field_modifiers.setAccessible(true);
  557. field_blockList = (Session.class).getDeclaredFields()[0];
  558. field_blockList.setAccessible(true);
  559. field_TileEntityRenderers = (TileEntityRenderer.class).getDeclaredFields()[0];
  560. field_TileEntityRenderers.setAccessible(true);
  561. field_armorList = (RenderPlayer.class).getDeclaredFields()[3];
  562. field_modifiers.setInt(field_armorList, field_armorList.getModifiers() & 0xffffffef);
  563. field_armorList.setAccessible(true);
  564. field_animList = (RenderEngine.class).getDeclaredFields()[5];
  565. field_animList.setAccessible(true);
  566. Field afield[] = (BiomeGenBase.class).getDeclaredFields();
  567. LinkedList<BiomeGenBase> linkedlist = new LinkedList<BiomeGenBase>();
  568. for(int j = 0; j < afield.length; j++)
  569. {
  570. Class class1 = afield[j].getType();
  571. if((afield[j].getModifiers() & 8) != 0 && class1.isAssignableFrom(BiomeGenBase.class))
  572. {
  573. BiomeGenBase biomegenbase = (BiomeGenBase)afield[j].get(null);
  574. if(!(biomegenbase instanceof BiomeGenHell))
  575. {
  576. linkedlist.add(biomegenbase);
  577. }
  578. }
  579. }
  580. standardBiomes = linkedlist.toArray(new BiomeGenBase[0]);
  581. try
  582. {
  583. method_RegisterTileEntity = (TileEntity.class).getDeclaredMethod("a", new Class[] {
  584. java.lang.Class.class, java.lang.String.class
  585. });
  586. }
  587. catch(NoSuchMethodException e)
  588. {
  589. method_RegisterTileEntity = (TileEntity.class).getDeclaredMethod("addMapping", new Class[] {
  590. java.lang.Class.class, java.lang.String.class
  591. });
  592. }
  593. method_RegisterTileEntity.setAccessible(true);
  594. try
  595. {
  596. method_RegisterEntityID = (EntityList.class).getDeclaredMethod("a", new Class[] {
  597. java.lang.Class.class, java.lang.String.class, Integer.TYPE
  598. });
  599. }
  600. catch(NoSuchMethodException e)
  601. {
  602. method_RegisterEntityID = (EntityList.class).getDeclaredMethod("addMapping", new Class[] {
  603. java.lang.Class.class, java.lang.String.class, Integer.TYPE
  604. });
  605. }
  606. method_RegisterEntityID.setAccessible(true);
  607. }
  608. catch(SecurityException e)
  609. {
  610. logger.throwing("ModLoader", "init", e);
  611. ThrowException(e);
  612. throw new RuntimeException(e);
  613. }
  614. catch(NoSuchFieldException e)
  615. {
  616. logger.throwing("ModLoader", "init", e);
  617. ThrowException(e);
  618. throw new RuntimeException(e);
  619. }
  620. catch(NoSuchMethodException e)
  621. {
  622. logger.throwing("ModLoader", "init", e);
  623. ThrowException(e);
  624. throw new RuntimeException(e);
  625. }
  626. catch(IllegalArgumentException e)
  627. {
  628. logger.throwing("ModLoader", "init", e);
  629. ThrowException(e);
  630. throw new RuntimeException(e);
  631. }
  632. catch(IllegalAccessException e)
  633. {
  634. logger.throwing("ModLoader", "init", e);
  635. ThrowException(e);
  636. throw new RuntimeException(e);
  637. }
  638. try
  639. {
  640. loadConfig();
  641. if(props.containsKey("loggingLevel"))
  642. {
  643. cfgLoggingLevel = Level.parse(props.getProperty("loggingLevel"));
  644. }
  645. if(props.containsKey("grassFix"))
  646. {
  647. RenderBlocks.cfgGrassFix = Boolean.parseBoolean(props.getProperty("grassFix"));
  648. }
  649. logger.setLevel(cfgLoggingLevel);
  650. if((logfile.exists() || logfile.createNewFile()) && logfile.canWrite() && logHandler == null)
  651. {
  652. logHandler = new FileHandler(logfile.getPath());
  653. logHandler.setFormatter(new SimpleFormatter());
  654. logger.addHandler(logHandler);
  655. }
  656. logger.fine("ModLoader Beta 1.6.6 Initializing...");
  657. System.out.println("ModLoader Beta 1.6.6 Initializing...");
  658. File source = new File((ModLoader.class).getProtectionDomain().getCodeSource().getLocation().toURI());
  659. modDir.mkdirs();
  660. readFromModFolder(modDir);
  661. readFromClassPath(source);
  662. System.out.println("Done.");
  663. props.setProperty("loggingLevel", cfgLoggingLevel.getName());
  664. props.setProperty("grassFix", Boolean.toString(RenderBlocks.cfgGrassFix));
  665. for (BaseMod mod : modList.values()) {
  666. mod.ModsLoaded();
  667. if (!props.containsKey(mod.getClass().getName())) {
  668. props.setProperty(mod.getClass().getName(), "on");
  669. }
  670. }
  671. initStats();
  672. saveConfig();
  673. }
  674. catch(Throwable throwable)
  675. {
  676. logger.throwing("ModLoader", "init", throwable);
  677. ThrowException("ModLoader has failed to initialize.", throwable);
  678. if(logHandler != null)
  679. {
  680. logHandler.close();
  681. }
  682. throw new RuntimeException(throwable);
  683. }
  684. }
  685. private static void initStats()
  686. {
  687. for(int i = 0; i < Block.blocksList.length; i++)
  688. {
  689. if(!StatList.field_25169_C.containsKey(Integer.valueOf(0x1000000 + i)) && Block.blocksList[i] != null && Block.blocksList[i].getEnableStats())
  690. {
  691. String s = StatCollector.translateToLocalFormatted("stat.mineBlock", new Object[] {
  692. Block.blocksList[i].func_25016_i()
  693. });
  694. StatList.mineBlockStatArray[i] = (new StatCrafting(0x1000000 + i, s, i)).registerStat();
  695. StatList.field_25185_d.add(StatList.mineBlockStatArray[i]);
  696. }
  697. }
  698. for(int j = 0; j < Item.itemsList.length; j++)
  699. {
  700. if(!StatList.field_25169_C.containsKey(Integer.valueOf(0x1020000 + j)) && Item.itemsList[j] != null)
  701. {
  702. String s1 = StatCollector.translateToLocalFormatted("stat.useItem", new Object[] {
  703. Item.itemsList[j].getStatName()
  704. });
  705. StatList.field_25172_A[j] = (new StatCrafting(0x1020000 + j, s1, j)).registerStat();
  706. if(j >= Block.blocksList.length)
  707. {
  708. StatList.field_25186_c.add(StatList.field_25172_A[j]);
  709. }
  710. }
  711. if(!StatList.field_25169_C.containsKey(Integer.valueOf(0x1030000 + j)) && Item.itemsList[j] != null && Item.itemsList[j].isDamagable())
  712. {
  713. String s2 = StatCollector.translateToLocalFormatted("stat.breakItem", new Object[] {
  714. Item.itemsList[j].getStatName()
  715. });
  716. StatList.field_25170_B[j] = (new StatCrafting(0x1030000 + j, s2, j)).registerStat();
  717. }
  718. }
  719. HashSet<Integer> idHashSet = new HashSet<Integer>();
  720. for (Object result : CraftingManager.getInstance().getRecipeList())
  721. idHashSet.add(Integer.valueOf(((IRecipe)result).func_25117_b().itemID));
  722. for (Object result : FurnaceRecipes.smelting().getSmeltingList().values())
  723. idHashSet.add(Integer.valueOf(((ItemStack)result).itemID));
  724. for (int id : idHashSet) {
  725. if(!StatList.field_25169_C.containsKey(Integer.valueOf(0x1010000 + id)) && Item.itemsList[id] != null)
  726. {
  727. String s3 = StatCollector.translateToLocalFormatted("stat.craftItem", new Object[] {
  728. Item.itemsList[id].getStatName()
  729. });
  730. StatList.field_25158_z[id] = (new StatCrafting(0x1010000 + id, s3, id)).registerStat();
  731. }
  732. }
  733. }
  734. public static boolean isGUIOpen(Class<? extends GuiScreen> gui)
  735. {
  736. Minecraft minecraft = getMinecraftInstance();
  737. if(gui == null)
  738. {
  739. return minecraft.currentScreen == null;
  740. }
  741. if(minecraft.currentScreen == null && gui != null)
  742. {
  743. return false;
  744. } else
  745. {
  746. return gui.isInstance(minecraft.currentScreen);
  747. }
  748. }
  749. public static boolean isModLoaded(String modname)
  750. {
  751. Class chk = null;
  752. try {
  753. chk = Class.forName(modname);
  754. } catch (ClassNotFoundException e) {
  755. return false;
  756. }
  757. if (chk != null) {
  758. for (BaseMod mod : modList.values()) {
  759. if (chk.isInstance(mod))
  760. return true;
  761. }
  762. }
  763. return false;
  764. }
  765. public static void loadConfig()
  766. throws IOException
  767. {
  768. cfgdir.mkdir();
  769. if(!cfgfile.exists() && !cfgfile.createNewFile())
  770. {
  771. return;
  772. }
  773. if(cfgfile.canRead())
  774. {
  775. FileInputStream fileinputstream = new FileInputStream(cfgfile);
  776. props.load(fileinputstream);
  777. fileinputstream.close();
  778. }
  779. }
  780. public static BufferedImage loadImage(RenderEngine texCache, String path)
  781. throws Exception
  782. {
  783. TexturePackList texturepacklist = (TexturePackList)getPrivateValue(RenderEngine.class, texCache, 11);
  784. InputStream inputstream = texturepacklist.selectedTexturePack.getResourceAsStream(path);
  785. if(inputstream == null)
  786. {
  787. throw new Exception("Image not found: " + path);
  788. }
  789. BufferedImage bufferedimage = ImageIO.read(inputstream);
  790. if(bufferedimage == null)
  791. {
  792. throw new Exception("Image not found: " + path);
  793. } else
  794. {
  795. return bufferedimage;
  796. }
  797. }
  798. public static void OnTick(Minecraft game)
  799. {
  800. if(!hasInit)
  801. {
  802. init();
  803. logger.fine("Initialized");
  804. }
  805. if(texPack == null || game.gameSettings.skin != texPack)
  806. {
  807. texturesAdded = false;
  808. texPack = game.gameSettings.skin;
  809. }
  810. if(!texturesAdded && game.renderEngine != null)
  811. {
  812. RegisterAllTextureOverrides(game.renderEngine);
  813. texturesAdded = true;
  814. }
  815. long newclock = 0L;
  816. if(game.theWorld != null)
  817. {
  818. newclock = game.theWorld.getWorldTime();
  819. for (Map.Entry<BaseMod, Boolean> modSet : inGameHooks.entrySet())
  820. if ((clock == newclock) && (modSet.getValue().booleanValue()))
  821. modSet.getKey().OnTickInGame(game);
  822. }
  823. if(game.currentScreen != null)
  824. {
  825. for (Map.Entry<BaseMod, Boolean> modSet : inGUIHooks.entrySet())
  826. if(clock != newclock || !(modSet.getValue().booleanValue() & (game.theWorld != null)))
  827. modSet.getKey().OnTickInGUI(game, game.currentScreen);
  828. }
  829. if(clock != newclock)
  830. {
  831. for (Map.Entry<BaseMod, Map<KeyBinding, boolean[]>> modSet : keyList.entrySet()) {
  832. for (Map.Entry<KeyBinding, boolean[]> keySet : modSet.getValue().entrySet()) {
  833. boolean state = Keyboard.isKeyDown(keySet.getKey().keyCode);
  834. boolean[] keyInfo = keySet.getValue();
  835. boolean oldState = keyInfo[1];
  836. keyInfo[1] = state;
  837. if ((!state) || ((oldState) && (!keyInfo[0])))
  838. continue;
  839. modSet.getKey().KeyboardEvent(keySet.getKey());
  840. }
  841. }
  842. }
  843. clock = newclock;
  844. }
  845. public static void OpenGUI(EntityPlayer player, GuiScreen gui)
  846. {
  847. if(!hasInit)
  848. {
  849. init();
  850. logger.fine("Initialized");
  851. }
  852. Minecraft minecraft = getMinecraftInstance();
  853. if(minecraft.thePlayer != player)
  854. {
  855. return;
  856. }
  857. if(gui != null)
  858. {
  859. minecraft.displayGuiScreen(gui);
  860. }
  861. }
  862. public static void PopulateChunk(IChunkProvider generator, int chunkX, int chunkZ, World world)
  863. {
  864. if(!hasInit)
  865. {
  866. init();
  867. logger.fine("Initialized");
  868. }
  869. for (BaseMod mod : modList.values())
  870. {
  871. if (generator.makeString().equals("RandomLevelSource")) mod.GenerateSurface(world, world.rand, chunkX, chunkZ);
  872. else if (generator.makeString().equals("HellRandomLevelSource"))
  873. mod.GenerateNether(world, world.rand, chunkX, chunkZ);
  874. }
  875. }
  876. private static void readFromModFolder(File folder)
  877. throws IOException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException
  878. {
  879. if(!folder.isDirectory())
  880. throw new IllegalArgumentException("folder must be a Directory.");
  881. logger.finer((new StringBuilder("Adding mods from ")).append(folder.getCanonicalPath()).toString());
  882. System.out.println((new StringBuilder("Adding mods from ")).append(folder.getCanonicalPath()).toString());
  883. readFromFileRecursive(folder, folder);
  884. }
  885. private static void readFromClassPath(File file)
  886. throws FileNotFoundException, IOException
  887. {
  888. logger.finer((new StringBuilder("Adding mods from ")).append(file.getCanonicalPath()).toString());
  889. System.out.println((new StringBuilder("Adding mods from ")).append(file.getCanonicalPath()).toString());
  890. readFromFileRecursive(file, file.isDirectory() ? file : file.getParentFile());
  891. }
  892. private static void readFromFileRecursive(File file, File folder)
  893. throws FileNotFoundException, IOException
  894. {
  895. if(file.isDirectory())
  896. for (File subfFile : file.listFiles())
  897. readFromFileRecursive(subfFile, folder);
  898. else if(file.isFile())
  899. {
  900. String fileName = file.getName();
  901. if (fileName.endsWith(".jar") || fileName.endsWith(".zip"))
  902. {
  903. logger.finer("Archive found : " + fileName);
  904. ZipInputStream zipinputstream = new ZipInputStream(new BufferedInputStream(new FileInputStream(file)));
  905. try
  906. {
  907. for (ZipEntry entry = zipinputstream.getNextEntry(); entry != null; entry = zipinputstream.getNextEntry())
  908. {
  909. String entryName = entry.getName();
  910. String className = entryName.substring(entryName.lastIndexOf('/') + 1, entryName.length());
  911. if(!entry.isDirectory() && className.startsWith("mod_") && className.endsWith(".class"))
  912. addMod(new URLClassLoader(new URL[] { folder.toURI().toURL() }), className, entryName.replace('/', '.'));
  913. }
  914. }
  915. finally
  916. {
  917. zipinputstream.close();
  918. }
  919. }
  920. else if(fileName.startsWith("mod_") && fileName.endsWith(".class"))
  921. addMod(new URLClassLoader(new URL[] { folder.toURI().toURL() }), fileName, file.getAbsolutePath().replace(folder.getAbsolutePath() + "\\", "").replace('\\', '.'));
  922. }
  923. }
  924. public static KeyBinding[] RegisterAllKeys(KeyBinding[] akeybinding)
  925. {
  926. List<KeyBinding> existingKeyList = Arrays.asList(akeybinding);
  927. List<KeyBinding> combinedList = new ArrayList<KeyBinding>();
  928. combinedList.addAll(existingKeyList);
  929. for (Map<KeyBinding, boolean[]> keyMap : keyList.values())
  930. combinedList.addAll(keyMap.keySet());
  931. return combinedList.toArray(new KeyBinding[0]);
  932. }
  933. public static void RegisterAllTextureOverrides(RenderEngine texCache)
  934. {
  935. animList.clear();
  936. Minecraft game = getMinecraftInstance();
  937. for (BaseMod mod : modList.values())
  938. mod.RegisterAnimation(game);
  939. for (TextureFX anim : animList)
  940. texCache.registerTextureFX(anim);
  941. for (Map.Entry<Integer, Map<String, Integer>> overlay : overrides.entrySet())
  942. for (Map.Entry<String, Integer> overlayEntry : overlay.getValue().entrySet()) {
  943. String overlayPath = overlayEntry.getKey();
  944. int index = overlayEntry.getValue().intValue();
  945. int dst = overlay.getKey().intValue();
  946. String dstPath = null;
  947. if (dst == 0) dstPath = "/terrain.png";
  948. else if (dst == 1) dstPath = "/gui/items.png"; else
  949. throw new ArrayIndexOutOfBoundsException(dst);
  950. try {
  951. BufferedImage im = loadImage(texCache, overlayPath);
  952. ModTextureStatic anim = new ModTextureStatic(index, dst, im);
  953. texCache.registerTextureFX(anim);
  954. } catch (Exception e) {
  955. logger.throwing("ModLoader", "RegisterAllTextureOverrides", e);
  956. ThrowException(e);
  957. throw new RuntimeException(e);
  958. }
  959. }
  960. }
  961. public static void RegisterBlock(Block block)
  962. {
  963. RegisterBlock(block, null);
  964. }
  965. public static void RegisterBlock(Block block, Class<? extends ItemBlock> class1)
  966. {
  967. try
  968. {
  969. if(block == null)
  970. {
  971. throw new IllegalArgumentException("block parameter cannot be null.");
  972. }
  973. List<Block> list = (List<Block>)field_blockList.get(null);
  974. list.add(block);
  975. int id = block.blockID;
  976. ItemBlock item = null;
  977. if(class1 != null)
  978. item = (ItemBlock)class1.getConstructor(new Class[] { Integer.TYPE }).newInstance(new Object[] { Integer.valueOf(id - 256) });
  979. else
  980. item = new ItemBlock(id - 256);
  981. if(Block.blocksList[id] != null && Item.itemsList[id] == null)
  982. Item.itemsList[id] = item;
  983. }
  984. catch(IllegalArgumentException e)
  985. {
  986. logger.throwing("ModLoader", "RegisterBlock", e);
  987. ThrowException(e);
  988. }
  989. catch(IllegalAccessException e)
  990. {
  991. logger.throwing("ModLoader", "RegisterBlock", e);
  992. ThrowException(e);
  993. }
  994. catch(SecurityException e)
  995. {
  996. logger.throwing("ModLoader", "RegisterBlock", e);
  997. ThrowException(e);
  998. }
  999. catch(InstantiationException e)
  1000. {
  1001. logger.throwing("ModLoader", "RegisterBlock", e);
  1002. ThrowException(e);
  1003. }
  1004. catch(InvocationTargetException e)
  1005. {
  1006. logger.throwing("ModLoader", "RegisterBlock", e);
  1007. ThrowException(e);
  1008. }
  1009. catch(NoSuchMethodException e)
  1010. {
  1011. logger.throwing("ModLoader", "RegisterBlock", e);
  1012. ThrowException(e);
  1013. }
  1014. }
  1015. public static void RegisterEntityID(Class<? extends Entity> entityClass, String entityName, int id)
  1016. {
  1017. try
  1018. {
  1019. method_RegisterEntityID.invoke(null, new Object[] { entityClass, entityName, Integer.valueOf(id) });
  1020. } catch (IllegalArgumentException e) {
  1021. logger.throwing("ModLoader", "RegisterEntityID", e);
  1022. ThrowException(e);
  1023. } catch (IllegalAccessException e) {
  1024. logger.throwing("ModLoader", "RegisterEntityID", e);
  1025. ThrowException(e);
  1026. } catch (InvocationTargetException e) {
  1027. logger.throwing("ModLoader", "RegisterEntityID", e);
  1028. ThrowException(e);
  1029. }
  1030. }
  1031. public static void RegisterKey(BaseMod mod, KeyBinding keyHandler, boolean allowRepeat)
  1032. {
  1033. Map<KeyBinding, boolean[]> keyMap = keyList.get(mod);
  1034. if (keyMap == null)
  1035. keyMap = new HashMap<KeyBinding, boolean[]>();
  1036. keyMap.put(keyHandler, new boolean[] { allowRepeat });
  1037. keyList.put(mod, keyMap);
  1038. }
  1039. public static void RegisterTileEntity(Class<? extends TileEntity> tileEntityClass, String id)
  1040. {
  1041. RegisterTileEntity(tileEntityClass, id, null);
  1042. }
  1043. public static void RegisterTileEntity(Class<? extends TileEntity> tileEntityClass, String id, TileEntitySpecialRenderer renderer)
  1044. {
  1045. try
  1046. {
  1047. method_RegisterTileEntity.invoke(null, new Object[] { tileEntityClass, id });
  1048. if (renderer != null) {
  1049. TileEntityRenderer ref = TileEntityRenderer.instance;
  1050. Map<Class<? extends TileEntity>, TileEntitySpecialRenderer> renderers = (Map<Class<? extends TileEntity>, TileEntitySpecialRenderer>)field_TileEntityRenderers.get(ref);
  1051. renderers.put(tileEntityClass, renderer);
  1052. renderer.setTileEntityRenderer(ref);
  1053. }
  1054. } catch (IllegalArgumentException e) {
  1055. logger.throwing("ModLoader", "RegisterTileEntity", e);
  1056. ThrowException(e);
  1057. } catch (IllegalAccessException e) {
  1058. logger.throwing("ModLoader", "RegisterTileEntity", e);
  1059. ThrowException(e);
  1060. } catch (InvocationTargetException e) {
  1061. logger.throwing("ModLoader", "RegisterTileEntity", e);
  1062. ThrowException(e);
  1063. }
  1064. }
  1065. public static void RemoveSpawn(Class<? extends EntityLiving> entityClass, EnumCreatureType spawnList)
  1066. {
  1067. RemoveSpawn(entityClass, spawnList, null);
  1068. }
  1069. public static void RemoveSpawn(Class<? extends EntityLiving> entityClass, EnumCreatureType spawnList, BiomeGenBase[] biomes)
  1070. {
  1071. if (entityClass == null) {
  1072. throw new IllegalArgumentException("entityClass cannot be null");
  1073. }
  1074. if (spawnList == null) {
  1075. throw new IllegalArgumentException("spawnList cannot be null");
  1076. }
  1077. if (biomes == null) {
  1078. biomes = standardBiomes;
  1079. }
  1080. for (int i = 0; i < biomes.length; i++) {
  1081. List<SpawnListEntry> list = biomes[i].getSpawnableList(spawnList);
  1082. if (list != null)
  1083. for (SpawnListEntry entry : list)
  1084. if (entry.entityClass == entityClass) {
  1085. list.remove(entry);
  1086. break;
  1087. }
  1088. }
  1089. }
  1090. public static void RemoveSpawn(String entityName, EnumCreatureType spawnList)
  1091. {
  1092. RemoveSpawn(entityName, spawnList, null);
  1093. }
  1094. public static void RemoveSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase[] biomes)
  1095. {
  1096. Class entityClass = classMap.get(entityName);
  1097. if ((entityClass != null) && (EntityLiving.class.isAssignableFrom(entityClass)))
  1098. RemoveSpawn(entityClass, spawnList, biomes);
  1099. }
  1100. public static boolean RenderBlockIsItemFull3D(int modelID)
  1101. {
  1102. if(!blockSpecialInv.containsKey(Integer.valueOf(modelID)))
  1103. return modelID == 11;
  1104. return blockSpecialInv.get(Integer.valueOf(modelID)).booleanValue();
  1105. }
  1106. public static void RenderInvBlock(RenderBlocks renderer, Block block, int metadata, int modelID)
  1107. {
  1108. BaseMod mod = blockModels.get(Integer.valueOf(modelID));
  1109. if (mod == null)
  1110. return;
  1111. mod.RenderInvBlock(renderer, block, metadata, modelID);
  1112. }
  1113. public static boolean RenderWorldBlock(RenderBlocks renderer, IBlockAccess world, int x, int y, int z, Block block, int modelID)
  1114. {
  1115. BaseMod mod = blockModels.get(Integer.valueOf(modelID));
  1116. if (mod == null)
  1117. return false;
  1118. return mod.RenderWorldBlock(renderer, world, x, y, z, block, modelID);
  1119. }
  1120. public static void saveConfig()
  1121. throws IOException
  1122. {
  1123. cfgdir.mkdir();
  1124. if(!cfgfile.exists() && !cfgfile.createNewFile())
  1125. {
  1126. return;
  1127. }
  1128. if(cfgfile.canWrite())
  1129. {
  1130. FileOutputStream fileoutputstream = new FileOutputStream(cfgfile);
  1131. props.store(fileoutputstream, "ModLoader Config");
  1132. fileoutputstream.close();
  1133. }
  1134. }
  1135. public static void SetInGameHook(BaseMod mod, boolean enable, boolean useClock)
  1136. {
  1137. if (enable) inGameHooks.put(mod, Boolean.valueOf(useClock)); else
  1138. inGameHooks.remove(mod);
  1139. }
  1140. public static void SetInGUIHook(BaseMod mod, boolean enable, boolean useClock)
  1141. {
  1142. if (enable) inGUIHooks.put(mod, Boolean.valueOf(useClock)); else
  1143. inGUIHooks.remove(mod);
  1144. }
  1145. public static <T, E> void setPrivateValue(Class<? super T> instanceclass, T instance, int fieldindex, E value)
  1146. throws IllegalArgumentException, SecurityException, NoSuchFieldException
  1147. {
  1148. try
  1149. {
  1150. Field f = instanceclass.getDeclaredFields()[fieldindex];
  1151. f.setAccessible(true);
  1152. int modifiers = field_modifiers.getInt(f);
  1153. if ((modifiers & 0x10) != 0)
  1154. field_modifiers.setInt(f, modifiers & 0xFFFFFFEF);
  1155. f.set(instance, value);
  1156. } catch (IllegalAccessException e) {
  1157. logger.throwing("ModLoader", "setPrivateValue", e);
  1158. ThrowException("An impossible error has occured!", e);
  1159. }
  1160. }
  1161. public static <T, E> void setPrivateValue(Class<? super T> instanceclass, T instance, String field, E value)
  1162. throws IllegalArgumentException, SecurityException, NoSuchFieldException
  1163. {
  1164. try
  1165. {
  1166. Field f = instanceclass.getDeclaredField(field);
  1167. int modifiers = field_modifiers.getInt(f);
  1168. if ((modifiers & 0x10) != 0)
  1169. field_modifiers.setInt(f, modifiers & 0xFFFFFFEF);
  1170. f.setAccessible(true);
  1171. f.set(instance, value);
  1172. } catch (IllegalAccessException e) {
  1173. logger.throwing("ModLoader", "setPrivateValue", e);
  1174. ThrowException("An impossible error has occured!", e);
  1175. }
  1176. }
  1177. public static void TakenFromCrafting(EntityPlayer player, ItemStack item)
  1178. {
  1179. for (BaseMod mod : modList.values())
  1180. mod.TakenFromCrafting(player, item);
  1181. }
  1182. public static void TakenFromFurnace(EntityPlayer player, ItemStack item)
  1183. {
  1184. for (BaseMod mod : modList.values())
  1185. mod.TakenFromFurnace(player, item);
  1186. }
  1187. public static void OnItemPickup(EntityPlayer player, ItemStack item)
  1188. {
  1189. for (BaseMod mod : modList.values())
  1190. mod.OnItemPickup(player, item);
  1191. }
  1192. public static void ThrowException(String message, Throwable e)
  1193. {
  1194. Minecraft minecraft = getMinecraftInstance();
  1195. if(minecraft != null)
  1196. {
  1197. minecraft.displayUnexpectedThrowable(new UnexpectedThrowable(message, e));
  1198. } else
  1199. {
  1200. throw new RuntimeException(e);
  1201. }
  1202. }
  1203. private static void ThrowException(Throwable e)
  1204. {
  1205. ThrowException("Exception occured in ModLoader", e);
  1206. }
  1207. }