OSDN Git Service

tc
[chemicraft/chemicraft.git] / common / pcc / chemicraft / base / ChemiCraftBase.java
1 package pcc.chemicraft.base;
2
3 import java.util.List;
4
5 import net.minecraft.block.Block;
6 import net.minecraft.creativetab.CreativeTabs;
7 import net.minecraft.item.Item;
8 import net.minecraft.item.ItemStack;
9 import net.minecraftforge.common.Configuration;
10 import net.minecraftforge.common.Property;
11 import net.minecraftforge.oredict.OreDictionary;
12 import pcc.chemicraft.ChemiCraft;
13 import pcc.chemicraft.ChemiCraftConfiguration;
14 import pcc.chemicraft.ChemiCraftRegister;
15 import pcc.chemicraft.base.creativetab.CreativeTabAtomOres;
16 import pcc.chemicraft.base.system.CommonProxy;
17 import pcc.chemicraft.base.system.PacketHandler;
18 import pcc.chemicraft.core.ChemiCraftAPI;
19 import cpw.mods.fml.common.Loader;
20 import cpw.mods.fml.common.Mod;
21 import cpw.mods.fml.common.ModContainer;
22 import cpw.mods.fml.common.LoaderState.ModState;
23 import cpw.mods.fml.common.Mod.Instance;
24 import cpw.mods.fml.common.Mod.PostInit;
25 import cpw.mods.fml.common.Mod.PreInit;
26 import cpw.mods.fml.common.SidedProxy;
27 import cpw.mods.fml.common.event.FMLInitializationEvent;
28 import cpw.mods.fml.common.event.FMLPostInitializationEvent;
29 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
30 import cpw.mods.fml.common.network.NetworkMod;
31
32 @Mod(modid = "ChemiCraftBase", name = "ChemiCraftBase", version = "beta")
33 @NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "1.4.6", channels = "chemicraftbase", packetHandler = PacketHandler.class)
34 public class ChemiCraftBase extends ChemiCraft
35 {
36
37         /**
38          * this is ChemiCraft instance.
39          */
40         @Instance("ChemiCraftBase")
41         public static ChemiCraftBase instance;
42
43         /**
44          * proxy of ChemiCraft.
45          */
46         @SidedProxy(clientSide = "pcc.chemicraft.base.client.ClientProxy", serverSide = "pcc.chemicraft.base.system.CommonProxy")
47         public static CommonProxy proxy;
48
49         /**
50          * API Instance.
51          */
52         public ChemiCraftAPI api = ChemiCraftAPI.instance();
53         public ChemiCraftBaseAPI apiBase = ChemiCraftBaseAPI.instance();
54
55         /**
56          * CreativeTab of ChemiCraft.
57          */
58         public static final CreativeTabs creativeTabAtomsOre = new CreativeTabAtomOres("AtomsOre");
59
60         /**
61          * the ItemID.
62          */
63         public int atomGrenadeID;
64         public int blackSmokeID;
65         public int dustID;
66         public int radiationGunID;
67         public int radiationBalletID;
68
69         /**
70          * the BlockID.
71          */
72         public int[] atomOresID = new int[3];
73
74         /**
75          * Variables of Block type.
76          */
77         public Block[] blockAtomOres = new Block[atomOresID.length];
78
79         /**
80          * Variables of Item type.
81          */
82         public Item itemAtomGrenade;
83         public Item itemBlackSmoke;
84         public Item itemDust;
85         public Item itemRadiationGun;
86         public Item itemRadiationBallet;
87
88         /**
89          * the Register Instances.
90          */
91         public ChemiCraftRegister registerCompounds;
92         public ChemiCraftRegister registerCompoundsHandler;
93         public ChemiCraftRegister registerItem;
94         public ChemiCraftRegister registerChemicalRecipe;
95         public ChemiCraftRegister registerBlock;
96         public ChemiCraftRegister registerRecipe;
97         public ChemiCraftRegister registerEntitys;
98
99         public ChemiCraftBase()
100         {
101                 this.registerCompounds = new ChemiCraftRegisterCompounds(this);
102                 this.registerCompoundsHandler = new ChemiCraftRegisterCompoundsHandler(this);
103                 this.registerItem = new ChemiCraftRegisterItem(this);
104                 this.registerChemicalRecipe = new ChemiCraftRegisterChemicalRecipe(this);
105                 this.registerBlock = new ChemiCraftRegisterBlock(this);
106                 this.registerRecipe = new ChemiCraftRegisterBaseRecipe(this);
107                 this.registerEntitys = new ChemiCraftRegisterEntitys(this);
108         }
109
110         @PostInit
111         public void chemiPostLoadMethod(final FMLPostInitializationEvent event) {
112                 this.thread = new Thread(this);
113                 this.event = event;
114                 this.thread.start();
115
116                 try {
117                         this.thread.join();
118                 } catch (InterruptedException e) {
119                         e.printStackTrace();
120                 }
121
122                 proxy.registerRenderInformation();
123                 Thread.yield();
124         }
125
126         @Override
127         public void run()
128         {
129                 while (true) {
130                         if (proxy != null && instance != null) {
131                                 this.settingProcessing((FMLPostInitializationEvent) event);
132                                 this.apiProcessing((FMLPostInitializationEvent) event);
133                                 break;
134                         }
135                 }
136
137                 Thread loadCheckThread = new Thread() {
138                         @Override
139                         public void run() {
140                                 while (true) {
141                                         List<ModContainer> mod = Loader.instance().getModList();
142                                         ModContainer finalMod = mod.get(mod.size()-1);
143                                         ModState finalModState = Loader.instance().getModState(finalMod);
144                                         if (finalModState == ModState.AVAILABLE) {
145                                                 apiProcessing((FMLPostInitializationEvent) event);
146                                                 break;
147                                         }
148                                 }
149                         }
150                 };
151                 loadCheckThread.start();
152
153         }
154
155         /**
156          * PreInit:
157          * Configをロードします。
158          * @param event アノテーション呼び出しにより呼び出す必要なし
159          */
160         @PreInit
161         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
162                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
163                 cfg.load();
164
165                 Property baseBlockID = cfg.get("BlockID", "Base of Block ID", 2500);
166                 Property baseItemID = cfg.get("ItemID", "Base of Item ID", 25500);
167
168                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(baseBlockID.getInt());
169                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(baseItemID.getInt());
170
171                 for (int i = 0; i < atomOresID.length; i++) {
172                         this.atomOresID[i] = ccfgBlock.additionID();
173                 }
174
175                 this.atomGrenadeID = ccfgItem.additionID();
176                 this.dustID = ccfgItem.additionID();
177                 this.radiationGunID = ccfgItem.additionID();
178                 this.radiationBalletID = ccfgItem.additionID();
179                 this.blackSmokeID = ccfgItem.additionID();
180
181                 cfg.save();
182         }
183
184         protected void settingProcessing(FMLPostInitializationEvent event)
185         {
186                 this.registerCompounds.start();
187                 this.registerCompoundsHandler.start();
188                 this.registerItem.start();
189                 this.registerBlock.start();
190                 this.registerChemicalRecipe.start();
191                 this.registerRecipe.start();
192                 this.registerEntitys.start();
193         }
194
195         private void apiProcessing(final FMLPostInitializationEvent event) {
196                 // API用の処理
197                 for (int i = 0; i < apiBase.getAtomOresName().sizeKeysList(); i++)
198                 {
199                         for (int j = 0; j < apiBase.getAtomOresName().sizeElementsList(apiBase.getAtomOresName().getKeyList(i)); j++)
200                         {
201                                 this.nameAuxiliary.addName(new ItemStack(blockAtomOres[i / 16], 0, i - i / 16 * 16), apiBase.getAtomOresLanguage().get(apiBase.getAtomOresName().getKeyList(i), j), apiBase.getAtomOresName().get(apiBase.getAtomOresName().getKeyList(i), j));
202                                 OreDictionary.registerOre("ore" + apiBase.getAtomOresName().getKeyList(i), new ItemStack(blockAtomOres[i / 16], 1, i - i / 16 * 16));
203                         }
204                 }
205
206         }
207
208 }