OSDN Git Service

tc
[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                 this.api.getCompoundsName().createHash("en_US");
153                 this.registerItem = new ChemiCraftRegisterItem(this);
154                 this.registerBlock = new ChemiCraftRegisterBlock(this);
155                 this.registerTileEntity = new ChemiCraftRegisterTileEntity(this);
156                 this.registerRecipe = new ChemiCraftRegisterCoreRecipe(this);
157                 this.logger.startLogging();
158                 //this.sinVisualizer  = new SinVisualizer();
159         }
160
161         /**
162          * PreInit:
163          * Configをロードします。
164          * @param event アノテーション呼び出しにより呼び出す必要なし
165          */
166         @PreInit
167         public void chemiPreLoadMethod(final FMLPreInitializationEvent event) {
168                 Configuration cfg = new Configuration(event.getSuggestedConfigurationFile());
169                 cfg.load();
170
171                 Property coreBlockID = cfg.get("BlockID", "Base of Block ID", 2400);
172                 Property coreItemID = cfg.get("ItemID", "Base of Item ID", 25000);
173
174                 ChemiCraftConfiguration ccfgBlock = new ChemiCraftConfiguration(coreBlockID.getInt());
175                 ChemiCraftConfiguration ccfgItem = new ChemiCraftConfiguration(coreItemID.getInt());
176
177                 this.pyrolysisTableID = ccfgBlock.additionID();
178                 this.electrolysisTableID = ccfgBlock.additionID();
179                 this.chemicalConbinationTableID = ccfgBlock.additionID();
180                 this.toolAndWeaponCraftingTableID = ccfgBlock.additionID();
181                 this.chemicalCraftingTableID = ccfgBlock.additionID();
182
183                 this.atomsID = ccfgItem.additionID();
184                 this.compoundsID = ccfgItem.additionID();
185                 this.gasCollectingBottleID = ccfgItem.additionID();
186                 this.chemicalCellsID = ccfgItem.additionID();
187                 this.pearID = ccfgItem.additionID();
188
189                 Property guiPyrolysisTableIDProp = cfg.get("GUI", "GUIPyrolysisID", 1000);
190                 Property guiElectrolysisTableIDProp = cfg.get("GUI", "GUIElectrolysisTableIDProp", 1001);
191                 Property guiChemicalCombinationTableIDProp = cfg.get("GUI", "GUIChemicalCombinationTableID", 1002);
192                 Property guiToolAndWeaponCraftingTableIDProp = cfg.get("GUI", "GUIToolAndWeaponCraftingTableID", 1003);
193                 Property guiChemicalCraftingTableIDProp = cfg.get("GUI", "GUIChemicalCraftingTableID", 1004);
194
195                 this.guiPyrolysisTableID = guiPyrolysisTableIDProp.getInt();
196                 this.guiElectrolysisTableID = guiElectrolysisTableIDProp.getInt();
197                 this.guiChemicalCombinationTableID = guiChemicalCombinationTableIDProp.getInt();
198                 this.guiToolAndWeaponCraftingTableID = guiToolAndWeaponCraftingTableIDProp.getInt();
199                 this.guiChemicalCraftingTableID = guiChemicalCraftingTableIDProp.getInt();
200
201                 cfg.save();
202         }
203
204
205
206         @ServerStarting
207         public void serverStarting(final FMLServerStartingEvent event) {
208                 event.registerServerCommand(new CommandSetTile());
209                 event.registerServerCommand(new CommandDeleteItem());
210                 event.registerServerCommand(new CommandGenDebugRoom());
211         }
212
213
214
215         @Init
216         public void chemiPostLoadMethod(final FMLInitializationEvent event) {
217                 this.thread = new Thread(this);
218                 this.event = event;
219                 this.thread.start();
220
221                 try {
222                         this.thread.join();
223                 } catch (InterruptedException e) {
224                         e.printStackTrace();
225                 }
226
227                 proxy.registerRenderInformation();
228                 Thread.yield();
229         }
230
231
232
233         @Override
234         public void run() {
235                 while (true) {
236                         if (proxy != null && instance != null) {
237                                 this.settingProcessing((FMLInitializationEvent) event);
238                                 this.debug((FMLInitializationEvent) event);
239                                 break;
240                         }
241                 }
242
243                 Thread loadCheckThread = new Thread() {
244                         @Override
245                         public void run() {
246                                 while (true) {
247                                         List<ModContainer> mod = Loader.instance().getModList();
248                                         ModContainer finalMod = mod.get(mod.size()-1);
249                                         ModState finalModState = Loader.instance().getModState(finalMod);
250                                         if (finalModState == ModState.POSTINITIALIZED) {
251                                                 ChemiCraftCore.logger.write("ChemiCraftCore>APIProcessing", EnumLoggingType.INFO);
252                                                 apiProcessing((FMLInitializationEvent) event);
253                                                 break;
254                                         }
255                                 }
256                         }
257                 };
258                 loadCheckThread.start();
259
260         }
261
262
263
264         protected void settingProcessing(final FMLInitializationEvent event) {
265
266                 this.registerItem.start();
267                 this.registerBlock.start();
268                 this.registerRecipe.start();
269                 this.registerTileEntity.start();
270
271                 // GUIを追加します
272                 NetworkRegistry.instance().registerGuiHandler(instance, proxy);
273
274                 this.api.addPyrolysisDecompositionFuel(new ItemStack(Item.coal), 2000*8);
275         }
276
277
278
279         private void apiProcessing(final FMLInitializationEvent event) {
280                 Iterator<String> langcompoundsItr = this.api.getCompoundsName().keySet().iterator();
281                 while (langcompoundsItr.hasNext()) {
282                         String lang = langcompoundsItr.next();
283                         ArrayList<String> names = this.api.getCompoundsName().get(lang);
284                         for (int i = 0; i < names.size(); i++) {
285                                 ChemiCraftCore.logger.write("CompoundAddName:" + "Name-" + names.get(i) + "/Damage-" + i + "/Lang-" + lang,
286                                                 EnumLoggingType.INFO);
287
288                                 LanguageRegistry.instance().addNameForObject(
289                                                 new ItemStack(this.itemCompounds, 1, i),
290                                                 lang,
291                                                 names.get(i));
292                         }
293                 }
294
295         }
296
297
298
299         public static EntityDamageSource getRadiationDamageSource(Entity par1Entity){
300                 return new EntityDamageSource("radiation", par1Entity){
301                         @Override
302                         public String getDeathMessage(EntityLiving par1EntityLiving) {
303                                 if (par1EntityLiving instanceof EntityPlayer) {
304                                         return ((EntityPlayer) (par1EntityLiving)).username + " is dead by radiation.";
305                                 } else {
306                                         return par1EntityLiving.getEntityName() + " is dead by radiation.";
307                                 }
308                         }
309                 };
310         }
311
312
313
314         private void debug(final FMLInitializationEvent event) {
315                 //this.proxy.registerTickHandler();
316         }
317
318 }