Advertisement
Guest User

MY MOD MAIN CLASS CODE

a guest
Jan 11th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.16 KB | None | 0 0
  1. package LivingSponge.common;
  2.  
  3. import java.io.*;
  4. import java.nio.charset.Charset;
  5. import java.lang.reflect.*;
  6. import cpw.mods.fml.common.Mod;
  7. import cpw.mods.fml.common.Mod.Init;
  8. import cpw.mods.fml.common.event.FMLInitializationEvent;
  9. import cpw.mods.fml.common.network.IGuiHandler;
  10. import cpw.mods.fml.common.network.NetworkMod;
  11. import cpw.mods.fml.common.network.NetworkRegistry;
  12. import cpw.mods.fml.common.registry.GameRegistry;
  13. import cpw.mods.fml.common.registry.LanguageRegistry;
  14. import java.util.*;
  15. import java.util.Map.*;
  16.  
  17. import net.minecraft.potion.Potion;
  18. import net.minecraft.src.*;
  19. import net.minecraft.world.biome.BiomeGenBase;
  20. import net.minecraft.world.biome.BiomeGenMushroomIsland;
  21. import net.minecraft.client.*;
  22. import net.minecraft.entity.EntityList;
  23. import net.minecraft.entity.EnumCreatureType;
  24. import net.minecraft.item.Item;
  25. import net.minecraft.item.ItemBucketMilk;
  26. import net.minecraft.item.ItemStack;
  27. import net.minecraftforge.common.*;
  28. import net.minecraftforge.oredict.*;
  29. import cpw.mods.fml.common.*;
  30. import cpw.mods.fml.common.Mod.*;
  31. import cpw.mods.fml.common.event.*;
  32. import cpw.mods.fml.common.network.*;
  33. import cpw.mods.fml.common.registry.*;
  34. import cpw.mods.fml.relauncher.*;
  35. import cpw.mods.fml.common.registry.EntityRegistry;
  36.  
  37. @Mod(modid = "Living sponge", name = "Living sponge", version = Main.VERSION)
  38. @NetworkMod(clientSideRequired = true, serverSideRequired = false)
  39. public class Main<Entity>
  40. {
  41. public static final String VERSION = "1.2";
  42. @Instance("Living sponge")
  43. public static Main instance;
  44. public static Configuration CONFIG;
  45. public static File LANGFILE_PREFIX;
  46. public static HashMap<String, Configuration> LANG;
  47. public static final String TEXTUREFILE = "/LivingSponge/gfx/";
  48.  
  49. // Blocks start
  50. net.minecraft.block.Block blockSmallSponge;
  51. net.minecraft.block.Block blockSmallWetSponge;
  52. net.minecraft.block.Block blockWetSponge;
  53. static net.minecraft.block.Block blockSpongeCake;
  54. net.minecraft.block.Block blockTinyStar;
  55. net.minecraft.block.Block blockSpongePortalFrame;
  56. public static net.minecraft.block.Block blockSpongePortal;
  57. // Blocks end
  58. //Items start
  59. net.minecraft.item.Item itemSpongeMaterial;
  60. net.minecraft.item.Item itemSpongeCookie;
  61. net.minecraft.item.Item itemSpongeCake;
  62. //Items end
  63. //Entities start
  64. Entity entitySpongeMonster;
  65. Entity entityJumpingSpongeMouseHead;
  66. //Entities end
  67. //Dimensions start
  68. public static int SpongeDimension = 3;
  69. //Dimensions end
  70. public ModContainer cont;
  71. private IGuiHandler guiHandlerObject;
  72. public Main(){}
  73. @SidedProxy(clientSide = "LivingSponge.common.ClientProxyBS", serverSide = "LivingSponge.common.CommonProxyBS")
  74. public static CommonProxyBS proxy;
  75. @PreInit
  76. public void preInit(FMLPreInitializationEvent event) throws IOException
  77. {
  78. instance = this;
  79. cont = Loader.instance().activeModContainer();
  80. if(cont.getMod() != this){throw new RuntimeException("Loader activeModContainer isn't current mod container! "+cont.getModId());}
  81. setMetadata();
  82. File cfgf = new File(Loader.instance().getConfigDir(),"LivingSponges/SS.cfg");
  83. if(!cfgf.getParentFile().exists())
  84. cfgf.getParentFile().mkdirs();
  85. if(!cfgf.exists())
  86. cfgf.createNewFile();
  87. CONFIG = new Configuration(cfgf);
  88. CONFIG.load();
  89. LANGFILE_PREFIX = new File(Loader.instance().getConfigDir(),"LivingSponges/lang/");
  90. if(!LANGFILE_PREFIX.exists())
  91. LANGFILE_PREFIX.mkdir();
  92. for(File f : LANGFILE_PREFIX.listFiles(new FilenameFilter() {
  93.  
  94. @Override
  95. public boolean accept(File dir, String name) {
  96. return name.endsWith(".cfg");
  97. }
  98. }))
  99. {
  100. String fnm = f.getName(), lang = fnm.trim().substring(0, fnm.length()-4);
  101. Properties prs = new Properties();
  102. prs.load(new InputStreamReader(new FileInputStream(f), Charset.forName("UTF8")));
  103. for(Entry<Object,Object> ent: prs.entrySet())
  104. {
  105. String k = (String)ent.getKey(), v = (String)ent.getValue();
  106. LanguageRegistry.instance().addStringLocalization(k, lang, v);
  107. }
  108. }
  109. loadConfig();
  110. }
  111.  
  112. @Init
  113. public void init(FMLInitializationEvent event) throws Throwable
  114. {
  115. addBlocks();
  116. addItems();
  117. addEntities();
  118. addGen();
  119. addDimension();
  120. }
  121.  
  122. @PostInit
  123. public void postInit(FMLPostInitializationEvent event)
  124. {
  125. addRecipes();
  126. addSmelting();
  127. addEntities();
  128. addGen();
  129. addDimension();
  130. proxy.registerRenderThings();
  131. }
  132.  
  133. public String getVersion() {
  134. return VERSION;
  135. }
  136.  
  137. protected void setMetadata()
  138. {
  139. cont.getMetadata().autogenerated=false;
  140. cont.getMetadata().authorList.add("Adanos020 [on YouTube: MinecraftAdanos]");
  141. cont.getMetadata().credits = "";
  142. cont.getMetadata().description = "Sponges are achieveable now! To get sponges you have to kill sponge monsters! Now you can build a portal and travel to the mysterious Sponge World!";
  143. }
  144.  
  145. protected void loadConfig()
  146. {
  147. CONFIG.save();
  148. }
  149.  
  150. protected void addBlocks() throws IllegalArgumentException, IllegalAccessException
  151. {
  152. int tid;
  153.  
  154. tid = CONFIG.getBlock("Small wet sponge", 1550).getInt();
  155. blockSmallWetSponge = new BlockSmallWetSponge(1550).setStepSound(net.minecraft.block.Block.soundGrassFootstep).setHardness(0.5F).setResistance(1.0F).setBlockName("Wet small sponge");
  156. GameRegistry.registerBlock(blockSmallWetSponge);
  157. LanguageRegistry.addName(blockSmallWetSponge, "Wet small sponge");
  158.  
  159. tid = CONFIG.getBlock("Small sponge", 1551).getInt();
  160. blockSmallSponge = new BlockSmallSponge(1551).setStepSound(net.minecraft.block.Block.soundGrassFootstep).setHardness(0.5F).setResistance(1.0F).setBlockName("Small sponge");
  161. GameRegistry.registerBlock(blockSmallSponge);
  162. LanguageRegistry.addName(blockSmallSponge, "Small sponge");
  163.  
  164. tid = CONFIG.getBlock("Wet sponge", 1552).getInt();
  165. blockWetSponge = new BlockWetSponge(1552).setStepSound(net.minecraft.block.Block.soundGrassFootstep).setHardness(0.5F).setResistance(1.0F).setBlockName("Wet sponge");
  166. GameRegistry.registerBlock(blockWetSponge);
  167. LanguageRegistry.addName(blockWetSponge, "Wet sponge");
  168.  
  169. tid = CONFIG.getBlock("Sponge cake", 1553).getInt();
  170. blockSpongeCake = new BlockSpongeCake(1553, 48).setStepSound(net.minecraft.block.Block.soundGrassFootstep).setHardness(0.5F).setResistance(1.0F).setBlockName("Sponge cake");
  171. GameRegistry.registerBlock(blockSpongeCake);
  172. LanguageRegistry.addName(blockSpongeCake, "Sponge cake");
  173.  
  174. tid = CONFIG.getBlock("Sponge portal frame", 1554).getInt();
  175. blockSpongePortalFrame = new BlockSpongePortalFrame(1554).setStepSound(net.minecraft.block.Block.soundStoneFootstep).setHardness(1F).setResistance(1.0F).setBlockName("Sponge portal frame");
  176. GameRegistry.registerBlock(blockSpongePortalFrame);
  177. LanguageRegistry.addName(blockSpongePortalFrame, "Sponge portal frame");
  178.  
  179. tid = CONFIG.getBlock("Sponge portal", 1555).getInt();
  180. blockSpongePortal = new BlockSpongePortal(1555, 1).setBlockName("Sponge portal");
  181. GameRegistry.registerBlock(blockSpongePortal, "Sponge portal");
  182. LanguageRegistry.addName(blockSpongePortal, "Sponge portal");
  183.  
  184. tid = CONFIG.getBlock("Tiny star", 1556).getInt();
  185. blockTinyStar = new BlockTinyStar(1556).setStepSound(net.minecraft.block.Block.soundStoneFootstep).setHardness(1F).setResistance(1.0F).setBlockName("Tiny star");
  186. GameRegistry.registerBlock(blockTinyStar);
  187. LanguageRegistry.addName(blockTinyStar, "Tiny star");
  188.  
  189. CONFIG.save();
  190. }
  191. protected void addEntities()
  192. {
  193. addEntityName(registerEntity(EntitySpongeMonster.class, "Sponge", ModLoader.getUniqueEntityId(), 0xffff00, 0x000000), "Sponge");
  194. EntityRegistry.registerModEntity(EntitySpongeMonster.class, "Sponge", 44, this, 40, 1, true);
  195. EntityRegistry.addSpawn(EntitySpongeMonster.class, 2, 3, 5, EnumCreatureType.ambient, BiomeGenBase.beach, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.mushroomIsland, BiomeGenBase.mushroomIslandShore, BiomeGenBase.ocean, BiomeGenBase.river, BiomeGenBase.swampland);
  196.  
  197. addEntityName(registerEntity(EntitySpongeMonster.class, "Jumping sponge mouse head", ModLoader.getUniqueEntityId(), 0xffff00, 0xff00aa), "Jumping sponge mouse head");
  198. EntityRegistry.registerModEntity(EntityJumpingSpongeMouseHead.class, "Jumping sponge mouse head", 45, this, 41, 1, true);
  199. EntityRegistry.addSpawn(EntitySpongeMonster.class, 2, 3, 5, EnumCreatureType.ambient, BiomeGenBase.beach, BiomeGenBase.desert);
  200. }
  201. public static int registerEntity(Class class1, String str1, int i1, int i2, int i3)
  202. {
  203. ModLoader.registerEntityID(class1, str1, i1, i2, i3);
  204. return i1;
  205. }
  206.  
  207. public static void addEntityName(int i1, String str2)
  208. {
  209. ModLoader.addLocalization("entity." + EntityList.getStringFromID(i1) + ".name", str2);
  210. }
  211.  
  212. protected void addRecipes()
  213. {
  214. GameRegistry.addRecipe(new ItemStack(blockSmallSponge), new Object[]
  215. {
  216. "XXX", "XXX", "XXX", 'X', itemSpongeMaterial
  217. });
  218. GameRegistry.addRecipe(new ItemStack(net.minecraft.block.Block.sponge, 1), new Object[]
  219. {
  220. "XX", "XX", 'X', blockSmallSponge
  221. });
  222. GameRegistry.addRecipe(new ItemStack(itemSpongeCake, 1), new Object[]
  223. {
  224. "ZAZ", "YBY", "XXX", 'X', blockSmallSponge, 'Z', Item.bucketMilk, 'Y', Item.sugar, 'B', Item.egg, 'A', itemSpongeMaterial
  225. });
  226. GameRegistry.addShapelessRecipe(new ItemStack(blockSmallWetSponge), new Object[]
  227. {
  228. new ItemStack(Item.bucketWater), new ItemStack(blockSmallSponge)
  229. });
  230. GameRegistry.addShapelessRecipe(new ItemStack(blockWetSponge), new Object[]
  231. {
  232. new ItemStack(Item.bucketWater), new ItemStack(net.minecraft.block.Block.sponge)
  233. });
  234. GameRegistry.addRecipe(new ItemStack(itemSpongeCookie, 1), new Object[]
  235. {
  236. "XYX", 'X', itemSpongeMaterial, 'Y', new ItemStack(Item.dyePowder, 1, 3)
  237. });
  238. GameRegistry.addRecipe(new ItemStack(blockSpongePortalFrame), new Object[]
  239. {
  240. "XYX", "YZY", "XYX", 'X', Item.diamond, 'Y', net.minecraft.block.Block.sponge, 'Z', blockTinyStar
  241. });
  242. GameRegistry.addRecipe(new ItemStack(blockTinyStar), new Object[]
  243. {
  244. "0X0", "XYX", "0X0", 'X', Item.diamond, 'Y', Item.netherStar
  245. });
  246. }
  247. protected void addItems()
  248. {
  249. int tid;
  250.  
  251. tid = CONFIG.getItem("Sponge material", 5550).getInt();
  252. itemSpongeMaterial = new ItemSpongeMaterial(5550).setItemName("Sponge material");
  253. LanguageRegistry.addName(itemSpongeMaterial, "Sponge material");
  254.  
  255. tid = CONFIG.getItem("Sponge cookie", 5551).getInt();
  256. itemSpongeCookie = new ItemSpongeCookie(5551, 1, true).setItemName("Sponge cookie");
  257. LanguageRegistry.addName(itemSpongeCookie, "Sponge cookie");
  258.  
  259. tid = CONFIG.getItem("Sponge cake", 5552).getInt();
  260. itemSpongeCake = new ItemSpongeCake(5552, 1, true, blockSpongeCake).setItemName("Sponge cake");
  261. LanguageRegistry.addName(itemSpongeCake, "Sponge cake");
  262.  
  263. CONFIG.save();
  264. }
  265. protected void addSmelting()
  266. {
  267.  
  268. }
  269. public void addGen()
  270. {
  271. GameRegistry.registerWorldGenerator(new WorldGenTinyStar());
  272. }
  273. private void addDimension()
  274. {
  275. DimensionManager.registerProviderType(SpongeDimension, WorldSpongeDimension.class, false);
  276. DimensionManager.registerDimension(SpongeDimension, SpongeDimension);
  277. }
  278. @ServerStarting
  279. public void onServerStarting(FMLServerStartingEvent ev)
  280. {
  281.  
  282. }
  283.  
  284. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement