OSDN Git Service

修正・変更
[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
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 itemAtomIngots;
87         public Item itemAtomGrenade;
88         public Item itemBlackSmoke;
89         public Item itemDust;
90         public Item itemRadiationGun;
91         public Item itemRadiationBallet;
92         public Item itemOreSearcher;
93
94         /**
95          * the Register Instances.
96          */
97         public ChemiCraftRegister registerCompounds;
98         public ChemiCraftRegister registerCompoundsHandler;
99         public ChemiCraftRegister registerItem;
100         public ChemiCraftRegister registerChemicalRecipe;
101         public ChemiCraftRegister registerBlock;
102         public ChemiCraftRegister registerRecipe;
103         public ChemiCraftRegister registerEntitys;
104
105         /**
106          * the Textures
107          */
108         public static final String INGOT = ChemiCraft.TEXTURE + "atom_ingots_";
109         public static final String ORE = ChemiCraft.TEXTURE + "atom_ores_";
110
111         public ChemiCraftBase() {
112                 this.registerCompounds = new ChemiCraftRegisterCompounds(this);
113                 this.registerCompoundsHandler = new ChemiCraftRegisterCompoundsHandler(this);
114                 this.registerItem = new ChemiCraftRegisterItem(this);
115                 this.registerChemicalRecipe = new ChemiCraftRegisterChemicalRecipe(this);
116                 this.registerBlock = new ChemiCraftRegisterBlock(this);
117                 this.registerRecipe = new ChemiCraftRegisterBaseRecipe(this);
118                 this.registerEntitys = new ChemiCraftRegisterEntitys(this);
119         }
120
121         @PostInit
122         public void chemiPostLoadMethod(final FMLPostInitializationEvent event) {
123                 this.thread = new Thread(this);
124                 this.event = event;
125                 this.thread.start();
126
127                 try {
128                         this.thread.join();
129                 } catch (InterruptedException e) {
130                         e.printStackTrace();
131                 }
132
133                 proxy.registerRenderInformation();
134                 Thread.yield();
135         }
136
137         @Override
138         public void run() {
139                 while (true) {
140                         if (proxy != null && instance != null) {
141                                 this.settingProcessing((FMLPostInitializationEvent) event);
142                                 break;
143                         }
144                 }
145
146                 Thread loadCheckThread = new Thread() {
147                         @Override
148                         public void run() {
149                                 while (true) {
150                                         List<ModContainer> mod = Loader.instance().getModList();
151                                         ModContainer finalMod = mod.get(mod.size()-1);
152                                         ModState finalModState = Loader.instance().getModState(finalMod);
153                                         if (finalModState == ModState.POSTINITIALIZED) {
154                                                 ChemiCraftCore.logger.write("ChemiCraftBase>APIProcessing", EnumLoggingType.INFO);
155                                                 apiProcessing((FMLPostInitializationEvent) event);
156                                                 break;
157                                         }
158                                 }
159                         }
160                 };
161                 loadCheckThread.start();
162
163         }
164
165         /**
166          * PreInit:<br>
167          * Configをロードします。
168          * @param event アノテーション呼び出しにより呼び出す必要なし
169          */
170         @PreInit
171         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
172                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
173                 cfg.load();
174
175                 Property baseBlockID = cfg.get("BlockID", "Base of Block ID", 2500);
176                 Property baseItemID = cfg.get("ItemID", "Base of Item ID", 25500);
177
178                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(baseBlockID.getInt());
179                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(baseItemID.getInt());
180
181                 for (int i = 0; i < atomOresID.length; i++) {
182                         this.atomOresID[i] = ccfgBlock.additionID();
183                 }
184
185                 this.atomIngotsID = ccfgItem.additionID();
186                 this.atomGrenadeID = ccfgItem.additionID();
187                 this.dustID = ccfgItem.additionID();
188                 this.radiationGunID = ccfgItem.additionID();
189                 this.radiationBalletID = ccfgItem.additionID();
190                 this.blackSmokeID = ccfgItem.additionID();
191                 this.oreSerarcherID = ccfgItem.additionID();
192
193                 cfg.save();
194         }
195
196         protected void settingProcessing(FMLPostInitializationEvent event) {
197                 this.registerCompounds.start();
198                 this.registerCompoundsHandler.start();
199                 this.registerItem.start();
200                 this.registerBlock.start();
201                 this.registerChemicalRecipe.start();
202                 this.registerRecipe.start();
203                 this.registerEntitys.start();
204         }
205
206         private void apiProcessing(final FMLPostInitializationEvent event) {
207                 // API用の処理
208                 for (int i = 0; i < this.apiBase.getAtomOres().size(); i++) {
209                         OreDictionary.registerOre("ore" + this.apiBase.getAtomOresAtomName().get(i), new ItemStack(this.blockAtomOres[i / 16], 1, i % 16));
210                         OreDictionary.registerOre("ingot" + this.apiBase.getAtomOresAtomName().get(i), new ItemStack(this.itemAtomIngots, 1, i ));
211                         GameRegistry.registerWorldGenerator(this.apiBase.getAtomOres().get(i));
212                 }
213
214                 Iterator<String> langoresItr = this.apiBase.getAtomOresName().iterator();
215                 while (langoresItr.hasNext()){
216                         String lang = langoresItr.next();
217                         ArrayList<String> oresName = this.apiBase.getAtomOresName().get(lang);
218                         ArrayList<String> ingotsName = this.apiBase.getAtomIngotsName().get(lang);
219                         for (int i = 0; i < oresName.size(); i++) {
220                                 ChemiCraftCore.logger.write("AtomOresAddName:" + "IngotName-" + ingotsName.get(i) + "OreName-" + oresName.get(i) + "ID-" + (i / 16)+ "/Damage-" + (i - i / 16 * 16) + "/Lang-" + lang,
221                                                 EnumLoggingType.INFO);
222
223                                 LanguageRegistry.instance().addNameForObject(
224                                                 new ItemStack(this.atomOresID[i / 16], 1, i % 16),
225                                                 lang,
226                                                 oresName.get(i)
227                                                 );
228
229                                 /*
230                                 LanguageRegistry.instance().addNameForObject(
231                                                 new ItemStack(this.atomIngotsID, 1, i),
232                                                 lang,
233                                                 ingotsName.get(i)
234                                                 );
235                                                 */
236                         }
237                 }
238
239         }
240
241 }