Advertisement
Guest User

ItemDumper

a guest
Aug 30th, 2013
1,572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 KB | None | 0 0
  1. // ------------------------------------ itemdumper.java
  2. // ---------------------------------------------------------------------------------------------------
  3.  
  4. package oxinabox.itemdumper;
  5.  
  6. import cpw.mods.fml.common.Mod;
  7. import cpw.mods.fml.common.Mod.PreInit; // used in 1.5.2
  8. import cpw.mods.fml.common.Mod.Init; // used in 1.5.2
  9. import cpw.mods.fml.common.Mod.PostInit; // used in 1.5.2
  10. import cpw.mods.fml.common.Mod.Instance;
  11. import cpw.mods.fml.common.SidedProxy;
  12. import cpw.mods.fml.common.event.FMLInitializationEvent;
  13. import cpw.mods.fml.common.event.FMLPostInitializationEvent;
  14. import cpw.mods.fml.common.event.FMLPreInitializationEvent;
  15. import cpw.mods.fml.common.network.NetworkMod;
  16. import cpw.mods.fml.common.registry.GameRegistry;
  17.  
  18.  
  19.  
  20.  
  21. @Mod(modid="ItemDumper", name="ItemDumper", version="0.0.0")
  22. @NetworkMod(clientSideRequired=true, serverSideRequired=false)
  23. public class ItemDumper {
  24.  
  25. // The instance of your mod that Forge uses.
  26. @Instance("ItemDumper")
  27. public static ItemDumper instance;
  28.  
  29. // Says where the client and server 'proxy' code is loaded.
  30. @SidedProxy(clientSide="oxinabox.itemdumper.client.ClientProxy", serverSide="oxinabox.itemdumper.CommonProxy")
  31. public static CommonProxy proxy;
  32.  
  33.  
  34. @PreInit // used in 1.5.2
  35. public void preInit(FMLPreInitializationEvent event) {
  36. // Stub Method
  37. }
  38.  
  39.  
  40. @Init // used in 1.5.2
  41. public void load(FMLInitializationEvent event) {
  42. proxy.registerRenderers();
  43. GameRegistry.registerPlayerTracker(new PlayerTracker());
  44.  
  45.  
  46.  
  47.  
  48.  
  49. }
  50.  
  51.  
  52. @PostInit // used in 1.5.2
  53. public void postInit(FMLPostInitializationEvent event) {
  54. // Stub Method
  55. }
  56. }
  57.  
  58. // --------------------------------------------------------------------------------------------------
  59. // ------------ PlayerTracker.java
  60. // Used to know that the player has logged in to the world, and then to run the mod
  61.  
  62. package oxinabox.itemdumper;
  63.  
  64.  
  65. import net.minecraft.creativetab.CreativeTabs;
  66. import net.minecraft.enchantment.Enchantment;
  67. import net.minecraft.entity.player.EntityPlayer;
  68. import net.minecraft.item.Item;
  69. import net.minecraft.item.ItemStack;
  70. import cpw.mods.fml.common.IPlayerTracker;
  71.  
  72. import java.io.FileNotFoundException;
  73. import java.io.PrintWriter;
  74. import java.io.UnsupportedEncodingException;
  75. import java.util.ArrayList;
  76. import java.util.Iterator;
  77. import java.util.List;
  78.  
  79.  
  80. public class PlayerTracker implements IPlayerTracker {
  81.  
  82. private List<String> getAllItemInfo (EntityPlayer player)
  83. {
  84. ArrayList<ItemStack> itemsDiscovered = new ArrayList<ItemStack>();
  85. Item[] aitem = Item.itemsList;
  86. int i = aitem.length;
  87. int j;
  88.  
  89. for (j = 0; j < i; ++j)
  90. {
  91. Item item = aitem[j];
  92.  
  93. if (item != null && item.getCreativeTab() != null)
  94. {
  95. item.getSubItems(item.itemID, (CreativeTabs)null, itemsDiscovered); //Add the subitems
  96. }
  97. }
  98.  
  99.  
  100. List<String> info = new ArrayList<String>();
  101.  
  102. for (ItemStack itemstack : itemsDiscovered)
  103. {
  104. Iterator toolTipIter = itemstack.getTooltip(player, true).iterator();
  105.  
  106. String desc = "";
  107.  
  108. while (toolTipIter.hasNext())
  109. {
  110. desc += " " + (String)toolTipIter.next();
  111. }
  112.  
  113. info.add(itemstack.itemID + ":" + String.valueOf(itemstack.getItemDamage()) + " = " + itemstack.getDisplayName() + " = " + desc );
  114.  
  115. }
  116. return info;
  117.  
  118.  
  119. }
  120.  
  121. @Override
  122. public void onPlayerLogin(EntityPlayer player) {
  123.  
  124. List<String> info = getAllItemInfo(player);
  125.  
  126. try {
  127. PrintWriter writer = new PrintWriter("ItemDump.txt", "UTF-8");
  128. for (String line : info )
  129. {
  130. writer.write(line + "\n");
  131. }
  132.  
  133. writer.close();
  134. } catch (Exception e) {
  135. // TODO Auto-generated catch block
  136. e.printStackTrace();
  137. }
  138.  
  139. }
  140.  
  141. @Override
  142. public void onPlayerLogout(EntityPlayer player) {
  143.  
  144.  
  145. }
  146.  
  147. @Override
  148. public void onPlayerChangedDimension(EntityPlayer player) {
  149.  
  150. }
  151.  
  152. @Override
  153. public void onPlayerRespawn(EntityPlayer player) {
  154.  
  155.  
  156. }
  157.  
  158. }
  159.  
  160. // -----------------------
  161. The MIT License (MIT)
  162.  
  163. Copyright (c) 2013 Lyndon White (aka Frames, aka oxinabox, aka magnotop)
  164.  
  165. Permission is hereby granted, free of charge, to any person obtaining a copy
  166. of this software and associated documentation files (the "Software"), to deal
  167. in the Software without restriction, including without limitation the rights
  168. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  169. copies of the Software, and to permit persons to whom the Software is
  170. furnished to do so, subject to the following conditions:
  171.  
  172. The above copyright notice and this permission notice shall be included in
  173. all copies or substantial portions of the Software.
  174.  
  175. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  176. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  177. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  178. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  179. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  180. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  181. THE SOFTWARE.
  182.  
  183. ---------------
  184. Minecraft is the intelectual property of Mojang.
  185. This requires MCP and Forge, both of which have there own licenses.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement