OSDN Git Service

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