OSDN Git Service

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