OSDN Git Service

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