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