OSDN Git Service

www
[chemicraft/chemicraft.git] / common / pcc / chemicraft / core / ChemiCraftCore.java
1 package pcc.chemicraft.core;
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 pcc.chemicraft.ChemiCraft;
10 import pcc.chemicraft.ChemiCraftConfiguration;
11 import pcc.chemicraft.ChemiCraftRegister;
12 import pcc.chemicraft.core.compounds.CompoundDebug;
13 import pcc.chemicraft.core.creativetab.CreativeTabChemiCraft;
14 import pcc.chemicraft.core.debug.CommandDeleteItem;
15 import pcc.chemicraft.core.debug.CommandGenDebugRoom;
16 import pcc.chemicraft.core.debug.CommandSetTile;
17 import pcc.chemicraft.core.system.CommonProxy;
18 import pcc.chemicraft.core.system.PacketHandler;
19 import cpw.mods.fml.common.Mod;
20 import cpw.mods.fml.common.Mod.Init;
21 import cpw.mods.fml.common.Mod.Instance;
22 import cpw.mods.fml.common.Mod.PreInit;
23 import cpw.mods.fml.common.Mod.ServerStarting;
24 import cpw.mods.fml.common.SidedProxy;
25 import cpw.mods.fml.common.event.FMLInitializationEvent;
26 import cpw.mods.fml.common.event.FMLPreInitializationEvent;
27 import cpw.mods.fml.common.event.FMLServerStartingEvent;
28 import cpw.mods.fml.common.network.NetworkMod;
29 import cpw.mods.fml.common.network.NetworkRegistry;
30
31 /**
32  * ChemiCraft本体
33  * @author P.C.C.
34  */
35 @Mod(modid = "ChemiCraft", name = "ChemiCraft", version = "beta")
36 @NetworkMod(clientSideRequired = true, serverSideRequired = true, versionBounds = "1.4.6", channels = "chemicraftcore", packetHandler = PacketHandler.class)
37 public class ChemiCraftCore extends ChemiCraft{
38
39         /**
40          * 元素名配列
41          */
42         public static final String[] ATOMSNAME = {
43                 "Hydrogen", "Helium", "Lithium", "Beryllium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine", "Neon", "Sodium", "Magnesium", "Aluminium", "Silicon",
44                 "Phosphorus", "Sulfur", "Chlorine", "Argon", "Potassium", "Calcium", "Scandium", "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel", "Copper", "Zinc", "Gallium",
45                 "Germanium", "Arsenic", "Selenium", "Bromine", "Krypton", "Rubidium", "Strontium", "Yttorium", "Zirconium", "Niobium", "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium",
46                 "Silver", "Cadmium", "Indium", "Tin", "Antimony", "Tellurium", "Iodine", "Xenon", "Caesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium", "Promethium", "Samarium",
47                 "Europium", "Gadolinium", "Terbium", "Dysprosium", "Holmium", "Erbium", "Thulium", "Ytterbium", "Lutetium", "Hafnium", "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinum",
48                 "Gold", "Mercury", "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon", "Francium", "Radium", "Actinium", "Thorium", "Protactinium", "Uranium", "Neptunium", "Plutonium",
49                 "Americium", "Curium", "Berkelium", "Californium", "Einsteinium", "Fermium", "Mendelevium", "Nobelium", "Lawrencium", "Rutherfordium", "Dubnium", "Seaborgium", "Bohrium", "Hassium",
50                 "Meitnerium", "Darmstadtium", "Roentgenium", "Copernicium", "Ununtrium", "Ununquadium", "Ununpentium", "Ununhexium", "Ununseptium", "Ununoctium" };
51
52         /**
53          * 元素名日本語版配列
54          */
55         public static final String[] ATOMSNAMEJP = {
56                 "水素", "ヘリウム", "リチウム", "ベリウム", "ホウ素", "炭素", "窒素", "酸素", "フッ素", "ネオン", "ナトリウム", "マグネシウム", "アルミニウム", "ケイ素", "リン", "硫黄", "塩素", "アルゴン", "カリウム", "カルシウム", "スカンジウム",
57                 "チタン", "バナジウム", "クロム", "マンガン", "鉄", "コバルト", "ニッケル", "銅", "亜鉛", "ガリウム", "ゲルマニウム", "ヒ素", "セレン", "臭素", "クリプトン", "ルビジウム", "ストロンチウム", "イットリウム", "ジルコニウム", "ニオブ", "モリブデン", "テクネチウム", "ルテニウム",
58                 "ロジウム", "パラジウム", "銀", "カドミウム", "インジウム", "スズ", "アンチモン", "テルル", "ヨウ素", "キセノン", "セシウム", "バリウム", "ランタン", "セリウム", "プラセオジム", "ネオジム", "プロメチウム", "サマリウム", "ユウロビウム", "ガドリニウム", "テルビウム", "ジスプロニウム",
59                 "ホルミウム", "エルビウム", "ツリウム", "イッテルビウム", "ルテチウム", "ハフニウム", "タンタル", "タングステン", "レニウム", "オスミウム", "イリジウム", "白金", "金", "水銀", "タリウム", "鉛", "ビスマス", "ポロニウム", "アスタチン", "ラドン", "フランシウム", "ラジウム",
60                 "アクチニウム", "トリウム", "プロトアクチウム", "ウラン", "ネプツニウム", "プルトニウム", "アメリシウム", "キュリウム", "バークリウム", "カルホルニウム", "アインスタイニウム", "フェルミウム", "メンデレビウム", "ノーベリウム", "ローレンシウム", "ラサホージウム", "ドブニウム", "シーボーギウム",
61                 "ボーリウム", "ハッシウム", "マイトネリウム", "ダームスタチウム", "レントゲニウム", "コペルニシウム", "ウンウントリウム", "ウンウンクアジウム", "ウンウンペンチウム", "ウンウンヘキシウム", "ウンウンセプチウム", "ウンウンオクチウム" };
62
63         /**
64          * this is ChemiCraft instance.
65          */
66         @Instance("ChemiCraft")
67         public static ChemiCraftCore instance;
68
69         /**
70          * proxy of ChemiCraft.
71          */
72         @SidedProxy(clientSide = "pcc.chemicraft.core.client.ClientProxy", serverSide = "pcc.chemicraft.core.system.CommonProxy")
73         public static CommonProxy proxy;
74
75         /**
76          * CreativeTab of ChemiCraft.
77          */
78         public static final CreativeTabs creativeTabChemiCraft = new CreativeTabChemiCraft("ChemiCraft");
79
80         /**
81          * API Instance.
82          */
83         public ChemiCraftAPI api = ChemiCraftAPI.instance();
84
85         /**
86          * the ItemID.
87          */
88         public int atomsID;
89         public int compoundsID;
90         public int gasCollectingBottleID;
91         public int chemicalCellsID;
92         public int pearID;
93
94         /**
95          * the BlockID.
96          */
97         public int pyrolysisTableID;
98         public int electrolysisTableID;
99         public int chemicalConbinationTableID;
100         public int toolAndWeaponCraftingTableID;
101         public int chemicalCraftingTableID;
102
103         /**
104          * the GUIID.
105          */
106         public int guiPyrolysisTableID;
107         public int guiElectrolysisTableID;
108         public int guiChemicalCombinationTableID;
109         public int guiToolAndWeaponCraftingTableID;
110         public int guiChemicalCraftingTableID;
111
112         /**
113          * Variables of Block type.
114          */
115         public Block blockPyrolysisTable;
116         public Block blockElectrolysisTable;
117         public Block blockChemicalCombinationTable;
118         public Block blockToolAndWeaponCraftingTable;
119         public Block blockChemicalCraftingTable;
120
121         /**
122          * Variables of Item type.
123          */
124         public Item itemAtoms;
125         public Item itemCompounds;
126         public Item itemGasCollectingBottle;
127         public Item itemChemicalCells;
128         public Item itemPear;
129
130         /**
131          * the Register Instances.
132          */
133         public ChemiCraftRegister registerItem;
134         public ChemiCraftRegister registerBlock;
135         public ChemiCraftRegister registerTileEntity;
136         public ChemiCraftRegister registerRecipe;
137
138         public ChemiCraftCore() {
139                 this.registerItem = new ChemiCraftRegisterItem(this);
140                 this.registerBlock = new ChemiCraftRegisterBlock(this);
141                 this.registerTileEntity = new ChemiCraftRegisterTileEntity(this);
142                 this.registerRecipe = new ChemiCraftRegisterCoreRecipe(this);
143
144                 //this.sinVisualizer  = new SinVisualizer();
145         }
146
147         /**
148          * PreInit:
149          * Configをロードします。
150          * @param event アノテーション呼び出しにより呼び出す必要なし
151          */
152         @PreInit
153         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
154                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
155                 cfg.load();
156
157                 Property coreBlockID = cfg.get("BlockID", "Base of Block ID", 2400);
158                 Property coreItemID = cfg.get("ItemID", "Base of Item ID", 25000);
159
160                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(coreBlockID.getInt());
161                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(coreBlockID.getInt());
162
163                 this.pyrolysisTableID = ccfgBlock.additionID();
164                 this.electrolysisTableID = ccfgBlock.additionID();
165                 this.chemicalConbinationTableID = ccfgBlock.additionID();
166                 this.toolAndWeaponCraftingTableID = ccfgBlock.additionID();
167                 this.chemicalCraftingTableID = ccfgBlock.additionID();
168
169                 this.atomsID = ccfgItem.additionID();
170                 this.compoundsID = ccfgItem.additionID();
171                 this.gasCollectingBottleID = ccfgItem.additionID();
172                 this.chemicalCellsID = ccfgItem.additionID();
173
174                 Property guiPyrolysisTableIDProp = cfg.get("GUI", "GUIPyrolysisID", 1000);
175                 Property guiElectrolysisTableIDProp = cfg.get("GUI", "GUIElectrolysisTableIDProp", 1001);
176                 Property guiChemicalCombinationTableIDProp = cfg.get("GUI", "GUIChemicalCombinationTableID", 1002);
177                 Property guiToolAndWeaponCraftingTableIDProp = cfg.get("GUI", "GUIToolAndWeaponCraftingTableID", 1003);
178                 Property guiChemicalCraftingTableIDProp = cfg.get("GUI", "GUIChemicalCraftingTableID", 1004);
179
180                 this.guiPyrolysisTableID = guiPyrolysisTableIDProp.getInt();
181                 this.guiElectrolysisTableID = guiElectrolysisTableIDProp.getInt();
182                 this.guiChemicalCombinationTableID = guiChemicalCombinationTableIDProp.getInt();
183                 this.guiToolAndWeaponCraftingTableID = guiToolAndWeaponCraftingTableIDProp.getInt();
184                 this.guiChemicalCraftingTableID = guiChemicalCraftingTableIDProp.getInt();
185
186                 cfg.save();
187         }
188
189
190
191         @ServerStarting
192         public void serverStarting(final FMLServerStartingEvent event) {
193                 event.registerServerCommand(new CommandSetTile());
194                 event.registerServerCommand(new CommandDeleteItem());
195                 event.registerServerCommand(new CommandGenDebugRoom());
196         }
197
198
199
200         @Init
201         public void chemiPostLoadMethod(final FMLInitializationEvent event) {
202                 this.thread = new Thread(this);
203                 this.event = event;
204                 this.thread.start();
205
206                 try {
207                         this.thread.join();
208                 } catch (InterruptedException e) {
209                         e.printStackTrace();
210                 }
211
212                 proxy.registerRenderInformation();
213                 Thread.yield();
214         }
215
216
217
218         @Override
219         public void run() {
220                 while (true) {
221                         if (proxy != null && instance != null) {
222                                 this.settingProcessing((FMLInitializationEvent) event);
223                                 this.apiProcessing((FMLInitializationEvent) event);
224                                 this.debug((FMLInitializationEvent) event);
225                                 break;
226                         }
227                 }
228         }
229
230
231
232         protected void settingProcessing(final FMLInitializationEvent event) {
233
234                 this.registerItem.start();
235                 this.registerBlock.start();
236                 this.registerRecipe.start();
237                 this.registerTileEntity.start();
238
239                 // GUIを追加します
240                 NetworkRegistry.instance().registerGuiHandler(instance, proxy);
241
242                 //電池を追加します
243                 this.api.addChemicalCell(itemChemicalCells, "ChemicalCell", 1000);
244                 this.api.addChemicalCellLanguage("ChemicalCell", "ja_JP", "化学電池");
245
246                 this.api.addPyrolysisDecompositionFuel(new ItemStack(Item.coal), 2000*8);
247         }
248
249
250
251         private void apiProcessing(final FMLInitializationEvent event) {
252
253                 for (int i = 0; i < api.getChemicalCellsName().sizeKeysList(); i++)
254                 {
255                         for (int j = 0; j < api.getChemicalCellsName().sizeElementsList(api.getChemicalCellsName().getKeyList(i)); j++)
256                         {
257                                 this.nameAuxiliary.addName(new ItemStack(itemChemicalCells, 0, i), api.getChemicalCellsLanguage().get(api.getChemicalCellsName().getKeyList(i), j), api.getChemicalCellsName().get(api.getChemicalCellsName().getKeyList(i), j));
258                         }
259                 }
260
261                 for (int i = 0; i < api.getCompoundsName().sizeKeysList(); i++)
262                 {
263                         for (int j = 0; j < api.getCompoundsName().sizeElementsList(api.getCompoundsName().getKeyList(i)); j++)
264                         {
265                                 this.nameAuxiliary.addName(new ItemStack(itemCompounds, 0, i), api.getCompoundsLang().get(api.getCompoundsName().getKeyList(i), j), api.getCompoundsName().get(api.getCompoundsName().getKeyList(i), j));
266                         }
267                 }
268
269         }
270
271
272
273         private void debug(final FMLInitializationEvent event) {
274                 this.proxy.registerTickHandler();
275                 this.api.addCompound("Debug");
276                 this.api.settingCompoundHandler("Debug", new CompoundDebug());
277
278                 this.api.addToolAndWeaponRecipe(new ItemStack[] {
279                                 new ItemStack(Block.stone, 1, 1)
280                 },
281                 new ItemStack(Block.dirt, 1, 0));
282
283         }
284
285 }