OSDN Git Service

Merge branch 'master' of https://scm.sourceforge.jp/gitroot/chemicraft/chemicraft
[chemicraft/chemicraft.git] / common / pcc / chemicraft / base / ChemiCraftBase.java
1 package pcc.chemicraft.base;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6
7 import net.minecraft.block.Block;
8 import net.minecraft.creativetab.CreativeTabs;
9 import net.minecraft.item.Item;
10 import net.minecraft.item.ItemStack;
11 import net.minecraftforge.common.Configuration;
12 import net.minecraftforge.common.Property;
13 import net.minecraftforge.oredict.OreDictionary;
14 import pcc.chemicraft.ChemiCraft;
15 import pcc.chemicraft.ChemiCraftConfiguration;
16 import pcc.chemicraft.ChemiCraftRegister;
17 import pcc.chemicraft.EnumLoggingType;
18 import pcc.chemicraft.base.creativetab.CreativeTabAtomOres;
19 import pcc.chemicraft.base.system.CommonProxy;
20 import pcc.chemicraft.base.system.PacketHandler;
21 import pcc.chemicraft.core.ChemiCraftCore;
22 import cpw.mods.fml.common.Loader;
23 import cpw.mods.fml.common.LoaderState.ModState;
24 import cpw.mods.fml.common.Mod;
25 import cpw.mods.fml.common.Mod.Instance;
26 import cpw.mods.fml.common.Mod.PostInit;
27 import cpw.mods.fml.common.Mod.PreInit;
28 import cpw.mods.fml.common.ModContainer;
29 import cpw.mods.fml.common.SidedProxy;
30 import cpw.mods.fml.common.event.FMLPostInitializationEvent;
31 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
32 import cpw.mods.fml.common.network.NetworkMod;
33 import cpw.mods.fml.common.registry.GameRegistry;
34 import cpw.mods.fml.common.registry.LanguageRegistry;
35
36 @Mod(modid = "ChemiCraftBase", name = "ChemiCraftBase", version = "beta1")
37 @NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "1.5", 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 ChemiCraftBaseAPI apiBase = ChemiCraftBaseAPI.instance();
56
57         /**
58          * CreativeTab of ChemiCraft.
59          */
60         public static final CreativeTabs creativeTabAtomOres = new CreativeTabAtomOres("AtomOres");
61
62         /**
63          * the ItemID.
64          */
65         public int atomIngotsID;
66         public int atomGrenadeID;
67         public int blackSmokeID;
68         public int oreSerarcherID;
69         public int dustID;
70         public int radiationGunID;
71         public int radiationBalletID;
72         public int raditionGunDataChipID;
73
74         /**
75          * the BlockID.
76          */
77         public int[] atomOresID = new int[4];
78
79         /**
80          * Variables of Block type.
81          */
82         public Block[] blockAtomOres = new Block[atomOresID.length];
83
84         /**
85          * Variables of Item type.
86          */
87         public Item itemAtomIngots;
88         public Item itemAtomGrenade;
89         public Item itemBlackSmoke;
90         public Item itemDust;
91         public Item itemRadiationGun;
92         public Item itemRadiationBallet;
93         public Item itemOreSearcher;
94         public Item itemRaditionGunDataChip;
95
96         /**
97          * the Register Instances.
98          */
99         public ChemiCraftRegister registerCompounds;
100         public ChemiCraftRegister registerCompoundsHandler;
101         public ChemiCraftRegister registerItem;
102         public ChemiCraftRegister registerChemicalRecipe;
103         public ChemiCraftRegister registerBlock;
104         public ChemiCraftRegister registerRecipe;
105         public ChemiCraftRegister registerEntitys;
106
107         /**
108          * the Textures.
109          */
110         public static final String INGOT = ChemiCraft.TEXTURE + "atom_ingots_";
111         public static final String ORE = ChemiCraft.TEXTURE + "atom_ores_";
112
113         public ChemiCraftBase() {
114                 this.registerCompounds = new ChemiCraftRegisterCompounds(this);
115                 this.registerCompoundsHandler = new ChemiCraftRegisterCompoundsHandler(this);
116                 this.registerItem = new ChemiCraftRegisterItem(this);
117                 this.registerChemicalRecipe = new ChemiCraftRegisterChemicalRecipe(this);
118                 this.registerBlock = new ChemiCraftRegisterBlock(this);
119                 this.registerRecipe = new ChemiCraftRegisterBaseRecipe(this);
120                 this.registerEntitys = new ChemiCraftRegisterEntitys(this);
121         }
122
123         @PostInit
124         public void chemiPostLoadMethod(final FMLPostInitializationEvent event) {
125                 this.thread = new Thread(this);
126                 this.event = event;
127                 this.thread.start();
128
129                 try {
130                         this.thread.join();
131                 } catch (InterruptedException e) {
132                         e.printStackTrace();
133                 }
134
135                 proxy.registerRenderInformation();
136                 Thread.yield();
137         }
138
139         @Override
140         public void run() {
141                 while (true) {
142                         if (proxy != null && instance != null) {
143                                 this.settingProcessing((FMLPostInitializationEvent) event);
144                                 break;
145                         }
146                 }
147
148                 Thread loadCheckThread = new Thread() {
149                         @Override
150                         public void run() {
151                                 while (true) {
152                                         List<ModContainer> mod = Loader.instance().getModList();
153                                         ModContainer finalMod = mod.get(mod.size()-1);
154                                         ModState finalModState = Loader.instance().getModState(finalMod);
155                                         if (finalModState == ModState.POSTINITIALIZED) {
156                                                 ChemiCraftCore.logger.write("ChemiCraftBase>APIProcessing", EnumLoggingType.INFO);
157                                                 apiProcessing((FMLPostInitializationEvent) event);
158                                                 break;
159                                         }
160                                 }
161                         }
162                 };
163                 loadCheckThread.start();
164
165         }
166
167         /**
168          * PreInit:<br>
169          * Configをロードします。
170          * @param event アノテーション呼び出しにより呼び出す必要なし
171          */
172         @PreInit
173         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
174                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
175                 cfg.load();
176
177                 Property baseBlockID = cfg.get("BlockID", "Base of Block ID", 2500);
178                 Property baseItemID = cfg.get("ItemID", "Base of Item ID", 25500);
179
180                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(baseBlockID.getInt());
181                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(baseItemID.getInt());
182
183                 for (int i = 0; i < atomOresID.length; i++) {
184                         this.atomOresID[i] = ccfgBlock.additionID();
185                 }
186
187                 this.atomIngotsID = ccfgItem.additionID();
188                 this.atomGrenadeID = ccfgItem.additionID();
189                 this.dustID = ccfgItem.additionID();
190                 this.radiationGunID = ccfgItem.additionID();
191                 this.radiationBalletID = ccfgItem.additionID();
192                 this.blackSmokeID = ccfgItem.additionID();
193                 this.oreSerarcherID = ccfgItem.additionID();
194
195                 cfg.save();
196         }
197
198         protected void settingProcessing(FMLPostInitializationEvent event) {
199                 this.registerCompounds.start();
200                 this.registerCompoundsHandler.start();
201                 this.registerItem.start();
202                 this.registerBlock.start();
203                 this.registerChemicalRecipe.start();
204                 this.registerRecipe.start();
205                 this.registerEntitys.start();
206         }
207
208         private void apiProcessing(final FMLPostInitializationEvent event) {
209                 // API用の処理
210                 for (int i = 0; i < this.apiBase.getAtomOres().size(); i++) {
211                         OreDictionary.registerOre("ore" + this.apiBase.getAtomOresAtomName().get(i), new ItemStack(this.blockAtomOres[i / 16], 1, i % 16));
212                         OreDictionary.registerOre("ingot" + this.apiBase.getAtomOresAtomName().get(i), new ItemStack(this.itemAtomIngots, 1, i ));
213                         GameRegistry.registerWorldGenerator(this.apiBase.getAtomOres().get(i));
214                 }
215
216                 Iterator<String> langoresItr = this.apiBase.getAtomOresName().iterator();
217                 while (langoresItr.hasNext()){
218                         String lang = langoresItr.next();
219                         ArrayList<String> oresName = this.apiBase.getAtomOresName().get(lang);
220                         ArrayList<String> ingotsName = this.apiBase.getAtomIngotsName().get(lang);
221                         for (int i = 0; i < oresName.size(); i++) {
222                                 ChemiCraftCore.logger.write("AtomOresAddName:" + "IngotName-" + ingotsName.get(i) + "OreName-" + oresName.get(i) + "ID-" + (i / 16)+ "/Damage-" + (i - i / 16 * 16) + "/Lang-" + lang,
223                                                 EnumLoggingType.INFO);
224
225                                 LanguageRegistry.instance().addNameForObject(
226                                                 new ItemStack(this.atomOresID[i / 16], 1, i % 16),
227                                                 lang,
228                                                 oresName.get(i)
229                                                 );
230
231                                 /*
232                                 LanguageRegistry.instance().addNameForObject(
233                                                 new ItemStack(this.atomIngotsID, 1, i),
234                                                 lang,
235                                                 ingotsName.get(i)
236                                                 );
237                                                 */
238                         }
239                 }
240
241         }
242
243 }