OSDN Git Service

Merge branch 'master' of git.sourceforge.jp:/gitroot/chemicraft/chemicraft
[chemicraft/chemicraft.git] / common / pcc / chemicraft / ChemiCraft.java
1 package pcc.chemicraft;
2
3 import net.minecraft.block.Block;
4 import net.minecraft.creativetab.CreativeTabs;
5 import net.minecraft.item.Item;
6 import net.minecraft.item.ItemStack;
7 import net.minecraftforge.common.Configuration;
8 import net.minecraftforge.common.Property;
9 import net.minecraftforge.oredict.OreDictionary;
10 import pcc.chemicraft.compounds.CompoundDebug;
11 import pcc.chemicraft.creativetab.CreativeTabAtomOres;
12 import pcc.chemicraft.creativetab.CreativeTabChemiCraft;
13 import pcc.chemicraft.debug.CommandDeleteItem;
14 import pcc.chemicraft.debug.CommandGenDebugRoom;
15 import pcc.chemicraft.debug.CommandSetTile;
16 import pcc.chemicraft.system.CommonProxy;
17 import pcc.chemicraft.system.PacketHandler;
18 import pcc.chemicraft.util.Auxiliary;
19 import pcc.chemicraft.util.Auxiliary.ArrayAuxiliary;
20 import pcc.chemicraft.util.Auxiliary.MathAuxiliary;
21 import pcc.chemicraft.util.Auxiliary.NameAuxiliary;
22 import cpw.mods.fml.common.Mod;
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.Mod.ServerStarting;
27 import cpw.mods.fml.common.SidedProxy;
28 import cpw.mods.fml.common.event.FMLPostInitializationEvent;
29 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
30 import cpw.mods.fml.common.event.FMLServerStartingEvent;
31 import cpw.mods.fml.common.network.NetworkMod;
32 import cpw.mods.fml.common.network.NetworkRegistry;
33 import cpw.mods.fml.common.registry.GameRegistry;
34
35 /**
36  * ChemiCraft本体
37  * @author P.C.C.
38  */
39 @Mod(modid = "chemiCraft", name = "ChemiCraft", version = "beta")
40 @NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "1.4.6", channels = "chemicraft", packetHandler = PacketHandler.class)
41 public class ChemiCraft implements Runnable {
42
43         /**
44          * 元素名配列
45          */
46         public static final String[] ATOMSNAME = {
47                 "Hydrogen", "Helium", "Lithium", "Beryllium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine", "Neon", "Sodium", "Magnesium", "Aluminium", "Silicon",
48                 "Phosphorus", "Sulfur", "Chlorine", "Argon", "Potassium", "Calcium", "Scandium", "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel", "Copper", "Zinc", "Gallium",
49                 "Germanium", "Arsenic", "Selenium", "Bromine", "Krypton", "Rubidium", "Strontium", "Yttorium", "Zirconium", "Niobium", "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium",
50                 "Silver", "Cadmium", "Indium", "Tin", "Antimony", "Tellurium", "Iodine", "Xenon", "Caesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium", "Promethium", "Samarium",
51                 "Europium", "Gadolinium", "Terbium", "Dysprosium", "Holmium", "Erbium", "Thulium", "Ytterbium", "Lutetium", "Hafnium", "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinum",
52                 "Gold", "Mercury", "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon", "Francium", "Radium", "Actinium", "Thorium", "Protactinium", "Uranium", "Neptunium", "Plutonium",
53                 "Americium", "Curium", "Berkelium", "Californium", "Einsteinium", "Fermium", "Mendelevium", "Nobelium", "Lawrencium", "Rutherfordium", "Dubnium", "Seaborgium", "Bohrium", "Hassium",
54                 "Meitnerium", "Darmstadtium", "Roentgenium", "Copernicium", "Ununtrium", "Ununquadium", "Ununpentium", "Ununhexium", "Ununseptium", "Ununoctium" };
55
56         /**
57          * 元素名日本語版配列
58          */
59         public static final String[] ATOMSNAMEJP = {
60                 "水素", "ヘリウム", "リチウム", "ベリウム", "ホウ素", "炭素", "窒素", "酸素", "フッ素", "ネオン", "ナトリウム", "マグネシウム", "アルミニウム", "ケイ素", "リン", "硫黄", "塩素", "アルゴン", "カリウム", "カルシウム", "スカンジウム",
61                 "チタン", "バナジウム", "クロム", "マンガン", "鉄", "コバルト", "ニッケル", "銅", "亜鉛", "ガリウム", "ゲルマニウム", "ヒ素", "セレン", "臭素", "クリプトン", "ルビジウム", "ストロンチウム", "イットリウム", "ジルコニウム", "ニオブ", "モリブデン", "テクネチウム", "ルテニウム",
62                 "ロジウム", "パラジウム", "銀", "カドミウム", "インジウム", "スズ", "アンチモン", "テルル", "ヨウ素", "キセノン", "セシウム", "バリウム", "ランタン", "セリウム", "プラセオジム", "ネオジム", "プロメチウム", "サマリウム", "ユウロビウム", "ガドリニウム", "テルビウム", "ジスプロニウム",
63                 "ホルミウム", "エルビウム", "ツリウム", "イッテルビウム", "ルテチウム", "ハフニウム", "タンタル", "タングステン", "レニウム", "オスミウム", "イリジウム", "白金", "金", "水銀", "タリウム", "鉛", "ビスマス", "ポロニウム", "アスタチン", "ラドン", "フランシウム", "ラジウム",
64                 "アクチニウム", "トリウム", "プロトアクチウム", "ウラン", "ネプツニウム", "プルトニウム", "アメリシウム", "キュリウム", "バークリウム", "カルホルニウム", "アインスタイニウム", "フェルミウム", "メンデレビウム", "ノーベリウム", "ローレンシウム", "ラサホージウム", "ドブニウム", "シーボーギウム",
65                 "ボーリウム", "ハッシウム", "マイトネリウム", "ダームスタチウム", "レントゲニウム", "コペルニシウム", "ウンウントリウム", "ウンウンクアジウム", "ウンウンペンチウム", "ウンウンヘキシウム", "ウンウンセプチウム", "ウンウンオクチウム" };
66
67         /**
68          * this is ChemiCraft instance.
69          */
70         @Instance("chemiCraft")
71         public static ChemiCraft instance;
72
73         /**
74          * proxy of ChemiCraft.
75          */
76         @SidedProxy(clientSide = "pcc.chemicraft.client.ClientProxy", serverSide = "pcc.chemicraft.system.CommonProxy")
77         public static CommonProxy proxy;
78
79         /**
80          * CreativeTab of ChemiCraft.
81          */
82         public static final CreativeTabs creativeTabChemiCraft = new CreativeTabChemiCraft("ChemiCraft");
83         public static final CreativeTabs creativeTabAtomsOre = new CreativeTabAtomOres("AtomsOre");
84
85         /**
86          * the ItemID.
87          */
88         public int atomsID;
89         public int compoundsID;
90         public int gasCollectingBottleID;
91         public int atomGrenadeID;
92         public int chemicalCellsID;
93         public int dustID;
94         public int radiationGunID;
95         public int radiationBalletID;
96         public int blackSmokeID;
97         public int pearID;
98
99         /**
100          * the BlockID.
101          */
102         public int pyrolysisTableID;
103         public int electrolysisTableID;
104         public int chemicalConbinationTableID;
105         public int toolAndWeaponCraftingTableID;
106         public int chemicalCraftingTableID;
107
108         public int[] atomOresID = new int[3];
109
110         /**
111          * the GUIID.
112          */
113         public int guiPyrolysisTableID;
114         public int guiElectrolysisTableID;
115         public int guiChemicalCombinationTableID;
116         public int guiToolAndWeaponCraftingTableID;
117         public int guiChemicalCraftingTableID;
118
119         /**
120          * Variables of Block type.
121          */
122         public Block blockPyrolysisTable;
123         public Block blockElectrolysisTable;
124         public Block blockChemicalCombinationTable;
125         public Block blockToolAndWeaponCraftingTable;
126         public Block blockChemicalCraftingTable;
127
128         public Block[] blockAtomOres = new Block[atomOresID.length];
129
130         /**
131          * Variables of Block type.
132          */
133         public Item itemAtoms;
134         public Item itemCompounds;
135         public Item itemGasCollectingBottle;
136         public Item itemAtomGrenade;
137         public Item itemChemicalCells;
138         public Item itemDust;
139         public Item itemRadiationGun;
140         public Item itemRadiationBallet;
141         public Item itemBlackSmoke;
142         public Item itemPear;
143
144         /**
145          * this is Textures Path on ChemiCraft.
146          */
147         public final String ITEM_ATOMS_TEXTURE = "/pcc/chemicraft/items/Atoms.png";
148         public final String ITEM_COMPOUNDS_TEXTURE = "/pcc/chemicraft/items/Compounds.png";
149         public final String ITEM_VEGETABLES_TEXTURE = "/pcc/chemicraft/items/Vegetables.png";
150         public final String ITEM_TEXTURE = "/pcc/chemicraft/items/items.png";
151         public final String BLOCK_CHEMICAL_CRAFTING_TABLE_TEXTURE = "/pcc/chemicraft/blocks/cctable.png";
152         public final String BLOCK_ATOMS_ORE_TEXTURE = "/pcc/chemicraft/blocks/AtomsOre.png";
153         public final String BLOCK_VEGETABLES_TEXTURE = "/pcc/chemicraft/blocks/Vegetables.png";
154         public final String GUI_PYROLYSIS_TEXTURE = "/pcc/chemicraft/guis/Pyrolysis.png";
155         public final String GUI_ELECTROLYSIS_TEXTURE = "/pcc/chemicraft/guis/Electrolysis.png";
156         public final String GUI_CHEMICALCOMBINATION_TEXTURE = "/pcc/chemicraft/guis/ChemicalCombination.png";
157         public final String GUI_TOOLANDWEAPONCRAFTING_TEXTURE = "/pcc/chemicraft/guis/ToolAndWeaponCrafting.png";
158         public final String GUI_CHEMICALCRAFTING_TEXTURE = "/pcc/chemicraft/guis/MaterialCrafting.png";
159         public final String ENTITY_PARTICLE_TEXRURE = "/pcc/chemicraft/entityParticles/dust.png";
160
161         /**
162          *These Instances required on ChemiCraft.
163          */
164         public Auxiliary auxiliary = new Auxiliary();
165         public NameAuxiliary nameAuxiliary = new NameAuxiliary();
166         public ArrayAuxiliary arrayAuxiliary = new ArrayAuxiliary();
167         public MathAuxiliary mathAuxiliary = new MathAuxiliary();
168
169         /**
170          * API Instance and Data Instance.
171          */
172         public ChemiCraftAPI api = ChemiCraftAPI.instance();
173         public static final ChemiCraftData chemicalData = new ChemiCraftData();
174
175         /**
176          * this is Thread on ChemiCraft.
177          */
178         private Thread thread;
179
180         /**
181          * the Event Instance.
182          */
183         private FMLPostInitializationEvent event;
184
185         /**
186          * the Register Instances.
187          */
188         public ChemiCraftRegisterBlock registerBlock;
189         public ChemiCraftRegisterItem registerItem;
190         public ChemiCraftRegisterTileEntity registerTileEntity;
191         public ChemiCraftRegisterRecipe registerRecipe;
192         public ChemiCraftRegisterChemicalRecipe registerChemicalRecipe;
193         public ChemiCraftRegisterCompounds registerCompounds;
194         public ChemiCraftRegisterCompoundsHandler registerCompoundsHandler;
195         public ChemiCraftRegisterEntitys registerEntitys;
196
197         public ChemiCraft() {
198                 this.registerBlock = new ChemiCraftRegisterBlock(this);
199                 this.registerItem = new ChemiCraftRegisterItem(this);
200                 this.registerTileEntity = new ChemiCraftRegisterTileEntity(this);
201                 this.registerRecipe = new ChemiCraftRegisterRecipe(this);
202                 this.registerChemicalRecipe = new ChemiCraftRegisterChemicalRecipe(this);
203                 this.registerCompounds = new ChemiCraftRegisterCompounds(this);
204                 this.registerCompoundsHandler = new ChemiCraftRegisterCompoundsHandler(this);
205                 this.registerEntitys = new ChemiCraftRegisterEntitys(this);
206
207                 //this.sinVisualizer  = new SinVisualizer();
208         }
209
210         /**
211          * PreInit:
212          * Configをロードします。
213          * @param event アノテーション呼び出しにより呼び出す必要なし
214          */
215         @PreInit
216         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
217                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
218                 cfg.load();
219
220                 Property baseBlockID = cfg.get("BlockID", "Base of Block ID", 2400);
221                 Property baseItemID = cfg.get("ItemID", "Base of Item ID", 25000);
222
223                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(baseBlockID.getInt());
224                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(baseBlockID.getInt());
225
226                 this.pyrolysisTableID = ccfgBlock.additionID();
227                 this.electrolysisTableID = ccfgBlock.additionID();
228                 this.chemicalConbinationTableID = ccfgBlock.additionID();
229                 this.toolAndWeaponCraftingTableID = ccfgBlock.additionID();
230                 this.chemicalCraftingTableID = ccfgBlock.additionID();
231                 for (int i = 0; i < atomOresID.length; i++) {
232                         this.atomOresID[i] = ccfgBlock.additionID();
233                 }
234
235                 this.atomsID = ccfgItem.additionID();
236                 this.compoundsID = ccfgItem.additionID();
237                 this.gasCollectingBottleID = ccfgItem.additionID();
238                 this.atomGrenadeID = ccfgItem.additionID();
239                 this.chemicalCellsID = ccfgItem.additionID();
240                 this.dustID = ccfgItem.additionID();
241                 this.radiationGunID = ccfgItem.additionID();
242                 this.radiationBalletID = ccfgItem.additionID();
243                 this.blackSmokeID = ccfgItem.additionID();
244
245                 Property guiPyrolysisTableIDProp = cfg.get("GUI", "GUIPyrolysisID", 1000);
246                 Property guiElectrolysisTableIDProp = cfg.get("GUI", "GUIElectrolysisTableIDProp", 1001);
247                 Property guiChemicalCombinationTableIDProp = cfg.get("GUI", "GUIChemicalCombinationTableID", 1002);
248                 Property guiToolAndWeaponCraftingTableIDProp = cfg.get("GUI", "GUIToolAndWeaponCraftingTableID", 1003);
249                 Property guiChemicalCraftingTableIDProp = cfg.get("GUI", "GUIChemicalCraftingTableID", 1004);
250
251                 this.guiPyrolysisTableID = guiPyrolysisTableIDProp.getInt();
252                 this.guiElectrolysisTableID = guiElectrolysisTableIDProp.getInt();
253                 this.guiChemicalCombinationTableID = guiChemicalCombinationTableIDProp.getInt();
254                 this.guiToolAndWeaponCraftingTableID = guiToolAndWeaponCraftingTableIDProp.getInt();
255                 this.guiChemicalCraftingTableID = guiChemicalCraftingTableIDProp.getInt();
256
257                 /*
258                 Property pyrolysisTableIDProp = cfg.getBlock("PyrolysisTable", 2400);
259                 Property electrolysisTableIDProp = cfg.getBlock("ElectrolysisTable", 2401);
260                 Property chemicalCombinationTableIDProp = cfg.getBlock("ChemicalCombinationID", 2402);
261                 Property toolAndWeaponCraftingTableIDProp = cfg.getBlock("ToolAndWeaponCraftingTableID", 2403);
262                 Property chemicalCraftingTableIDProp = cfg.getBlock("ChemicalCraftingTableID", 2404);
263
264                 Property[] atomOresIDProp = new Property[this.atomOresID.length];
265                 for (int i = 0; i < atomOresIDProp.length; i++) {
266                         atomOresIDProp[i] = cfg.getBlock("AtomsOreID:" + i, 2500 + i);
267                 }
268
269                 Property atomsIDProp = cfg.getItem("AtomsID", 25000);
270                 Property compoundsIDProp = cfg.getItem("CompoundsID", 25001);
271                 Property gasCollectingBottleIDProp = cfg.getItem("gasCollectingBottleID", 25002);
272                 Property atomGrenadeIDProp = cfg.getItem("AtomGrenadeID", 25003);
273                 Property chemicalCellsIDProp = cfg.getItem("ChemicalCellID", 25004);
274                 Property dustIDProp = cfg.getItem("DustID", 25005);
275                 Property radiationGunIDProp = cfg.getItem("RadiationGunID", 25006);
276                 Property radiationBalletIDProp = cfg.getItem("RadiationBalletID", 25007);
277
278                 Property guiPyrolysisTableIDProp = cfg.get("GUI", "GUIPyrolysisID", 1000);
279                 Property guiElectrolysisTableIDProp = cfg.get("GUI", "GUIElectrolysisTableIDProp", 1001);
280                 Property guiChemicalCombinationTableIDProp = cfg.get("GUI", "GUIChemicalCombinationTableID", 1002);
281                 Property guiToolAndWeaponCraftingTableIDProp = cfg.get("GUI", "GUIToolAndWeaponCraftingTableID", 1003);
282                 Property guiChemicalCraftingTableIDProp = cfg.get("GUI", "GUIChemicalCraftingTableID", 1004);
283
284
285                 this.pyrolysisTableID = pyrolysisTableIDProp.getInt();
286                 this.electrolysisTableID = electrolysisTableIDProp.getInt();
287                 this.chemicalConbinationTableID = chemicalCombinationTableIDProp.getInt();
288                 this.toolAndWeaponCraftingTableID = toolAndWeaponCraftingTableIDProp.getInt();
289                 this.chemicalCraftingTableID = chemicalCraftingTableIDProp.getInt();
290                 for (int i = 0; i < atomOresID.length; i++) {
291                         this.atomOresID[i] = atomOresIDProp[i].getInt();
292                 }
293
294                 this.atomsID = atomsIDProp.getInt();
295                 this.compoundsID = compoundsIDProp.getInt();
296                 this.gasCollectingBottleID = gasCollectingBottleIDProp.getInt();
297                 this.atomGrenadeID = atomGrenadeIDProp.getInt();
298                 this.chemicalCellsID = chemicalCellsIDProp.getInt();
299                 this.dustID = dustIDProp.getInt();
300                 this.radiationGunID = radiationGunIDProp.getInt();
301                 this.radiationBalletID = radiationBalletIDProp.getInt();
302
303                 this.guiPyrolysisTableID = guiPyrolysisTableIDProp.getInt();
304                 this.guiElectrolysisTableID = guiElectrolysisTableIDProp.getInt();
305                 this.guiChemicalCombinationTableID = guiChemicalCombinationTableIDProp.getInt();
306                 this.guiToolAndWeaponCraftingTableID = guiToolAndWeaponCraftingTableIDProp.getInt();
307                 this.guiChemicalCraftingTableID = guiChemicalCraftingTableIDProp.getInt();
308                 */
309
310                 cfg.save();
311         }
312
313
314
315         @ServerStarting
316         public void serverStarting(final FMLServerStartingEvent event) {
317                 event.registerServerCommand(new CommandSetTile());
318                 event.registerServerCommand(new CommandDeleteItem());
319                 event.registerServerCommand(new CommandGenDebugRoom());
320         }
321
322
323
324         @PostInit
325         public void chemiPostLoadMethod(final FMLPostInitializationEvent event) {
326                 this.thread = new Thread(this);
327                 this.event = event;
328                 this.thread.start();
329
330                 try {
331                         this.thread.join();
332                 } catch (InterruptedException e) {
333                         e.printStackTrace();
334                 }
335
336                 proxy.registerRenderInformation();
337                 Thread.yield();
338         }
339
340
341
342         @Override
343         public void run() {
344                 while (true) {
345                         if (proxy != null && instance != null) {
346                                 this.settingProcessing(event);
347                                 this.apiProcessing(event);
348                                 this.debug(event);
349                                 break;
350                         }
351                 }
352         }
353
354
355
356         private void settingProcessing(final FMLPostInitializationEvent event) {
357
358                 this.registerBlock.start();
359                 this.registerItem.start();
360                 this.registerTileEntity.start();
361                 this.registerRecipe.start();
362                 this.registerChemicalRecipe.start();
363                 this.registerCompounds.start();
364                 this.registerCompoundsHandler.start();
365                 this.registerEntitys.start();
366
367                 // GUIを追加します
368                 NetworkRegistry.instance().registerGuiHandler(instance, proxy);
369
370                 //電池を追加します
371                 this.api.addChemicalCell(itemChemicalCells, "ChemicalCell", 1000);
372                 this.api.addChemicalCellLanguage("ChemicalCell", "ja_JP", "化学電池");
373
374                 this.api.addPyrolysisDecompositionFuel(new ItemStack(Item.coal), 2000*8);
375         }
376
377
378
379         private void apiProcessing(final FMLPostInitializationEvent event) {
380                 // API用の処理
381                 for (int i = 0; i < api.getAtomOresName().sizeKeysList(); i++)
382                 {
383                         for (int j = 0; j < api.getAtomOresName().sizeElementsList(api.getAtomOresName().getKeyList(i)); j++)
384                         {
385                                 this.nameAuxiliary.addName(new ItemStack(blockAtomOres[i / 16], 0, i - i / 16 * 16), api.getAtomOresLanguage().get(api.getAtomOresName().getKeyList(i), j), api.getAtomOresName().get(api.getAtomOresName().getKeyList(i), j));
386                                 OreDictionary.registerOre("ore" + api.getAtomOresName().getKeyList(i), new ItemStack(blockAtomOres[i / 16], 1, i - i / 16 * 16));
387                         }
388                 }
389
390                 for (int i = 0; i < api.getAtomOres().size(); i++)
391                 {
392                         GameRegistry.registerWorldGenerator(api.getAtomOres().get(i));
393                 }
394
395                 for (int i = 0; i < api.getChemicalCellsName().sizeKeysList(); i++)
396                 {
397                         for (int j = 0; j < api.getChemicalCellsName().sizeElementsList(api.getChemicalCellsName().getKeyList(i)); j++)
398                         {
399                                 this.nameAuxiliary.addName(new ItemStack(itemChemicalCells, 0, i), api.getChemicalCellsLanguage().get(api.getChemicalCellsName().getKeyList(i), j), api.getChemicalCellsName().get(api.getChemicalCellsName().getKeyList(i), j));
400                         }
401                 }
402
403                 for (int i = 0; i < api.getCompoundsName().sizeKeysList(); i++)
404                 {
405                         for (int j = 0; j < api.getCompoundsName().sizeElementsList(api.getCompoundsName().getKeyList(i)); j++)
406                         {
407                                 this.nameAuxiliary.addName(new ItemStack(itemCompounds, 0, i), api.getCompoundsLang().get(api.getCompoundsName().getKeyList(i), j), api.getCompoundsName().get(api.getCompoundsName().getKeyList(i), j));
408                         }
409                 }
410
411         }
412
413
414
415         private void debug(final FMLPostInitializationEvent event) {
416                 this.proxy.registerTickHandler();
417                 this.api.addCompound("Debug");
418                 this.api.settingCompoundHandler("Debug", new CompoundDebug());
419
420                 this.api.addToolAndWeaponRecipe(new ItemStack[] {
421                                 new ItemStack(Block.stone, 1, 1)
422                 },
423                 new ItemStack(Block.dirt, 1, 0));
424
425         }
426
427 }