OSDN Git Service

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